Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Comment on

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

prune prevents recursion.

max_depth(1) also prevents recursion :)

Based on the previous links I might write this which avoids the slurping of both files and filenames :)

#!/usr/bin/perl -- use strict; use warnings; use File::Find::Rule; Main( @ARGV ); exit( 0 ); sub Fudge { use Errno(); join qq/\n/, "Error @_", map { " $_" } int( $! ) . q/ / . $!, int( $^E ) . q/ / . $^E, grep( { $!{$_} } keys %! ), q/ /; } sub pie(&@) { my( $cb, $file, $backup ) = @_; $backup ||= "$file~"; $backup = "$file$backup" if length $file > length $backup; rename $file, $backup or die Fudge( "backing up q{$file} to q{$bac +kup}:" ); open my $IN, "<", $backup or die Fudge( "reading q{$backup}:" ); open my $OUT, ">", $file or die Fudge( "writing $file:" ); local $_; while( defined( $_ = <$IN> ) ) { $cb->(); print $OUT $_; } } ## end sub pie(&@) #~ pie { s/^\s+// } "myfile.txt"; #~ pie { s/^\s+// } "myfile.txt", ".orig"; #~ pie { s/^\s+// } "myfile.txt", "myfile.txt.bak"; #~ pie { s/^\s+// } @ARGV; ## $ perltidy -csc -csci=10 -cscl="sub : BEGIN END" -otr -opr -ce -nib +c -i=4 -pt=0 "-nsak=*" #~ my @files = Path::Class::Rule->new->file->name( qr/^rc\.itm\d+$/ )- +>max_depth(1)->all( $dir ); #~ my @files = File::Find::Rule->new->file->name( qr/^rc\.itm\d+$/ )-> +max_depth(1)->in( $dir ); #~ my @files = find( file => name => qr/^rc\.itm\d+$/ => max_depth => +1 => in => $dir ); #~ for my $file( @files ){ #~ pie { #~ m/start ux/ and s{^}{#} #~ } $file; #~ } #~ for my $file( @files ){ #~ pie \&uxcomment, $file; #~ } #~ for my $file( @files ){ #~ eval { pie \&uxcomment, $file } or warn $@; #~ } sub uxcomment { s/^\s+// } sub Main { my $dir = \@_; my $filefinder = find( file => name => qr/^rc\.itm\d+$/, max_depth => 1, start => $dir, ); while( my $file = $filefinder->match ) { eval { pie \&uxcomment, $file } or warn $@; } } ## end sub Main

In reply to Re^2: Write to existing file with character insert by Anonymous Monk
in thread Write to existing file with character insert by Mark.Allan

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
  • Outside of code tags, you may need to use entities for some characters:
            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 about the Monastery: (7)
    As of 2014-11-01 00:32 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      For retirement, I am banking on:










      Results (226 votes), past polls