Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: How can i extract a number from an string

by Bloodnok (Vicar)
on Jan 22, 2009 at 11:51 UTC ( [id://738120]=note: print w/replies, xml ) Need Help??


in reply to How can i extract a number from an string

foreach (@array) { /^BS(\d)/; my $num = $1; . . }

A user level that continues to overstate my experience :-))

Replies are listed 'Best First'.
Re^2: How can i extract a number from an string
by jplindstrom (Monsignor) on Jan 22, 2009 at 17:25 UTC
    /^BS(\d)/ or warn("Invalid frobniz id ($_)\n"), next;

    Or possibly die on bad input. Never ignore it.

    (And, it's better to be explicit about the loop variable IMHO, $_ is a missed opportunity to write self documented code).

    /J

Re^2: How can i extract a number from an string
by Sombrerero_loco (Beadle) on Jan 22, 2009 at 12:04 UTC
    and this should capture only the number from the string "BS4-SuchaString" ???
      As the RE says, if the string begins with BS and is followed by a single digit, that digit will be captured - see perlre.

      A user level that continues to overstate my experience :-))

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-04-18 06:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found