Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

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

by Athanasius (Archbishop)
on Aug 19, 2017 at 16:13 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (6)
As of 2024-04-26 09:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found