in reply to Re^2: performance issues
in thread performance issues
OK. From what I've understood you to want... see if something along these lines works any better:
noting that the [ \t]+ can be changed to simply \t for use with your file (I've used [ \t]+ here only because that works even if the stuff between the "blocks" has been converted to any mixture tabs and spaces). Noting also that the (.*) will stop at end of line.use strict ; use warnings ; my $data ; { local $/ ; $data = <DATA> ; } ; my $s = 'bc' ; # Substring to search for in left hand side my @r = ($data =~ m/$s[^\s]*[ \t]+(.*)/g) ; print "@r\n" ; __DATA__ abcd s1 efgh s2 ijklm s3 nopq s4 bc s5 aqbc s6 rst s7 uvwx s8 yz s9
Note also that this is assuming that the right hand side will not contain any tabs (or spaces)
The regex can match to the search substring in the right hand side, but since that ends in a newline, the [^\s]*[ \t]+ part will fail the match.
The following:
avoids matching in the right hand side, and the right hand side can contain tabs (and spaces). I don't have enough data to know if there's any performance advantage or disadvantage here.my $data = "\n" ; { local $/ ; $data .= <DATA> ; } ; my $s = 'bc' ; # Substring to search for in left hand side my @r = ($data =~ m/\n.*?$s[^\s]*[ \t]+(.*)/g) ;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: performance issues
by perlcat (Novice) on Jan 28, 2009 at 07:54 UTC |