in reply to Re: Re^5: Grep Pattern Match
in thread Grep Pattern Match
I threw some debug-foo at this code fragment and came up with yes and no. Looking at the code via B::Concise it looks like the regex is compiled each time. Looking at the code view use re 'debug' it looks like it's compiled only once. I suppose that enough digging through perl's guts would provide a real answer but really -- I'd rather just use qr to control when the regex is compiled and not have to worry about what the internals are doing.
I mean, there are times it's interesting and useful to know what's happening but this case is just too opaque to get at.
my @in = qw(nc01123.log nc02123.log nc03123.log); my $year = '0'; my $month = '2'; @in = grep { /^nc$year$month.*\.log$/ } @in; print "@in\n"; __END__ Try zero: The nested sub block was hard to read so this didn't yield t +oo much. perl -MO=Concise test.pl Try one: This makes it look like the regex is compiled anew each time. perl -MO=Concise,-exec test.pl Try two: This looks like the regex is compiled only once. Or maybe deb +ug just <i>dumps</i> it once. use re 'debug';
Fun Fun Fun in the Fluffy Chair
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re^7: Grep Pattern Match
by BrowserUk (Patriarch) on Dec 27, 2002 at 18:16 UTC | |
by diotalevi (Canon) on Dec 27, 2002 at 19:48 UTC |