in reply to regex code embedding problem?
This looks like some unusual interaction between lexicals and the regex engine.use strict; use warnings; use Data::Dumper; my @file_names = qw( /a/990101ag/toc.html /a/20000115/toc.html /a/990115ag/toc.html ); my %date; for my $file_name ( @file_names ) { print "Now working on $file_name\n"; %date = ( YEAR => '', MONTH => '', DAY => '' ); $file_name =~ m# (?<=/a/) (\d{2,4})(\d{2})(\d{2})(?:ag)? (?=/) (?{ @date{'YEAR', 'MONTH', 'DAY'} = ( ( length($1) == 2 ? '19' . $1 : $1), $2, $3 ) }) (?{ print "Here, \%date is populated (joined): ", join('-', @date{'YEAR', 'MONTH', 'DAY'}), "\n" }) #x; print "But after the first iteration, ", "it isn't populated here (joined): ", join('-', @date{'YEAR', 'MONTH', 'DAY'}), "\n"; print Dumper(\%date); print "\n\n"; }
Update: cleaned up an initialization.
-Mark
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: regex code embedding problem?
by perlguy (Deacon) on Mar 12, 2004 at 23:45 UTC |