Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Regular expression

by Athanasius (Abbot)
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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (15)
As of 2015-07-02 13:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (38 votes), past polls