Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^3: Perl oddities

by Anonymous Monk
on Mar 02, 2005 at 13:47 UTC ( #435824=note: print w/replies, xml ) Need Help??


in reply to Re^2: Perl oddities
in thread Perl oddities

That doesn't work:
#!/usr/bin/perl use strict; use warnings; $_ = "this that some other foo bar baz"; if (/(this)\s*(that)\s*(some)\s*(other)\s*(foo)\s*(bar)\s*(baz)/) { my ($this, $that, $some, $other, $foo, $bar, $baz) = ($1 .. $+); print "$this, $that, $some, $other, $foo, $bar, $baz\n"; } __END__ Use of uninitialized value in concatenation (.) or string at Use of uninitialized value in concatenation (.) or string at Use of uninitialized value in concatenation (.) or string at Use of uninitialized value in concatenation (.) or string at Use of uninitialized value in concatenation (.) or string at Use of uninitialized value in concatenation (.) or string at Use of uninitialized value in concatenation (.) or string at , , , , , ,
What does work is:
#!/usr/bin/perl use strict; use warnings; $_ = "this that some other foo bar baz"; if (/(this)\s*(that)\s*(some)\s*(other)\s*(foo)\s*(bar)\s*(baz)/) { my ($this, $that, $some, $other, $foo, $bar, $baz) = map {;no strict 'refs'; $$_} 1 .. $#-; print "$this, $that, $some, $other, $foo, $bar, $baz\n"; } __END__ this, that, some, other, foo, bar, baz
A trick I've been using for quite a long time. ($#+ instead of $#- works as well).

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://435824]
help
Chatterbox?
and snow settles gently...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2016-12-10 00:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (159 votes). Check out past polls.