First,welcome to Perl Monks!
Second, you are much more likely to get enthusiastic help if you surround your code with code tags (<code>....</code>). That way you can preserve all of the indenting in your original code.
use strict;
use Cwd 'abs_path';
use File::Spec::Link;
use vars qw ($LIST_SEPARATOR);
my $path = "/home/czechar/foo/bar/myfile.xml";
print STDOUT "Original path: $path\n";
my $new_path = File::Spec::Link->resolve_all($path);
print STDOUT "Resolved path(1): $new_path\n";
my $abs_path = abs_path($path);
print STDOUT "Resolved path(2): $abs_path\n";
# # now try to read from a file...
# open (FILE_LIST, "< ./filenames");
my $path = <FILE_LIST>;
chomp $path;
print STDOUT "path from file: $path\n";
$abs_path = abs_path($path);
print STDOUT "abs path: $abs_path\n";
$new_path = File::Spec::Link->resolve_all($path);
print STDOUT "new path: $new_path\n";
close (FILE_LIST);
exit;
Now isn't that MUCH easier to read? :-) Here's how to do it:
My code:
<code>
[ cut and paste your code here ]
</code>
As for the bug and tracking down its causes:
- always surround variable names with delimiters when you print out variables to check their value. Thus print STDERR "path from file: <$path>\n";.
A lot of subtle bugs can develop from trailing or leading white space. Unexpected trailing whitespace could certainly be a reason that a final path segment didn't resolve properly. White space is significant in *nix and windows systems so to the operating system, "foo " is a different file from "foo".
- when you are printing debugging output, it is best to use print STDERR rather than print STDOUT. This makes all of your debugging code easier to find when you are ready to comment it out.
Note: Please don't rely on my formatting above in lieu of fixing your original post. People may not take the time to look at the replies if they see your original post has no formatting.
To edit and save changes, click on your original post, scroll down below to see the text box (make changes there), scroll down below the text box to see the update button (click to save). Thanks!
Best, beth
|