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

Re^3: delete all directories which are not in list

by saskaqueer (Friar)
on Feb 11, 2005 at 03:54 UTC ( [id://429983]=note: print w/replies, xml ) Need Help??


in reply to Re^2: delete all directories which are not in list
in thread delete all directories which are not in list

Well then, maybe next time you ask a question, you will specify more details. How was I supposed to know you had one entry per line? I just assumed comma-separated because that's the closest assumption I could make out of the original posting. In any case, the code I provided will work for a one-item-per-line file anyway. But here's a refactored version of the whole thing:

#!/usr/bin/perl -w use strict; chdir('dir1'); open(my $fh, '<', 'list.name') or die("open() failed: $!"); my %all = map { $_ => undef } grep { -d } glob("*"); delete($all{$_}) for ( map { chomp; $_ } <$fh> ); system('rm', '-ir', $_) for (keys(%all)); __END__ format of dir1/list.name: dir1 dir2 dir3 dir4 dirx

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://429983]
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: (3)
As of 2024-04-25 21:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found