Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

( [id://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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2024-04-16 05:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found