in reply to Re^3: How can I test for the representation of an integer?
in thread How can I test for the representation of an integer?

The regexps are user-supplied and arbitrary - they may or may not have captures.
Matching the number '1' is a real use-case.

  • Comment on Re^4: How can I test for the representation of an integer?

Replies are listed 'Best First'.
Re^5: How can I test for the representation of an integer?
by hippo (Archbishop) on Apr 25, 2016 at 11:25 UTC

    So I guess you want the count rather than the match (since you didn't specify). In that case, just force scalar context:

    $ perl -MData::Dumper -e 'print Dumper(scalar ("2" =~ /(2)/));' $VAR1 = 1;

    Update: As per haukex's correction the scalar context simply forces true/false rather than the count of matches. The above strategy still applies if this (whether the regex is a match or not) is all that you really want to test.