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?? |
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
In Section
Seekers of Perl Wisdom
|
|