use warnings; use strict; my @OuterData = ( "This is some space separated text", "On three different lines", "So you can see what happens"); my @InnerData = ( "1, 2, 3, 4", "2, 6, 7, 8", "3, 10, 11, 12", "4, 17, 22, 21", "5, B, C, E, F", "6, 2, 3, 4, 5"); FileParse('\s+', \@OuterData, sub { my @Words = @_; my $NWords = scalar @Words; print "Line has $NWords words. '@Words'\n"; FileParse(',\s*', \@InnerData, sub { my ($Key, @Values) = @_; $Key == $NWords and print join(' ',@Values)," - "; }); print join("-",@Words),"\n"; }); sub FileParse { my ($PatternCore, $TextAref, $Code) = @_; # print "$PatternCore, $TextAref, $Code\n"; my $regexp_p = qr/$PatternCore/; foreach my $line (@{$TextAref}) { # my @Data = split($PatternCore, $line); my @Data = split($regexp_p, $line); $Code->(@Data); } } =cut Perl 5.6.1 built for sun4-solaris Line has 6 words. 'This is some space separated text' Argument "1," isn't numeric in numeric eq (==) at pbug.pl line 30. Argument "2," isn't numeric in numeric eq (==) at pbug.pl line 30. Argument "3," isn't numeric in numeric eq (==) at pbug.pl line 30. Argument "4," isn't numeric in numeric eq (==) at pbug.pl line 30. Argument "5," isn't numeric in numeric eq (==) at pbug.pl line 30. Argument "6," isn't numeric in numeric eq (==) at pbug.pl line 30. 2, 3, 4, 5 - This-is-some-space-separated-text Line has 4 words. 'On three different lines' Argument "1," isn't numeric in numeric eq (==) at pbug.pl line 30. Argument "2," isn't numeric in numeric eq (==) at pbug.pl line 30. Argument "3," isn't numeric in numeric eq (==) at pbug.pl line 30. perl-5.8.8 Line has 6 words. 'This is some space separated text' 2 3 4 5 - This-is-some-space-separated-text Line has 4 words. 'On three different lines' 17 22 21 - On-three-different-lines Line has 6 words. 'So you can see what happens' 2 3 4 5 - So-you-can-see-what-happens And if you really want to have fun: Try changing my $Regexp_ref; To: our $Regexp_ref; Passing the string directly into split seems to work with perl 5.6.1 a +nd perl 5.8.8
In reply to Re^4: qr bug in perl 5.6.1 with lexicals
by Anonymous Monk
in thread qr bug in perl 5.6.1 with lexicals
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |