in reply to matching patterns
Your regex is complicated and likely to be buggy. The use of greedy .* may blow up in your face.
What is @line, and what is its relation to $line?
I'd get at the match variable problem like this:
With that, the $unit and $port variables can only be assigned from $1 if the match succeeded and the value fresh. If the match fails the empty string is assigned, which will save warnings about undefined values when you print.if ($line[0] =~ /^c/) { # . . . my $unit = ($line =~ /\bunit=(\d*)/) ? $1 : ''; my $port = ($line =~ /\bport=(\d*)/) ? $1 : ''; # . . . }
After Compline,
Zaxo
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: matching patterns
by theroninwins (Friar) on Apr 11, 2006 at 07:45 UTC | |
by SamCG (Hermit) on Apr 11, 2006 at 22:51 UTC |