Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Remove non-numerics from string

by svsingh (Priest)
on Jan 26, 2004 at 18:02 UTC ( #324201=note: print w/ replies, xml ) Need Help??


in reply to Remove non-numerics from string

I think you're on the right track, but probably don't want to use split. Here, split would take the string and break it into a list of strings after each underscore.

For what you're trying to do, a simple regular expression match will work. If you just want to pull out the sequence of numbers from $oldValue, then try something like:

if ( $oldValue =~ m|(\d+)| ) { $newValue = $1; }

For what you're trying to do with split, you need to specify which list element you want to put into $newValue. Since the list starts at element 0, you'll want element 1. You can access it with the following statement:

$newValue=(split("_",$oldValue,2))[1]

Note, this will return everything after the underscore, and not just the numbers.


Comment on Re: Remove non-numerics from string
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (20)
As of 2014-07-24 15:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (162 votes), past polls