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

Re: list files based on age and pattern

by hdb (Parson)
on Sep 16, 2013 at 09:42 UTC ( #1054265=note: print w/ replies, xml ) Need Help??


in reply to list files based on age and pattern

What prevents you from trying whether it is possible or not? And should it give unexpected results, what have you tried and what did you get?


Comment on Re: list files based on age and pattern
Re^2: list files based on age and pattern
by kaka_2 (Acolyte) on Sep 16, 2013 at 10:09 UTC

    lack of knowledge on perl syntax prevents me to do that. this is not my experties but few time i have to deal with these codes.

      To test for files older than 15 mins use ... and (-M) > 1.0 / 96 in your grep.

        To test for files older than 15 mins use ... and (-M) > 1.0 / 96 in your grep.

        That's a pretty strong obfu to someone who is not fluent with the -M file test.

        It is definitely worth a comment in your code what you meant to do/'re doing there. ;-)

        Cheers, Sören

        Créateur des bugs mobiles - let loose once, run everywhere.
        (hooked on the Perl Programming language)

Re^2: list files based on age and pattern
by kaka_2 (Acolyte) on Sep 16, 2013 at 13:18 UTC
    i have made changes like this.
    sub GetINDirFiles { my ($path) = @_; my $min_age = 1 / 96; opendir DIR, $path or die $!; # my @files = readdir DIR; # my @files = grep {!/\_NSA|_\d+_\d+\.xml/} readdir DIR; closedir DIR; my @files = grep {!/\_NSA|d+_\d+\.xml/ && (-M) > $min_age} readdir DIR +; return(@files); }

    in the source path i added two more file and executed the code but i see @files has no file in it whereas i would expect all the files other then newly added files.

    -KAKA-

      That is, because you are doing closedir before readdir. If you were running under use warnings;, Perl would have given you an error message like

      readdir() attempted on invalid dirhandle $dh at test-m.pl line 5.
        Hello hdb,

        Sorry it is mistake while copy paste but in the actual script closdir is after the readdir.

        there is no syntax or compilation error, only no files.

        -KAKA-

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (10)
As of 2014-09-02 13:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (22 votes), past polls