Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: assigning regex matches to variables

by lidden (Deacon)
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.


Comment on Re: assigning regex matches to variables
Select or Download Code
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 chilling in the Monastery: (3)
As of 2014-07-26 16:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (178 votes), past polls