Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re: Use of "my" after Perl v5.14

by AnomalousMonk (Chancellor)
on Sep 21, 2012 at 04:42 UTC ( #994805=note: print w/replies, xml ) Need Help??

in reply to Use of "my" after Perl v5.14

What is difference between: -
    while( my($index, $value) = each @rocks )
    while((my $index,my $value) = each @rocks )

You can see what Perl thinks the difference is by using the O compiler backend interface to the B::Deparse module (invoked here with  -p full parenthesization):

>perl -wMstrict -MO=Deparse,-p -le "my @rocks = qw(a b c); ;; while (my ($i, $v) = each @rocks) { print qq{$i: '$v'}; } ;; while ((my $i, my $v) = each @rocks) { print qq{$i: '$v'}; } " BEGIN { $^W = 1; } BEGIN { $/ = "\n"; $\ = "\n"; } use strict 'refs'; (my(@rocks) = ('a', 'b', 'c')); while ((my($i, $v) = each(@rocks))) { do { print("${i}: '${v}'") }; } while ((my($i, $v) = each(@rocks))) { do { print("${i}: '${v}'") }; } -e syntax OK

Apparently, Perl doesn't think there is any difference at all. (Same results under Strawberries and

See also Basic debugging checklist.

Replies are listed 'Best First'.
Re^2: Use of "my" after Perl v5.14
by Rohit Jain (Sexton) on Sep 21, 2012 at 06:36 UTC

    Frankly, I didn't understand few segments of that code.. (Especially that BEGIN..But will come over again when I gain some more experience coding Perl..

    Thank You :)
      I didn't understand few segments of that code.. (Especially that BEGIN..

      Those two blocks are inserted by the compiler in response to the  -w and  -l command line switches, respectively. (See perlrun for info on all switches.) Try deparsing the command line invocation with and without the switches and see the effect!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://994805]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (2)
As of 2018-02-24 04:44 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (310 votes). Check out past polls.