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

Re^5: Unable to get the paragraph in the list of hashes. Getting single lines instead.

by GrandFather (Saint)
on Sep 21, 2020 at 21:05 UTC ( [id://11122037]=note: print w/replies, xml ) Need Help??


in reply to Re^4: Unable to get the paragraph in the list of hashes. Getting single lines instead.
in thread Unable to get the paragraph in the list of hashes. Getting single lines instead.

next if !/^(\d+):(.*)/s; skip the remainder of the loop body and start the next itteration - in this case, deal with the next record.

The \s*? isn't actually required at all. The ? does mean "lazy" - match the fewest white space characters possible and still match. See perlre for regular expression documentation.

The /s (s at the end of the regex) means treat the string as a single line. That captures the remainder of the record regardless of the line breaks in it.

next and last are loop control statements. They skip to the next iteration or terminate the loop respectively. They are very important to understand to help write clear succinct code.

Your analysis of the regex is spot on. The regex is not so great though. In particular, both the \s* matches could be omitted because they actually do nothing - maybe my coffee levels were dropping by the time I wrote that?

Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond
  • Comment on Re^5: Unable to get the paragraph in the list of hashes. Getting single lines instead.
  • Select or Download Code

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (3)
As of 2024-04-26 04:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found