On Tue, 7 Dec 2004 13:54:41 -0500, Ed Christian <[EMAIL PROTECTED]> wrote: > [SNIP] > I'm certainly far from a Perl expert, but one suggestion I do have is to > be careful to test that your regular expression does have a match before > using $1. I believe $1 contains the first match from the last > _successful_ regex, not just the last regex. I would change the above > snippit to something along the lines of: > > my $ppp0 = `/sbin/ifconfig ppp0`; > die "Invalid output from ifconfig! Received: $ppp0\n" > unless ($ppp0 =~ m/(\d+\.\d+\.\d+\.\d+)/); > my $ip = $1;
I agree strongly here, because robustness is required in this instance. Never rely on a PPP connection being up when coding... Stylistically, I would prefer C<if> here (SUGGESTION ONLY): if ($ppp0 =~ m/(\d+\.\d+\.\d+\.\d+)/) { # Success, work with $1 etc. } else { die "Invalid output from ifconfig! Received: $ppp0\n" } Reason: By using a postfix conditional, you are placing emphasis on the error message not the condition that follows it. I wouldn't normally expect a postfix conditional to also have important side effects. You may not agree. Jonathan Paton -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>