Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^3: my $x or my ($x)

by Rhandom (Curate)
on Apr 05, 2006 at 15:06 UTC ( #541408=note: print w/ replies, xml ) Need Help??


in reply to Re^2: my $x or my ($x)
in thread my $x or my ($x)

The only warning I can give is that using an undef in the list will throw warnings (errors?) in older versions of perl:
my (undef, $foo, undef, $bar) = @array;


Never fear. Just move your my.

(undef, my $foo, undef, my $bar) = @array;

This is particularly more useful in cases where you already have a declared variable.
my $foo = "ab"; (my $avar, $foo) = ($foo =~ /(.)(.)/);


my @a=qw(random brilliant braindead); print $a[rand(@a)];


Comment on Re^3: my $x or my ($x)
Select or Download Code
Replies are listed 'Best First'.
Re: my $x or my ($x)
by benizi (Hermit) on Apr 25, 2006 at 15:45 UTC

    I prefer slicing. Instead of:

    my (undef, $foo, undef, $bar) = @array;

    or

    (undef, my $foo, undef, my $bar) = @array;

    do:

    my ($foo, $bar) = @array[1,3];

    e.g.

    my ($size, $mtime) = (stat $filename)[7,9];

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2015-07-30 00:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (269 votes), past polls