in reply to multiple-pass search?

use Tie::File; sub replace_serialnumbers_in_file($) { my @word = qw( zero one two three four five six seven eight nine ) +; my $filename = shift; my $serno = join '', map $word[$_], $filename =~ /(\d)/; # assumin +g no other digits in the filename tie my @lines, 'Tie::File', $filename or die; s/\\zerozerozero/\\$serno/g for @lines; }

You don't need multipass if you take the serial number from the filename.

I reckon we are the only monastery ever to have a dungeon staffed with 16,000 zombies.

Replies are listed 'Best First'.
Re^2: multiple-pass search?
by propellerhat (Novice) on Dec 09, 2021 at 22:39 UTC

    Here is how I extract the serial number from the filename:

    use File::Find; my $dir = "documents"; find( sub { my $filename = $_; return unless ( $filename =~ /abstract-([0-9][0-9][0-9]).tex/ && -f $filename ); my $serialnumber = $1 ;

      So I take it the filename will have the exact pattern abstract-NNN.tex. If so, the regex you gave is too broad. It will match, for example, nonabstract-000stexts. You need to anchor the beginning and end, and escape the dot: /^abstract-(\d{3})\.tex$/

        I understand; I plead ignorance, and have made note. However, I am searching in a directory in which there are only *-xxx.tex files, with separate directories for articles, abstract, and catalogue.