Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: How do I get the value of a number that belongs to a string??

by chromatic (Archbishop)
on Feb 19, 2000 at 02:07 UTC ( [id://3726]=note: print w/replies, xml ) Need Help??


in reply to How do I get the value of a number that is part of a string?

Perl will automatically do the right thing with a scalar depending on the context in which you use it. If you were to say:
my $x = "1"; my $y = "2"; print $x + $y, "\n";
you'll get 3. If you say:
my $x = "1"; my $y = "2"; print $x . $y, "\n";
you'll get 12 ("2" appended to "1"). To force interpretation in a numeric context, you can try:
my $x = "10abc"; print $x + 0, "\n";
and you'll get 10. Note that this only works on scalars starting with digits. Strip them out with a regex if you need to.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2024-04-26 01:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found