Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: glob directory to array, then wait, and check again

by Athanasius (Archbishop)
on Aug 19, 2017 at 16:13 UTC ( #1197664=note: print w/replies, xml ) Need Help??

in reply to glob directory to array, then wait, and check again

Hello flieckster,

You need to loop; for example:

use strict; use warnings; use POSIX qw( strftime ); my $dir = $ARGV[0] // '.'; my $wait = $ARGV[1] // 10; chdir $dir or die "$!"; my $count = () = glob '*'; print_dir_status($count); if ($count > 0) { my $equal = 0; until ($equal) { sleep $wait; my $new_count = () = glob '*'; $equal = 1 if $new_count == $count; $count = $new_count; print_dir_status($count); } } sub print_dir_status { my ($count) = @_; my $time = strftime "%a %d %b %Y %I:%M:%S %p", localtime; print "$time: there are $count files\n"; }

Update: Note that (contrary to the node title) it’s not necessary to store the results of the glob in an array. The syntax $count = () = glob '*'; evaluates glob in list context (via the assignment to empty parentheses), then implicitly puts that list into scalar context (by assigning to a scalar variable) to get the list count.

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Replies are listed 'Best First'.
Re^2: glob directory to array, then wait, and check again
by flieckster (Scribe) on Aug 20, 2017 at 01:20 UTC
    thats works perfectly! thank you so uch.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2022-06-30 03:36 GMT
Find Nodes?
    Voting Booth?
    My most frequent journeys are powered by:

    Results (97 votes). Check out past polls.