Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Efficient deletion of files / shell interaction

by kyle (Abbot)
on Jul 19, 2009 at 17:55 UTC ( [id://781471]=note: print w/replies, xml ) Need Help??


in reply to Efficient deletion of files / shell interaction

I might write this, if I didn't care if anyone can read it.

my @job_nums = 0 .. $jobs_run; my $logs = join q{ }, map { sprintf "$prefix%04d.log" } @job_nums; my $tail_rx = qr{ ==> (.+?) <== \n ( [^\n]* ) \n }xms; my @tail_pairs = `tail -n 1 $logs` =~ $tail_rx; unlink map { s/\.log$/.data/; $_ } map { $tail_pairs[$_*2] } grep { $tail_pairs[1+$_*2] !~ /Normal/ } @job_nums;

Note that I haven't tried this, and given that it calls unlink, one would do well to test it with a copy of real data before trying it with real data.

This has the advantages that it shells out to run tail only once on the list of every log file and that it calls unlink only once with the list of the files to delete. On the other hand, the heavy use of map and grep means it does more looping than is absolutely necessary.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2024-04-25 18:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found