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

Re^2: breaking up a file by delimiter

by navalned (Sexton)
on Oct 07, 2018 at 13:48 UTC ( #1223639=note: print w/replies, xml ) Need Help??


in reply to Re: breaking up a file by delimiter
in thread breaking up a file by delimiter

I don't generally like statement modifiers. However, this does exactly what I need. I think my main issue was I forgot while slurping my /^XXX$/ probably didn't work and I should have changed it to /\nXXX\n/.

Replies are listed 'Best First'.
Re^3: breaking up a file by delimiter
by Laurent_R (Canon) on Oct 07, 2018 at 21:46 UTC
    I don't generally like statement modifiers.
    You don't have to follow me on that, but statement modifiers can help making your code clearer and more concise.

    Consider for instance this (somewhat meaningless) example:

    while (<$IN>) { next if /^\s*$/; # remove empty lines next if /^\s*#/; # remove comments next if /ORA/i; # remove lines with Oracle warnings and errors next unless some_condition($_); last if /File processed/; # ... now do the actual processing of useful lines }
    If you wanted to do the same with regular conditionals, you would need about three times as many code lines, and it would probably end up being less clear.

    Update: added a missing closing parenthesis to the while condition.<\small>

      without statement modifiers :)

      while (<$IN> { /^\s*$/ and next; # remove empty lines /^\s*#/ and next; # remove comments /ORA/i and next; # remove lines with Oracle warnings and errors some_condition($_) or next; /File processed/ and last; # ... now do the actual processing of useful lines }

      I actually prefer this form. It's in the same spirit as open or die

      ( TMTOWTDI forever :)

        Yes, you're right, I know this can be done and I am sometimes using this form. TIMTOWTDI. I tend however to prefer statement modifiers because I believe they are slightly clearer to many people, especially beginners.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (8)
As of 2022-01-28 11:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (73 votes). Check out past polls.

    Notices?