Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

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";

Replies are listed 'Best First'.
Re: problems with perl input
by Athanasius (Chancellor) 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?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1024413]
Approved by Athanasius
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (7)
As of 2018-06-18 14:09 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (110 votes). Check out past polls.