Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Climbing Mt. Perlcritic -- Switch statements

by JavaFan (Canon)
on Mar 25, 2009 at 23:46 UTC ( [id://753297]=note: print w/replies, xml ) Need Help??


in reply to Climbing Mt. Perlcritic -- Switch statements

Assuming you're not hanging on to old versions of Perl, I'd write it as:
given ($_) { when (/filename\s*=\s*(\S+)/) {$file = basename($1)} when (/go/ && exists $files{$file}) { push @PLACE, @batch; delete $files{$file} } @batch = ();
If it's in a for loop, and $_ is your loop variant, you can even omit the given.
Thing is, I think I understand what is happening here but not why: essentially, the call to basename() is not finding a good value in $1, which should have been returned from the match by the (\S+).
But you're not matching. qr// creates a pattern, it does not perform a match. qr/filename\s*=\s*(\S+)/ is always true. If you want to match, use m// instead.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-04-24 04:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found