Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re: Regular expression

by Athanasius (Chancellor)
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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1001460]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2018-05-23 22:11 GMT
Find Nodes?
    Voting Booth?