XP is just a number | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Hi Monks, Even after multiple attempts, I am at a total loss of how the "m" and "s" works for regex. I have a file like this:
Please note that in the example, "this:that", "here:there", etc are repeated, but that's not the case with the actual record I am working on. I am trying to write a script that will create a hash of hashes such that I get a hash with a key "first" and its value will be a key value pair such that the key will be "this" and value will be "that", key will "here" and value will be "there", and so on and so forth. But even before I reach there, I need to ensure that I write the correct regex. So, I tried to write a regex that will skip the line if it contains "first" or "second". Of course if the regex works, I can then capture the part and make that as a hashkey, but that's much later. I've tried the following, but it does not work. And I am pretty sure it's because my utter failure to understand how "m" and "s" work.
I tried using "s" instead of "m", but when I run the script, it does not read anything.
If I remove the next if $line =~ /^[a-z]+:$/m;, I get the whole file like so:
So at least I know it's reading the records right. I will be thankful if you could help me with this one. In reply to Applying regex to each line in a record. by pritesh_ugrankar
|
|