in reply to Re^4: check for square-number with a regex
in thread check for square-number with a regex
And I would have used (?{}) differently anyway. Something like:
But that's just a fancy way of writing:/^(a+)(b+)(c+)$(?(?{length($1) == length($2) && length($2) == length($ +3)})|(*FAIL))/;
And you can solve the "match a square" with:/^(a+)(b+)(c+)$/ && length($1) == length($2) && length($2) == length($ +3);
Or in general, match "whatever" by:/^([0-9]+)$(?(?{sqrt($1) == int sqrt($1)})|(*FAIL))/;
after writing the appropriate "is_whatever" function./^(.*)$(?(?{is_whatever($1)})|(*FAIL))/;
But that means the question no longer is "how can I do foo with a regexp", but "how can I do foo in Perl".
|
|---|