This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Attemting to readdir() something that isn't a dirhandle should cause
[perl5.git] / pod / perlretut.pod
index 57fc772..c0a78a4 100644 (file)
@@ -158,13 +158,14 @@ that a metacharacter can be matched by putting a backslash before it:
     "2+2=4" =~ /2\+2/;   # matches, \+ is treated like an ordinary +
     "The interval is [0,1)." =~ /[0,1)./     # is a syntax error!
     "The interval is [0,1)." =~ /\[0,1\)\./  # matches
-    "/usr/bin/perl" =~ /\/usr\/local\/bin\/perl/;  # matches
+    "/usr/bin/perl" =~ /\/usr\/bin\/perl/;  # matches
 
 In the last regexp, the forward slash C<'/'> is also backslashed,
 because it is used to delimit the regexp.  This can lead to LTS
 (leaning toothpick syndrome), however, and it is often more readable
 to change delimiters.
 
+    "/usr/bin/perl" =~ m!/usr/bin/perl!;    # easier to read
 
 The backslash character C<'\'> is a metacharacter itself and needs to
 be backslashed:
@@ -689,10 +690,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
@@ -1323,9 +1325,9 @@ If you change C<$pattern> after the first substitution happens, perl
 will ignore it.  If you don't want any substitutions at all, use the
 special delimiter C<m''>:
 
-    $pattern = 'Seuss';
+    @pattern = ('Seuss');
     while (<>) {
-        print if m'$pattern';  # matches '$pattern', not 'Seuss'
+        print if m'@pattern';  # matches literal '@pattern', not 'Seuss'
     }
 
 C<m''> acts like single quotes on a regexp; all other C<m> delimiters
@@ -1752,7 +1754,7 @@ letter, the braces can be dropped.  For instance, C<\pM> is the
 character class of Unicode 'marks', for example accent marks.
 For the full list see L<perlunicode>.
 
-The Unicode has also been separated into various sets of charaters
+The Unicode has also been separated into various sets of characters
 which you can test with C<\p{In...}> (in) and C<\P{In...}> (not in),
 for example C<\p{Latin}>, C<\p{Greek}>, or C<\P{Katakana}>.
 For the full list see L<perlunicode>.
@@ -2269,7 +2271,7 @@ may surprise you:
     $pat = qr/(?{ $foo = 1 })/;  # precompile code regexp
     /foo${pat}bar/;      # compiles ok
 
-If a regexp has (1) code expressions and interpolating variables,or
+If a regexp has (1) code expressions and interpolating variables, or
 (2) a variable that interpolates a code expression, perl treats the
 regexp as an error. If the code expression is precompiled into a
 variable, however, interpolating is ok. The question is, why is this