You're making this a lot harder than it needs to be.

#!/usr/bin/perl use 5.010; use strict; use File::Slurp qw(edit_file_lines); use Path::Class qw(file dir); use constant SKIP => 'SKIP'; use constant SIMULATION => 1; sub process_file { my ($file, %param) = @_; # skip files that need skipping if ($param{skip}->($file) eq SKIP) { say { $param{log} } "Skipping $file"; return 0; } if ($file->is_dir) { my $modified = 0; say { $param{log} } "Recursing into directory $file"; foreach ($file->children) { $modified += process_file($_, %param); } say { $param{log} } "Finished with directory $file - modified +$modified files inside"; return $modified; } say { $param{log} } "Processing file $file"; my $i = 0; my $modified = 0; edit_file_lines { $i++; foreach my $change (@{ $param{changes} }) { my ($match, $replace) = @$change; if (/$match/) { say { $param{log} } "Line $i matched $match - replacin +g with $replace"; $modified = 1; s/$match/$replace/g unless SIMULATION; } } } $file; say { $param{log} } "Done with file $file"; return $modified; } process_file( # starting point for crawl dir('somedir'), # list of changes to make changes => [ [ qr{ChangeThis}i => 'ToThis' ], [ qr{ChangeThat}i => 'ToThat' ], ], # sub which returns SKIP if a file (or directory) should be skippe +d skip => sub { my $file = shift; if ($file->is_dir and [$file->dir_list]->[-1] !~ /^[a-zA-Z0-9] +/) { return SKIP; } return; }, log => file('changling.log')->openw, );
perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

In reply to Re: Break out of program to get correct logic (total count) by tobyink
in thread Break out of program to get correct logic (total count) by begood321

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, 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.