Re: RFC 110 (v3) counting matches

[email protected] (Tom Christiansen)
Newsgroups perl.perl6.language.regex
Message-ID <7279.967562639@chthon>
>much possible action at a distance. I'm not seeing a nicely-parseable, 
>easily-understandable way of doing this. Would this be a possible:

>   $string =~ /(\d\d)-(\d\d)-(\d\d)?&{push @list,makedate(\1,\2,\3)}/g;

>Or is that just too ugly and nasty for words?

Yes, passing a reference to the numbers 1, 2, and 3 is clearly too ugly.

But you'll find we've already got that, I think.

    sub makedate {
	my($dd,$mm,$yy) = @_;
	warn "Just got a date for @_\n";
	return "[$yy/$mm/$dd]";
    } 

    $string = "22-33-44 and 55-66-77 are ok";
    @dates = ();

    () = $string =~ m{
	(\d\d) - (\d\d) - (\d\d)
	(?{ push @dates, makedate($1,$2,$3) })
    }gx;

    print "Now the dates are: @dates\n";

Running that yields: 

    Just got a date for 22 33 44
    Just got a date for 55 66 77
    Now the dates are: [44/33/22] [77/66/55]

--tom
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.