"be consistent" | |
PerlMonks |
Re: question about finding strings (regexes and slurping files)by Discipulus (Canon) |
on Nov 28, 2017 at 08:21 UTC ( [id://1204395]=note: print w/replies, xml ) | Need Help?? |
Hello SaraBetsy and welcome to the monastery and to the wonderful world of Perl! you already got some good advice, so I just want to clarify few things. > should grab the 25 characters before and after it it's not what the regex you posted is supposed to do: it grabs from 0 to 25 chars before and after the string. As already said gsix modifiers must go outside the regular expression: ' m/.../gsix' Let's use your regex to match 0-3 chars before and after the letter X using: /.{0,3}X.{0,3}/ against some strings:
And now confront the different output of the /.{3}X.{3}/ regex against the same set of strings:
Infact the second version search for at least 3 chars before and after X Now a little note about slurping files. When you do it the file goes deirectly into the memory, with probably even some overhead, so 100Mb of file data will be at least 100Mb+ of RAM used. As you will work as bioinformatic with possibly big files it's better to understand this early. If you process the file one line at time the memory consumption is minimal. The diamond operator <> is a poweful beast in Perl and, as many other things in perl, it acts differently depending on the context it was used in.
See How to read in large files L*
There are no rules, there are no thumbs.. Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
In Section
Seekers of Perl Wisdom
|
|