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

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

qwerty80:

You already have several good answers, so I'm not really adding much. However, I've not played much with opendir or readdir and I thought I'd like to play with them a bit. I didn't want a recursive solution, so I did it this way:

$ cat 1004138.pl #!/usr/bin/perl use strict; use warnings; use 5.10.0; use autodie; my $filespec = "abc*.xml"; my @dirs = ('ABC'); while (@dirs) { my $curdir = pop @dirs; opendir(my $dh, $curdir); for my $f (readdir($dh)) { next if $f =~ /^\.\.?$/; next unless -d "$curdir/$f"; print "pushing $curdir/$f\n"; push @dirs, "$curdir/$f"; } for (glob("$curdir/$filespec")) { print "processing $_\n"; } } $ perl 1004138.pl pushing ABC/DEF pushing ABC/GHI pushing ABC/JKL processing ABC/abcde.xml processing ABC/JKL/abc_x.xml processing ABC/JKL/abc_y.xml processing ABC/JKL/abc_z.xml pushing ABC/GHI/baz pushing ABC/GHI/foo pushing ABC/GHI/bar processing ABC/GHI/abc_5.xml processing ABC/GHI/abc_6.xml processing ABC/GHI/bar/abc_1.xml processing ABC/GHI/bar/abc_2.xml processing ABC/GHI/bar/abc_3.xml processing ABC/GHI/bar/abc_4.xml processing ABC/GHI/foo/abc_8.xml processing ABC/GHI/foo/abc_9.xml processing ABC/GHI/foo/abc_a.xml processing ABC/GHI/foo/abc_b.xml processing ABC/GHI/baz/abc_{7}.xml

It's not particularly pretty, but it amused me for a few minutes. I didn't actually let it do file deletions because I'm loath to do automatic deletes until I've well tested such a script. It's a good thing, too. On my earlier attempt, a pair of bugs conspired to make the script "process" all "abc*.xml" files on my hard drive, rather than just those in the ABC directory.

...roboticus

When your only tool is a hammer, all problems look like your thumb.


In reply to Re: Recursive search and delete by roboticus
in thread Recursive search and delete by qwerty80

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others rifling through the Monastery: (6)
    As of 2015-07-04 18:27 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (60 votes), past polls