Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

problems with perl input

by jarwulf (Initiate)
on Mar 20, 2013 at 01:42 UTC ( #1024413=perlquestion: print w/ replies, xml ) Need Help??
jarwulf has asked for the wisdom of the Perl Monks concerning the following question:

I'm having a problem running the code at the bottom. It tells me there is no such inputfile even though its sitting in the same directory as the pl script. The error is at the system ("sort -k 1,1 -k 4n -T $workingDir $name line. When I include the print statments
print "argument = /$workingDir/ \n"; print "argument = /$inputFileVolume/ \n"; print "argument = /$inputFileDir/ \n"; print "argument = /'pwd'/ \n"; #it gives me argument = /// argument = // argument = // argument = /'pwd'/
So I guess its not finding the proper directory for some reason. How would I fix this? Thanks
#!/usr/bin/perl use strict; use warnings; use File::Spec; my $inputFile = $ARGV[0]; my $backgroudFile = $ARGV[1]; #get name of the tester file and set it as the current working directo +ry my ($inputFileVolume,$inputFileDir,$name) = File::Spec->splitpath($inp +utFile); my @workingDirArr = ($inputFileVolume,$inputFileDir); my $workingDir = File::Spec->catdir(@workingDirArr); chdir $workingDir or die "$0 failed to chdir to working dir $workingDi +r"; system ("sort -k 1,1 -k 4n -T $workingDir $name >tempLoc_$name")==0 or + die "$0 failed to sort $name"; open (NAM, "tempLoc_$name") or die "$0 failed to open file tempLoc_$na +me";

Comment on problems with perl input
Select or Download Code
Re: problems with perl input
by Athanasius (Monsignor) on Mar 20, 2013 at 02:26 UTC

    Hello jarwulf, and welcome to the Monastery!

    You need to convert $inputFile into an absolute path before passing it to splitpath(). For example:

    my ($inputFileVolume, $inputFileDir, $name) = File::Spec->splitpath(File::Spec->rel2abs($inputFile));

    Or you could consider using File::Spec->curdir(). See File::Spec.

    Hope that helps,

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1024413]
Approved by Athanasius
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2014-08-27 12:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (237 votes), past polls