in reply to Formatting input
A few options:
my $string = "P5"; my $num = substr $string, 1; # or my( $num ) = $string =~ m/^\w(\d+)/; # or my $num; $num = $1 if $string =~ m/^\w(\d+)/;
...just to name a few. :) If your input is assured to begin with a capital letter, I see no reason in particular to bother checking to see if the first character is a capital letter. For that matter, I don't really even need \w, since you already know it starts with a letter. The RE could be rewritten as m/^.(\d+)/
Dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Formatting input
by Anonymous Monk on Feb 19, 2005 at 08:55 UTC |