From: Gurusamy Sarathy Date: Tue, 29 Feb 2000 08:13:56 +0000 (+0000) Subject: more m//s and $ vs \z fixups (from Greg Bacon) X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1b1e14d34a33bfe0df591910cafcab54421ca8a8;p=p5sagit%2Fp5-mst-13.2.git more m//s and $ vs \z fixups (from Greg Bacon) p4raw-id: //depot/perl@5349 --- diff --git a/lib/File/CheckTree.pm b/lib/File/CheckTree.pm index dca7f6a..ae18777 100644 --- a/lib/File/CheckTree.pm +++ b/lib/File/CheckTree.pm @@ -105,7 +105,7 @@ sub validate { sub valmess { local($disposition,$this) = @_; - $file = $cwd . '/' . $file unless $file =~ m|^/|; + $file = $cwd . '/' . $file unless $file =~ m|^/|s; if ($this =~ /^(!?)-(\w)\s+\$file\s*$/) { $neg = $1; $tmp = $2; diff --git a/lib/File/Copy.pm b/lib/File/Copy.pm index 8638bee..e6cf786 100644 --- a/lib/File/Copy.pm +++ b/lib/File/Copy.pm @@ -83,7 +83,7 @@ sub copy { if ($from_a_handle) { *FROM = *$from{FILEHANDLE}; } else { - $from = "./$from" if $from =~ /^\s/; + $from = "./$from" if $from =~ /^\s/s; open(FROM, "< $from\0") or goto fail_open1; binmode FROM or die "($!,$^E)"; $closefrom = 1; @@ -92,7 +92,7 @@ sub copy { if ($to_a_handle) { *TO = *$to{FILEHANDLE}; } else { - $to = "./$to" if $to =~ /^\s/; + $to = "./$to" if $to =~ /^\s/s; open(TO,"> $to\0") or goto fail_open2; binmode TO or die "($!,$^E)"; $closeto = 1; diff --git a/lib/File/DosGlob.pm b/lib/File/DosGlob.pm index e6fc311..9a61f17 100644 --- a/lib/File/DosGlob.pm +++ b/lib/File/DosGlob.pm @@ -61,7 +61,7 @@ sub doglob { s/\?/.?/g; #print "regex: '$_', head: '$head'\n"; - my $matchsub = eval 'sub { $_[0] =~ m|^' . $_ . '$|io }'; + my $matchsub = eval 'sub { $_[0] =~ m|^' . $_ . '\\z|ios }'; warn($@), next OUTER if $@; INNER: for my $e (@leaves) { diff --git a/lib/File/Path.pm b/lib/File/Path.pm index 59b72ba..79fdfb6 100644 --- a/lib/File/Path.pm +++ b/lib/File/Path.pm @@ -118,7 +118,7 @@ sub mkpath { $paths = [$paths] unless ref $paths; my(@created,$path); foreach $path (@$paths) { - $path .= '/' if $^O eq 'os2' and $path =~ /^\w:$/; # feature of CRT + $path .= '/' if $^O eq 'os2' and $path =~ /^\w:\z/s; # feature of CRT next if -d $path; # Logic wants Unix paths, so go with the flow. $path = VMS::Filespec::unixify($path) if $Is_VMS; @@ -157,7 +157,7 @@ sub rmtree { my($root); foreach $root (@{$roots}) { - $root =~ s#/$##; + $root =~ s#/\z##; (undef, undef, my $rp) = lstat $root or next; $rp &= 07777; # don't forget setuid, setgid, sticky bits if ( -d _ ) { @@ -181,8 +181,8 @@ sub rmtree { # Deleting large numbers of files from VMS Files-11 filesystems # is faster if done in reverse ASCIIbetical order @files = reverse @files if $Is_VMS; - ($root = VMS::Filespec::unixify($root)) =~ s#\.dir$## if $Is_VMS; - @files = map("$root/$_", grep $_!~/^\.{1,2}$/,@files); + ($root = VMS::Filespec::unixify($root)) =~ s#\.dir\z## if $Is_VMS; + @files = map("$root/$_", grep $_!~/^\.{1,2}\z/s,@files); $count += rmtree(\@files,$verbose,$safe); if ($safe && ($Is_VMS ? !&VMS::Filespec::candelete($root) : !-w $root)) { diff --git a/lib/File/Spec/Mac.pm b/lib/File/Spec/Mac.pm index 14da25a..22682f9 100644 --- a/lib/File/Spec/Mac.pm +++ b/lib/File/Spec/Mac.pm @@ -79,10 +79,10 @@ sub catdir { shift; my @args = @_; my $result = shift @args; - $result =~ s/:$//; + $result =~ s/:\z//; foreach (@args) { - s/:$//; - s/^://; + s/:\z//; + s/^://s; $result .= ":$_"; } return "$result:"; @@ -110,7 +110,7 @@ sub catfile { my $file = pop @_; return $file unless @_; my $dir = $self->catdir(@_); - $file =~ s/^://; + $file =~ s/^://s; return $dir.$file; } @@ -150,7 +150,7 @@ sub rootdir { require Mac::Files; my $system = Mac::Files::FindFolder(&Mac::Files::kOnSystemDisk, &Mac::Files::kSystemFolderType); - $system =~ s/:.*$/:/; + $system =~ s/:.*\z/:/; return $system; } @@ -194,7 +194,7 @@ distinguish unambiguously. sub file_name_is_absolute { my ($self,$file) = @_; if ($file =~ /:/) { - return ($file !~ m/^:/); + return ($file !~ m/^:/s); } else { return (! -e ":$file"); } @@ -228,22 +228,22 @@ sub splitpath { my ($volume,$directory,$file) = ('','',''); if ( $nofile ) { - ( $volume, $directory ) = $path =~ m@((?:[^:]+(?::|$))?)(.*)@; + ( $volume, $directory ) = $path =~ m@((?:[^:]+(?::|\z))?)(.*)@; } else { $path =~ m@^( (?: [^:]+: )? ) ( (?: .*: )? ) ( .* ) - @x; + @xs; $volume = $1; $directory = $2; $file = $3; } # Make sure non-empty volumes and directories end in ':' - $volume .= ':' if $volume =~ m@[^:]$@ ; - $directory .= ':' if $directory =~ m@[^:]$@ ; + $volume .= ':' if $volume =~ m@[^:]\z@ ; + $directory .= ':' if $directory =~ m@[^:]\z@ ; return ($volume,$directory,$file); } @@ -259,7 +259,7 @@ sub splitdir { # check to be sure that there will not be any before handling the # simple case. # - if ( $directories !~ m@:$@ ) { + if ( $directories !~ m@:\z@ ) { return split( m@:@, $directories ); } else { @@ -282,16 +282,16 @@ sub catpath { my $self = shift ; my $result = shift ; - $result =~ s@^([^/])@/$1@ ; + $result =~ s@^([^/])@/$1@s ; my $segment ; for $segment ( @_ ) { - if ( $result =~ m@[^/]$@ && $segment =~ m@^[^/]@ ) { + if ( $result =~ m@[^/]\z@ && $segment =~ m@^[^/]@s ) { $result .= "/$segment" ; } - elsif ( $result =~ m@/$@ && $segment =~ m@^/@ ) { - $result =~ s@/+$@/@; - $segment =~ s@^/+@@; + elsif ( $result =~ m@/\z@ && $segment =~ m@^/@s ) { + $result =~ s@/+\z@/@; + $segment =~ s@^/+@@s; $result .= "$segment" ; } else { diff --git a/lib/File/Spec/OS2.pm b/lib/File/Spec/OS2.pm index 07fc867..33370f0 100644 --- a/lib/File/Spec/OS2.pm +++ b/lib/File/Spec/OS2.pm @@ -15,7 +15,7 @@ sub case_tolerant { sub file_name_is_absolute { my ($self,$file) = @_; - return scalar($file =~ m{^([a-z]:)?[\\/]}i); + return scalar($file =~ m{^([a-z]:)?[\\/]}is); } sub path { diff --git a/lib/File/Spec/Unix.pm b/lib/File/Spec/Unix.pm index 186ab23..f4e9f27 100644 --- a/lib/File/Spec/Unix.pm +++ b/lib/File/Spec/Unix.pm @@ -33,9 +33,9 @@ sub canonpath { my ($self,$path) = @_; $path =~ s|/+|/|g unless($^O eq 'cygwin'); # xx////xx -> xx/xx $path =~ s|(/\.)+/|/|g; # xx/././xx -> xx/xx - $path =~ s|^(\./)+|| unless $path eq "./"; # ./xx -> xx - $path =~ s|^/(\.\./)+|/|; # /../../xx -> xx - $path =~ s|/$|| unless $path eq "/"; # xx/ -> xx + $path =~ s|^(\./)+||s unless $path eq "./"; # ./xx -> xx + $path =~ s|^/(\.\./)+|/|s; # /../../xx -> xx + $path =~ s|/\z|| unless $path eq "/"; # xx/ -> xx return $path; } @@ -146,7 +146,7 @@ directory. (Does not strip symlinks, only '.', '..', and equivalents.) sub no_upwards { my $self = shift; - return grep(!/^\.{1,2}$/, @_); + return grep(!/^\.{1,2}\z/s, @_); } =item case_tolerant @@ -168,7 +168,7 @@ Takes as argument a path and returns true, if it is an absolute path. sub file_name_is_absolute { my ($self,$file) = @_; - return scalar($file =~ m:^/:); + return scalar($file =~ m:^/:s); } =item path @@ -223,7 +223,7 @@ sub splitpath { $directory = $path; } else { - $path =~ m|^ ( (?: .* / (?: \.\.?$ )? )? ) ([^/]*) |x; + $path =~ m|^ ( (?: .* / (?: \.\.?\z )? )? ) ([^/]*) |xs; $directory = $1; $file = $2; } @@ -261,7 +261,7 @@ sub splitdir { # check to be sure that there will not be any before handling the # simple case. # - if ( $directories !~ m|/$| ) { + if ( $directories !~ m|/\z| ) { return split( m|/|, $directories ); } else { diff --git a/lib/File/Spec/VMS.pm b/lib/File/Spec/VMS.pm index 54a5f1a..1a0330a 100644 --- a/lib/File/Spec/VMS.pm +++ b/lib/File/Spec/VMS.pm @@ -55,7 +55,7 @@ sub eliminate_macros { $complex = 1; } } - else { ($macro = unixify($self->{$macro})) =~ s#/$##; } + else { ($macro = unixify($self->{$macro})) =~ s#/\z##; } $npath = "$head$macro$tail"; } } @@ -85,18 +85,18 @@ sub fixpath { $self = bless {} unless ref $self; my($fixedpath,$prefix,$name); - if ($path =~ m#^\$\([^\)]+\)$# || $path =~ m#[/:>\]]#) { - if ($force_path or $path =~ /(?:DIR\)|\])$/) { + if ($path =~ m#^\$\([^\)]+\)\z#s || $path =~ m#[/:>\]]#) { + if ($force_path or $path =~ /(?:DIR\)|\])\z/) { $fixedpath = vmspath($self->eliminate_macros($path)); } else { $fixedpath = vmsify($self->eliminate_macros($path)); } } - elsif ((($prefix,$name) = ($path =~ m#^\$\(([^\)]+)\)(.+)#)) && $self->{$prefix}) { + elsif ((($prefix,$name) = ($path =~ m#^\$\(([^\)]+)\)(.+)#s)) && $self->{$prefix}) { my($vmspre) = $self->eliminate_macros("\$($prefix)"); # is it a dir or just a name? - $vmspre = ($vmspre =~ m|/| or $prefix =~ /DIR$/) ? vmspath($vmspre) : ''; + $vmspre = ($vmspre =~ m|/| or $prefix =~ /DIR\z/) ? vmspath($vmspre) : ''; $fixedpath = ($vmspre ? $vmspre : $self->{$prefix}) . $name; $fixedpath = vmspath($fixedpath) if $force_path; } @@ -165,19 +165,19 @@ sub catdir { if (@dirs) { my $path = (@dirs == 1 ? $dirs[0] : $self->catdir(@dirs)); my ($spath,$sdir) = ($path,$dir); - $spath =~ s/.dir$//; $sdir =~ s/.dir$//; - $sdir = $self->eliminate_macros($sdir) unless $sdir =~ /^[\w\-]+$/; + $spath =~ s/.dir\z//; $sdir =~ s/.dir\z//; + $sdir = $self->eliminate_macros($sdir) unless $sdir =~ /^[\w\-]+\z/s; $rslt = $self->fixpath($self->eliminate_macros($spath)."/$sdir",1); # Special case for VMS absolute directory specs: these will have had device # prepended during trip through Unix syntax in eliminate_macros(), since # Unix syntax has no way to express "absolute from the top of this device's # directory tree". - if ($spath =~ /^[\[<][^.\-]/) { $rslt =~ s/^[^\[<]+//; } + if ($spath =~ /^[\[<][^.\-]/s) { $rslt =~ s/^[^\[<]+//s; } } else { - if ($dir =~ /^\$\([^\)]+\)$/) { $rslt = $dir; } - else { $rslt = vmspath($dir); } + if ($dir =~ /^\$\([^\)]+\)\z/s) { $rslt = $dir; } + else { $rslt = vmspath($dir); } } return $rslt; } @@ -197,8 +197,8 @@ sub catfile { if (@files) { my $path = (@files == 1 ? $files[0] : $self->catdir(@files)); my $spath = $path; - $spath =~ s/.dir$//; - if ($spath =~ /^[^\)\]\/:>]+\)$/ && basename($file) eq $file) { + $spath =~ s/.dir\z//; + if ($spath =~ /^[^\)\]\/:>]+\)\z/s && basename($file) eq $file) { $rslt = "$spath$file"; } else { @@ -305,8 +305,8 @@ Checks for VMS directory spec as well as Unix separators. sub file_name_is_absolute { my ($self,$file) = @_; # If it's a logical name, expand it. - $file = $ENV{$file} while $file =~ /^[\w\$\-]+$/ && $ENV{$file}; - return scalar($file =~ m!^/! || + $file = $ENV{$file} while $file =~ /^[\w\$\-]+\z/s && $ENV{$file}; + return scalar($file =~ m!^/!s || $file =~ m![<\[][^.\-\]>]! || $file =~ /:[^<\[]/); } @@ -321,7 +321,7 @@ sub splitpath { my($self,$path) = @_; my($dev,$dir,$file) = ('','',''); - vmsify($path) =~ /(.+:)?([\[<].*[\]>])?(.*)/; + vmsify($path) =~ /(.+:)?([\[<].*[\]>])?(.*)/s; return ($1 || '',$2 || '',$3); } @@ -335,7 +335,7 @@ sub splitdir { my($self,$dirspec) = @_; $dirspec =~ s/\]\[//g; $dirspec =~ s/\-\-/-.-/g; my(@dirs) = split('\.', vmspath($dirspec)); - $dirs[0] =~ s/^[\[<]//; $dirs[-1] =~ s/[\]>]$//; + $dirs[0] =~ s/^[\[<]//s; $dirs[-1] =~ s/[\]>]\z//s; @dirs; } @@ -379,7 +379,7 @@ sub splitpath { m{^ ( (?: /[^/]* )? ) ( (?: .*/(?:[^/]+.dir)? )? ) (.*) - }x; + }xs; $volume = $1; $directory = $2; $file = $3; @@ -389,14 +389,14 @@ sub splitpath { m{^ ( (?: (?: (?: [\w\$-]+ (?: "[^"]*")?:: )? [\w\$-]+: )? ) ) ( (?:\[.*\])? ) (.*) - }x; + }xs; $volume = $1; $directory = $2; $file = $3; } $directory = $1 - if $directory =~ /^\[(.*)\]$/ ; + if $directory =~ /^\[(.*)\]\z/s ; return ($volume,$directory,$file); } @@ -422,14 +422,14 @@ sub splitdir { return File::Spec::Unix::splitdir( $self, @_ ) if ( $directories =~ m{/} ) ; - $directories =~ s/^\[(.*)\]$/$1/ ; + $directories =~ s/^\[(.*)\]\z/$1/s ; # # split() likes to forget about trailing null fields, so here we # check to be sure that there will not be any before handling the # simple case. # - if ( $directories !~ m{\.$} ) { + if ( $directories !~ m{\.\z} ) { return split( m{\.}, $directories ); } else { @@ -453,13 +453,13 @@ sub catpath { my ($volume,$directory,$file) = @_; $volume .= ':' - if $volume =~ /[^:]$/ ; + if $volume =~ /[^:]\z/ ; $directory = "[$directory" - if $directory =~ /^[^\[]/ ; + if $directory =~ /^[^\[]/s ; $directory .= ']' - if $directory =~ /[^\]]$/ ; + if $directory =~ /[^\]]\z/ ; return "$volume$directory$file" ; } @@ -500,13 +500,13 @@ sub abs2rel { $self->splitpath( $path, 1 ) ; $path_directories = $1 - if $path_directories =~ /^\[(.*)\]$/ ; + if $path_directories =~ /^\[(.*)\]\z/s ; my ( undef, $base_directories, undef ) = $self->splitpath( $base, 1 ) ; $base_directories = $1 - if $base_directories =~ /^\[(.*)\]$/ ; + if $base_directories =~ /^\[(.*)\]\z/s ; # Now, remove all leading components that are the same my @pathchunks = $self->splitdir( $path_directories ); @@ -523,7 +523,7 @@ sub abs2rel { # @basechunks now contains the directories to climb out of, # @pathchunks now has the directories to descend in to. $path_directories = '-.' x @basechunks . join( '.', @pathchunks ) ; - $path_directories =~ s{\.$}{} ; + $path_directories =~ s{\.\z}{} ; return $self->catpath( '', $path_directories, $path_file ) ; } @@ -556,8 +556,8 @@ sub rel2abs($;$;) { my $sep = '' ; $sep = '.' - if ( $base_directories =~ m{[^.]$} && - $path_directories =~ m{^[^.]} + if ( $base_directories =~ m{[^.]\z} && + $path_directories =~ m{^[^.]}s ) ; $base_directories = "$base_directories$sep$path_directories" ; diff --git a/lib/File/Spec/Win32.pm b/lib/File/Spec/Win32.pm index 6ee2f3b..85a71a2 100644 --- a/lib/File/Spec/Win32.pm +++ b/lib/File/Spec/Win32.pm @@ -65,7 +65,7 @@ sub case_tolerant { sub file_name_is_absolute { my ($self,$file) = @_; - return scalar($file =~ m{^([a-z]:)?[\\/]}i); + return scalar($file =~ m{^([a-z]:)?[\\/]}is); } =item catfile @@ -100,13 +100,13 @@ path. On UNIX eliminated successive slashes and successive "/.". sub canonpath { my ($self,$path) = @_; - $path =~ s/^([a-z]:)/\u$1/; + $path =~ s/^([a-z]:)/\u$1/s; $path =~ s|/|\\|g; $path =~ s|([^\\])\\+|$1\\|g; # xx////xx -> xx/xx $path =~ s|(\\\.)+\\|\\|g; # xx/././xx -> xx/xx - $path =~ s|^(\.\\)+|| unless $path eq ".\\"; # ./xx -> xx - $path =~ s|\\$|| - unless $path =~ m#^([A-Z]:)?\\$#; # xx/ -> xx + $path =~ s|^(\.\\)+||s unless $path eq ".\\"; # ./xx -> xx + $path =~ s|\\\z|| + unless $path =~ m#^([A-Z]:)?\\\z#s; # xx/ -> xx return $path; } @@ -136,7 +136,7 @@ sub splitpath { $path =~ m{^( (?:[a-zA-Z]:|(?:\\\\|//)[^\\/]+[\\/][^\\/]+)? ) (.*) - }x; + }xs; $volume = $1; $directory = $2; } @@ -146,9 +146,9 @@ sub splitpath { (?:\\\\|//)[^\\/]+[\\/][^\\/]+ )? ) - ( (?:.*[\\\\/](?:\.\.?$)?)? ) + ( (?:.*[\\\\/](?:\.\.?\z)?)? ) (.*) - }x; + }xs; $volume = $1; $directory = $2; $file = $3; @@ -187,7 +187,7 @@ sub splitdir { # check to be sure that there will not be any before handling the # simple case. # - if ( $directories !~ m|[\\/]$| ) { + if ( $directories !~ m|[\\/]\z| ) { return split( m|[\\/]|, $directories ); } else { @@ -216,16 +216,16 @@ sub catpath { # If it's UNC, make sure the glue separator is there, reusing # whatever separator is first in the $volume $volume .= $1 - if ( $volume =~ m@^([\\/])[\\/][^\\/]+[\\/][^\\/]+$@ && - $directory =~ m@^[^\\/]@ + if ( $volume =~ m@^([\\/])[\\/][^\\/]+[\\/][^\\/]+\z@s && + $directory =~ m@^[^\\/]@s ) ; $volume .= $directory ; # If the volume is not just A:, make sure the glue separator is # there, reusing whatever separator is first in the $volume if possible. - if ( $volume !~ m@^[a-zA-Z]:$@ && - $volume =~ m@[^\\/]$@ && + if ( $volume !~ m@^[a-zA-Z]:\z@s && + $volume =~ m@[^\\/]\z@ && $file =~ m@[^\\/]@ ) { $volume =~ m@([\\/])@ ; @@ -330,7 +330,7 @@ sub abs2rel { } # It makes no sense to add a relative path to a UNC volume - $path_volume = '' unless $path_volume =~ m{^[A-Z]:}i ; + $path_volume = '' unless $path_volume =~ m{^[A-Z]:}is ; return $self->canonpath( $self->catpath($path_volume, $path_directories, $path_file )