Which pertains to the subroutine beginning with $target_file->edit( sub I am currently updating my CPAN modules (which is taking quite a long time) in hopes that will resolve the issue. EDIT: Updating CPAN modules did not resolve this issue. EDIT 2: After doing some more digging, it looks like the edit method comes from Path::Tiny, so I tried changing the start of the subroutine like so:Can't locate object method "edit" via package "IO::File" at searchandreplace.pl line 65 (#1) (F) You called a method correctly, and it correctly indicated a packag +e functioning as a class, but that package doesn't define that particula +r method, nor does any of its base classes. See perlobj.
Which gets me a Use of uninitialized value $_ in scalar assignment at searchandreplace.pl line 54 (#1) error. Line 54 is pos($_) = $pos;.sub search_and_replace { open my $target_file, "<", $_; my $filename = path($_); my $pos = 0; my $more = 1; while( $more ) { $filename->edit( sub { pos($_) = $pos; if( /$match/g ) { my ( $was, $where, $pre, $post ) = ( $1, $-[1], $`, $'); print "\n", $pre =~ s/^.*\n(?=.*\n)//sr, "$old$was$reset", $post =~ s/\n.*?\n\K.*//sr, "\n"; my $replace = ask( $was ); $was eq $replace or substr $_, $where, length $was, $replace +; $pos = $where + length $replace; } else { $more = 0 } } ); # print "\e[33m", $target_file->slurp, "\e[0m"; # FIXME here for + testing } close $target_file; }
In reply to Re^8: Immediately writing the results of search-and-replace
by elemkeh
in thread Immediately writing the results of search-and-replace
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |