Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: assigning regex matches to variables

by lidden (Curate)
on May 28, 2011 at 20:10 UTC ( #907161=note: print w/ replies, xml ) Need Help??


in reply to assigning regex matches to variables

Change my $digits = $string2 =~ /(\d)+/; to my ($digits) = $string2 =~ /(\d)+/; and it will work. The parens changes the assingment from scalar to list context.

Replies are listed 'Best First'.
Re^2: assigning regex matches to variables
by JavaFan (Canon) on May 28, 2011 at 20:22 UTC
    Context is one thing, but the regexp needs to be fixed as well. It ought to be /(\d+)/, with the plus inside the parenthesis.
Re^2: assigning regex matches to variables
by genghis (Novice) on May 28, 2011 at 20:26 UTC

    Couldn't get that to work. Also tried

    my @digits = $string2 =~ /(\d)+/;

    which didn't work either. I guess I'm generally confused about whether the =~ operator actually assigns the result of the search; i.e. whether

    $var =~ /some_regex/;

    changes the value of $var.

      $var =~ /some_regex/; does not change the value of $var, it just searches through $var for the pattern /some_regex/.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://907161]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (1)
As of 2016-07-31 00:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What is your favorite alternate name for a (specific) keyboard key?


















    Results (269 votes). Check out past polls.