Using $1 without testing success of the regexp, bad.
Rafael Garcia-Suarez [Sat, 28 Jun 2003 16:02:53 +0000 (16:02 +0000)]
p4raw-id: //depot/perl@19873

pod/perlretut.pod

index 57fc772..6e06f19 100644 (file)
@@ -689,10 +689,11 @@ inside goes into the special variables C<$1>, C<$2>, etc.  They can be
 used just as ordinary variables:
 
     # extract hours, minutes, seconds
-    $time =~ /(\d\d):(\d\d):(\d\d)/;  # match hh:mm:ss format
-    $hours = $1;
-    $minutes = $2;
-    $seconds = $3;
+    if ($time =~ /(\d\d):(\d\d):(\d\d)/) {    # match hh:mm:ss format
+       $hours = $1;
+       $minutes = $2;
+       $seconds = $3;
+    }
 
 Now, we know that in scalar context,
 S<C<$time =~ /(\d\d):(\d\d):(\d\d)/> > returns a true or false