http://qs1969.pair.com?node_id=738120


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 :-))