Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Duplicate variable returned from sub

by Your Mother (Archbishop)
on Sep 23, 2019 at 16:59 UTC ( [id://11106577]=note: print w/replies, xml ) Need Help??


in reply to Duplicate variable returned from sub

It’s easy enough to test–

perl -Mstrict -wE 'my ( $v1, $v2, $v1 ) = ( 1 .. 3 ); say $v1' "my" variable $v1 masks earlier declaration in same statement at -e li +ne 1. 3

I would not rely on the behavior though. Definitely fix it by cutting out the duplicates.

Replies are listed 'Best First'.
Re^2: Duplicate variable returned from sub
by Zenzizenzizenzic (Pilgrim) on Sep 23, 2019 at 17:05 UTC
    I am addressing the code issue, yes. Since we're running this on Linux and Solaris, I really don't want to rely on a "quirk" that the code run the same. Thank you!

      You could make this explicit by using:

      my (undef, $var2, $var3, $var1) = someFunction($var4);
      or refactoring someFunction() if that makes sense.

        I'm refactoring the function call. But was curious where the undef would need to be if I needed a "fast fix".

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (2)
As of 2024-04-25 01:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found