Vamsi Pavan’s Place

When curiousity outbursts …..

$_ will hold the reference, not the copy of variable

October 6th, 2006 · No Comments · Perl

#!/usr/bin/perl
@list=qw(one two three);
foreach(reverse @list) {
print “$_\n”;
$_=”foo”;
}
print “$list[0]\n”;

Finally it will pring ‘foo’ not ‘one’. Because
$_ isn’t a copy of the list element, it’s a reference. Modifying it will change the list.

Bookmark it! These icons link to social bookmarking sites where readers can share and discover new web pages.
  • bodytext
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • Live
  • StumbleUpon
  • BlinkList
  • YahooMyWeb
  • NewsVine
  • blogtercimlap
  • Netvouz
  • Technorati
  • Slashdot
  • Print this article!

Tags:

0 responses so far ↓

  • There are no comments yet...Kick things off by filling out the form below.

Leave a Comment