in reply to Works locally but not on Info Server

This looks like it works but it is a bit sloppy.
use strict; use warnings; my $mydir = '//Infoserver/directory'; opendir(DIR, $mydir) || die "Can not open directory $mydir: $!"; my @files = map { $mydir."/".$_; } grep { !/^\.+$/ && -M "$mydir/$_" > + 1; } readdir(DIR); closedir DIR; for my $file (@files){ my $size = (stat($file))[7]; next if ((-z $file) || ($size < 100)); print "$file is $size\n"; last; }

Replies are listed 'Best First'.
Re: Re: Works locally but not on Info Server
by Anonymous Monk on Jan 17, 2003 at 12:54 UTC
    Another thing I notice is the file I am retrieving is 483328 bytes but when I run it from the above script it says the size is 748544. Why is that?
Re: Re: Works locally but not on Info Server
by Anonymous Monk on Jan 17, 2003 at 11:42 UTC
    Thank you that worked but not understanding how you got it to work? Is the map function what made the difference? I looked it up and it stores output info in an anonymous arrays? Can someone please explain in more simpler language what the map function did in this script???

      I'll explain the map section for you.

      my @files = grep { !/.+$/ && -M $_ > 1; } map { $mydir."/".$_; } readdir(DIR);

      is basicly the same as

      # get the base file names my @files = readdir(DIR); # for each $file in @files, append the path to the front @files = map { $mydir."/".$_; } @files; # for each $file in @files, if it doesn't match the criteria then remo +ve it from @files @files = grep { !/.+$/ && -M $_ > 1; } @files;

      I hope that I didn't confuse you even more (:

        my @files = grep { !/^\.+$/ && -M $_ > 1; } map { $mydir."/".$_; } readdir(DIR);

        There is no point in doing that regex (corrected to your version above) after map, it will always fail. Also, you may want to skip all dot-files, since they are supposed to be hidden.

        my @files = grep { not /^\./ and -M "$mydir/$_" > 1 } readdir(DIR);

        — Arien