in reply to Regex question
This will work:
my ($number) = $data =~ /\d+/g;The match operator returns the matched substrings only in list context, which is why your first code worked (assignment to an array). By using extra parentheses (like in my code above), you can turn a scalar assignment into a list assignment.
Update: You won't need the /g flag if you use capturing parentheses:
my ($number) = $data =~ /(\d+)/;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regex question
by chromatic (Archbishop) on Oct 14, 2008 at 18:22 UTC | |
by betterworld (Curate) on Oct 18, 2008 at 11:38 UTC | |
|
Re^2: Regex question
by JavaFan (Canon) on Oct 14, 2008 at 10:41 UTC | |
by betterworld (Curate) on Oct 14, 2008 at 10:55 UTC |