Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Script to check for multiple files on FTP and print the one missing

by zork42 (Monk)
on Jul 01, 2013 at 03:19 UTC ( #1041717=note: print w/ replies, xml ) Need Help??


in reply to Script to check for multiple files on FTP and print the one missing

Hi.

(1) It it not clear what you mean by a "missing file", especially as all the files will have different names. Are you expecting to see these sort of filenames

@a = ( 'abc_some_text.txt', 'abc_some_other_text.txt', 'abc_some_diffe +rent_text.txt' ) @b = ( 'efg_some_text.txt', 'efg_some_other_text.txt', 'efg_some_diffe +rent_text.txt' ) @c = ( 'xyz_some_text.txt', 'xyz_some_other_text.txt' )
ie filenames where the '*' in the file masks are replaced by the same text in all 3 groups?

In this case would 'xyz_some_different_text.txt' be the "missing file"?

(2) I initially thought "if (@a && @b && @c)" was equivalent to "if ( scalar(@a) && scalar(@b) && scalar(@c) )".
However, the help file says
"Binary "&&" performs a short-circuit logical AND operation. That is, if the left operand is false, the right operand is not even evaluated. Scalar or list context propagates down to the right operand if it is evaluated."
This means that I have no idea what it means!
Maybe a helpful monk can explain?
It is a very unusual construction, it might be worth replacing it with something clearer.


UPDATE: I did not see Anonymous Monk's post before writing my post, as he posted while I was writing this. I don't think it actually makes any difference in this case, but I thought I'd mention it!


Comment on Re: Script to check for multiple files on FTP and print the one missing
Download Code
Re^2: Script to check for multiple files on FTP and print the one missing
by LanX (Canon) on Jul 01, 2013 at 03:27 UTC
    the if imposes scalar (i.e. boolean) context, so it's true if all arrays are not empty.

    just try testing print scalar(@a && @b)

    you could replace && with * and || with +.

    I'm doing this if I explicitly want to avoid any short-circuit!

    Cheers Rolf

    ( addicted to the Perl Programming Language)

      the if imposes scalar (i.e. boolean) context,
      I did not know that, thanks!

      Do you think perlop should make it clearer what "&&" means in list/array context?
      Or have I missed something?
Re^2: Script to check for multiple files on FTP and print the one missing
by Anonymous Monk on Jul 01, 2013 at 03:29 UTC

    It is a very unusual construction, it might be worth replacing it with something clearer.

    :) If you don't know what it means, how do you know its very unusual?

    Yes, it is equivalent , if forces scalar context,

    $ perl -le " @f=4..6;@g=7..9; print @f && @g ; " 789 $ perl -le " @f=4..6;@g=7..9; print scalar( @f && @g ); " 3
    See also Re: Script to check for multiple files on FTP and print the one missing
      It is a very unusual construction, it might be worth replacing it with something clearer.

      :) If you don't know what it means, how do you know its very unusual?
      Um, my dog told me?!
      Fair point!
Re^2: Script to check for multiple files on FTP and print the one missing
by perlvroom (Acolyte) on Jul 01, 2013 at 04:33 UTC
    Yes, for simplicity, ignore the *. Suppose i am checking for 3 files: abc.txt, xyz.txt, efg.txt. If all are present on FTP then it prints "all files are there". If xyz.txt and abc.txt are the only files on the FTP it will print "efg.txt is missing". The actual number of files i need to check for is about 20 which is why i'm trying to write it cleaner.
      Are you using Net::FTP?
      Because that its documentation says that $ftp->ls($dir) returns a directory listing.
      Assuming that to be the case, then something like this should work.
      use strict; use warnings; my @files_to_check = ( 'abc.txt', 'xyz.txt', 'efg.txt' ); # list +of files to check my @directory_listing = $ftp->ls($dir); my %files_on_FTP_server; foreach my $file (@directory_listing) { # extra processing here? $files_on_FTP_server{$file} = 1; } foreach my $file (@files_to_check) { if ( ! $files_on_FTP_server{$file} ) { print "File $file is missin +g\n"; } }
      However, as I do not know the format of @directory_listing, you might need some extra processing where indicated on line 12.
      If @directory_listing contains a line of info for each file, you'd need a regexp to extract the file from each line, and you'd change line 10 from
      foreach my $file (@directory_listing) to:
      foreach my $line (@directory_listing)


      UPDATE: s/Net::FTP/Net::FTP/ (ie linkified it)
      s/that/its documentation/

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (8)
As of 2014-12-19 11:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (79 votes), past polls