Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re: Regular expression

by Athanasius (Canon)
on Oct 30, 2012 at 06:13 UTC ( #1001460=note: print w/ replies, xml ) Need Help??

in reply to Regular expression

Parsing from right to left:

  • Assuming KEY_FH is a filehandle which has been opened for reading, grep places <KEY_FH> into list context, so it returns a list of the lines in the input file.
  • grep applies the regex !/^$/ to each element, filtering out blank lines. So, the output of the call to grep is a list of the non-blank lines in the input file.
  • map takes these lines as input, and applies the split function to each.
  • This splits on the pipe character (“|”), optionally surrounded by whitespace.
  • The LIMIT of 2 ensures that split will return at most 2 fields. So if the line contains more than one |, only the first will be used to split the line into fields. Assuming the line contains at least one |, split will return a list of two fields.
  • These two fields are assigned to the hash %key_hash, where they form a key-value pair.
  • Finally, chop is applied to the whole hash, which removes the final character from the value half of each key-value pair. This will presumably be the newline character read in at the end of each line. (But chomp would be a better choice here.)

Hope that helps,

Athanasius <°(((><contra mundum

Comment on Re: Regular expression

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2015-11-28 22:06 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (746 votes), past polls