This node has pretty much been hashed to death, but I just noticed it and wanted to share my own little bit of nostalgia from back when i first realized how mgical $1 really was. I was working with teh File::PathConvert module, and discovered that in some strange instances, the filenames one method returne contained weird strings from other parts of my program that had no earthly buisiness being there, which lead to a lengthy investigation, and the consumate workarround for dealing with any module/method that doesn't do a good job of testing $1,$2,... before using them...
Date: Thu, 8 Apr 1999 12:32:44 -0700 (PDT)
From: {me}
To: {the module authors}
Subject: BUG in File::PathConvert::realpath
there appears to be a bug in realpath that causes it to have problems with
paths that have spaces in them. the bug causes the value of $1 prior to
the call of realpath to get appended to the result, the bug does not
manifest itself if $1 is undefined prior to calling realpath.
a script which demonstrates this bug (as well as a fix i found to ensure
it dosesn't cause problems) is attached... run this program on a file name
with spaces in it to see the bug demonstrated.
here is the output of the program on my machine...
guido:~/code> touch "a file with spaces"
guido:~/code> test.pl --file "a file with spaces"
File::PathConvert::realpath test
File::PathConvert version#: 0.85
$FILE == a file with spaces
REALPATH($FILE) == /export/home/hossman/code/a file with spaces
EXECUTING CODE ==> "some string" =~ /(\S*)/;
REALPATH($FILE) == /export/home/hossman/code/a file with spacessome
EXECUTING CODE ==> "" =~ /((((((((()))))))))/;
REALPATH($FILE) == /export/home/hossman/code/a file with spaces
guido:~/code>
guido:~/code> test.pl --file a\ file\ with\ spaces
File::PathConvert::realpath test
File::PathConvert version#: 0.85
$FILE == a file with spaces
REALPATH($FILE) == /export/home/hossman/code/a file with spaces
EXECUTING CODE ==> "some string" =~ /(\S*)/;
REALPATH($FILE) == /export/home/hossman/code/a file with spacessome
EXECUTING CODE ==> "" =~ /((((((((()))))))))/;
REALPATH($FILE) == /export/home/hossman/code/a file with spaces
guido:~/code>
this was the attachment...
#!/usr/bin/perl -w use strict; use Getopt::Long; use File::PathConvert; my $file; GetOptions('file=s' => \$file); die "need --file arg" unless defined $file; print "File::PathConvert::realpath test\n"; print "File::PathConvert version#: " . $File::PathConvert::VERSION . " +\n\n"; print " \$FILE == $file\n"; print "REALPATH(\$FILE) == " . File::PathConvert::realpath($file) . "\ +n"; "some string" =~ /(\S*)/; print "EXECUTING CODE ==> \"some string\" =~ /(\\S*)/;\n"; print "REALPATH(\$FILE) == " . File::PathConvert::realpath($file) . "\ +n"; # executing this regexp prior to any call of realpath ensures that it # won't generate fall pray to $n bug "" =~ /((((((((()))))))))/; print "EXECUTING CODE ==> \"\" =~ /((((((((()))))))))/;\n"; print "REALPATH(\$FILE) == " . File::PathConvert::realpath($file) . "\ +n";
In reply to Re: Regex Capturing: Is this a bug or a feature?
by hossman
in thread Regex Capturing: Is this a bug or a feature?
by shotgunefx
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |