Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
Perl Monk, Perl Meditation
 
PerlMonks  

Re: -s testing for empty file; works on local, but not on remote

by pvaldes (Hermit)
on Sep 26, 2011 at 23:13 UTC ( #927974=note: print w/ replies, xml ) Need Help??


in reply to -s testing for empty file; works on local, but not on remote

Four notes about your code, probably wrong and surely unrelated with your problem, but...

1 - You could use chdir and/or put "/home/vcg/Documents/Trial" in a $dirname var saving a lot of typing. This also will protect you of mistakes like this:

$cmd = "rm /home/vcg/Documents/Trial/ $MAF"; #this extra space could delete the whole file $MAF AND the whole parentdir (at least under some circumstances) when you pass this chain to "system" in the next line.

(Also, consider to unlink a file instead to rm a file, is more portable)

2 - You should survey all this changes in the value of the cmd var, I'm worried specially by things like this:

my $cmd = "/home/vcg/Documents/Trial/muscle -in $Fprot -out $MAF"; system ($cmd);

see the trouble here? you're missing a "." sign. If you want to run the local executable named muscle in the shell you should write "./muscle", not simply "muscle". Even if your local system knows that muscle IS an executable, the remote system could ignore all about this. This could also be ambiguous to the remote shell (that will search in vain the file in its own hard disk and return false instead to run the command) .

3 - if you "open my $filehandle..." you can treat $filehandle as any other scalar variable, you could probably use simply while ($filehandle) instead while (<$FILEHANDLE>) unless you have a reason to do this (that I'm probably missing)

4 - There is room still for improving your code. You could probably put "use autodie;" in your header, quit a lot of unnecessary "()" here and there, avoid the need for creating some vars, etc


Comment on Re: -s testing for empty file; works on local, but not on remote
Select or Download Code
Re^2: -s testing for empty file; works on local, but not on remote
by jwkrahn (Monsignor) on Sep 26, 2011 at 23:33 UTC
    3 - if you "open my $filehandle..." you can treat $filehandle as any other scalar variable, you could probably use simply while ($filehandle) instead while (<$FILEHANDLE>) unless you have a reason to do this (that I'm probably missing)

    while ($filehandle) loops while the variable $filehandle contains a TRUE value.

    while (<$FILEHANDLE>) is short for while ( defined( $_ = readline $FILEHANDLE ) ) and it loops until readline returns undef.

      aha, now is clear to me, thanks for the explanation
Re^2: -s testing for empty file; works on local, but not on remote
by Jeri (Scribe) on Sep 27, 2011 at 12:58 UTC

    Thanks, I'll tidy it up.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2014-04-17 04:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (439 votes), past polls