Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Use of next if...

by basicdez (Pilgrim)
on Nov 13, 2001 at 01:27 UTC ( [id://124920]=perlquestion: print w/replies, xml ) Need Help??

basicdez has asked for the wisdom of the Perl Monks concerning the following question:

Is this possible? If not, how do I use the next statement?
next if (/^"EMP"$/)
what I have is code that has three character data tags differentiating them from other input files. Please help me if you can. peace, LOVE and ((code)) basicdez

Replies are listed 'Best First'.
Re: Use of next if...
by Rhose (Priest) on Nov 13, 2001 at 01:38 UTC
    Here is a sample with next if. (Quick language tutorial for my 1 year old. *Smiles*)

    use strict; while(<DATA>) { next if /^Bad/; print; } __DATA__ Good:Good morning Bad:Shut up Good:You're welcome Bad:No!
Re: Use of next if...
by blakem (Monsignor) on Nov 13, 2001 at 01:52 UTC
    When continuing a discussion in a new top level thread, it it is polite to provide a link back to said thread. For one thing, it would have avoided confusion about why you put quotes inside the regex.

    -Blake

Re: Use of next if...
by VSarkiss (Monsignor) on Nov 13, 2001 at 01:43 UTC

    The basic answer is "yes". Presumably this statement appears in a loop; Perl will exit the loop if $_ matches the five characters you've specified (not three). Your pattern matches, in order

    1. beginning of line
    2. double quote
    3. capital E
    4. capital M
    5. capital P
    6. double quote
    7. end of line

    The parentheses following the if are not necessary. Another way to do this would be: next if $_ eq '"EMP"'

    HTH

Re: Use of next if...
by runrig (Abbot) on Nov 13, 2001 at 01:41 UTC
    Its a regex. Don't quote anything in it unless you want to match the quotes. And if you know they're all three characters, no need for ^ or $ :
    next if /EMP/;
Re: Use of next if...
by cLive ;-) (Prior) on Nov 13, 2001 at 01:39 UTC
    Is this possible?

    gosh, perhaps if you tried it you'd find out? Maybe adding a semi-colon might help if you're in the middle of a block of code. I'd drop the quotes unless you want to match them (vaguely worded question...)

    cLive ;-)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2024-04-24 23:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found