Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

sequential file handling

by airblaine (Acolyte)
on May 30, 2002 at 22:41 UTC ( [id://170538]=perlquestion: print w/replies, xml ) Need Help??

airblaine has asked for the wisdom of the Perl Monks concerning the following question:

Code help please, oh great ones! Scenerio: when a file shows up in /dir/main, it needs to move to /dir1 the next file that shows up needs to go to /dir2 and the next, to /dir3 (now for where I'm stuck on the array/shift/push thing) the next file needs to go to /dir1 etc,so basically a round robbin of file distribution. Seems simple, but I'm just not getting it! Thanks in advance!

Replies are listed 'Best First'.
Re: sequential file handling
by maverick (Curate) on May 30, 2002 at 23:07 UTC
    Here's how to do just the 'round robin' part.
    my @dirs = qw{ dir1 dir2 dir3 }; my $num_targets = $#dirs + 1; my $counter = 0; foreach (0..10) { my $target = $dirs[$counter % $num_targets]; print "$_ => $target\n"; $counter++; }
    The % operator gives you the remainder of the division of $counter / $num_targets, which will be 0, 1 or 2 for any value of $counter. Use that number to select the proper directory out of the array.

    Run this little snippet and you can see the result...

    /\/\averick
    OmG! They killed tilly! You *bleep*!!

Re: sequential file handling
by DamnDirtyApe (Curate) on May 30, 2002 at 23:15 UTC
Re: sequential file handling
by wageslave (Novice) on May 31, 2002 at 01:39 UTC
    or something like this should works
    use strict; my @dir = qw{ dir1 dir2 dir3 }; my $target=shift(@dir); push(@dir,$target); print "$target\n";
    plus your file copy
      Sorry, I didn't mention that this will have to be run from cron or timed every 5 minutes. That's the tricky part. So it will have to distribute the file from /main to /dir1 then 5 minutes later, /main to /dir2 etc. Should it be done by writing to and from a text file? I'm stumped. Thanks -Blaine

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://170538]
Approved by Rex(Wrecks)
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (7)
As of 2024-04-23 07:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found