Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

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

by AnomalousMonk (Monsignor)
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 )
and
    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 5.12.3.0 and 5.14.2.1.)

See also Basic debugging checklist.


Comment on Re: Use of "my" after Perl v5.14
Select or Download Code
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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://994805]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (15)
As of 2014-08-27 17:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (247 votes), past polls