Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
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";

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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1024413]
Approved by Athanasius
help
Chatterbox?
[Corion]: Yay! As I had to reset my phone again, I now also back up my SMS automatically. Highly conveniently, there is a program to back up my SMS to my IMAP server as mails ;)
[1nickt]: Corion this is an android phone? If so, are you encountering problems with recent upgrades? Lately my phone dies suddenly quite often, seemingly coredumps caused by interaction of two actions, eg phone playing a sound and user swiping simultaneously :-/
[Corion]: 1nickt: Yeah, it's Android, but it's CM 11, so fairly old. I'm looking for a newer (china) phone, but I think I'll wait until Oreo ROMs get out for them
[Corion]: Otherwise, the Vernee Mars looks tempting
[Corion]: ... but alas, no Oreo support in sight yet, and I prefer to flash a stock Android over the custom ROMs, and Oreo promises to make the userland more maintainable.

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (5)
As of 2017-11-18 15:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (277 votes). Check out past polls.

    Notices?