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

Re^3: Perl oddities

by YuckFoo (Abbot)
on Mar 01, 2005 at 20:19 UTC ( #435598=note: print w/ replies, xml ) Need Help??


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

I am aware of the method suggested by gaal. I usually do not use it because I almost always wrap the regex up with an 'if'. Throw in a my function and it starts to get messy.

# Ugly to me... if (my ($this, $that, $some, $other) = $line =~ /(this).*(that).*(some +).*(other)/) { do_it(); }; # Better, I think... if ($line =~ /(this).*(that).*(some).*(other)/) { my ($this, $that, $some, $other) = ($1, $2, $3, $4); do_it(); }
This business doesn't DWYM:

my ( $this, $that, $some, $other, $foo, $bar, $baz ) = ( $1 .. $+ );
The magical string incrementer is summoned to build a list of strings starting with the first capture, ending with the last.

YuckFoo


Comment on Re^3: Perl oddities
Select or Download Code
Re^4: Perl oddities
by ihb (Deacon) on Mar 01, 2005 at 22:10 UTC

    You can do

    if (my @r = $line =~ /(this).*(that).*(some).*(other)/) { my ($this, $that, $some, $other) = @r; do_it(); }
    if you want the conditional expression shorter and don't want to repeat the dollar-digit vars.

    ihb

    See perltoc if you don't know which perldoc to read!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (8)
As of 2015-07-03 03:21 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 (48 votes), past polls