Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: syntax question

by keszler (Priest)
on Oct 23, 2013 at 20:14 UTC ( #1059344=note: print w/ replies, xml ) Need Help??


in reply to syntax question

Assuming that you're in some loop and the next command is how you "exclude a field ending in X", you have the right idea. The parentheses around the regular expression are not needed. I would usually write that as next if $fld0 =~ /X$/;, but if ($fld0 =~ /X$/) { next; } is effectively the same.

Another option: next if substr($fld0,-1,1) eq "X"; (substr)


Comment on Re: syntax question
Select or Download Code
Replies are listed 'Best First'.
Re^2: syntax question
by QM (Vicar) on Oct 24, 2013 at 08:35 UTC
    Update: Sorry, I should have read the thread first, toolic said the same thing.

    next if substr($fld0,-1,1) eq "X";

    is not exactly equivalent to

    next if $fld0 =~ /X$/;

    since $ at the end of a regex is a bit special. From perlre #Metacharacters:

    $ Match the end of the line (or before newline at the end)

    -QM
    --
    Quantum Mechanics: The dreams stuff is made of

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2015-08-01 02:56 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 (285 votes), past polls