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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.