"John W. Krahn" wrote: > > Rob Dixon wrote: > > > > Marco wrote: > > > On Wed, Jan 22, 2003 at 01:07:19PM -0000, Rob Dixon > > > <[EMAIL PROTECTED]> wrote: > > > > > >> push @files, join ' and ', delete @files[-2,-1]; > > > > > > Your program successfully matches the entries, prints in which files > > > the string is found: > > > > > > Zone foo.com was found in files and boot.fixed > > > > > > But it also prints the following warnings: > > > Use of uninitialized value in join or string at checkdomain.pl line > > > 19, <> line 1. > > > > Sorry, I didn't account for the cases where the zone was found in > > less than two files! > > > > while (<>) { > > chomp; > > if ($files = $zone{$_}) { > > if ((my @files = @$files) >= 2) { > > push @files, join ' and ', delete @files[-2,-1]; > > } > > print "Zone $_ was found in files ", join (', ', @files), > > "\n"; > > } else { > > print "Zone $_ was not found\n"; > > } > > } > > How about this: :-)
Oops! slight change. :-) use strict; use warnings; my %zone; # get zone names from named.conf type files @ARGV = qw( one.txt two.txt three.txt ); /^zone\b[^"]*"([^"]+)/ and push @{$zone{$1}}, "$ARGV, " while <>; # adjust output format for ( keys %zone ) { $zone{$_}[-1] =~ s/, $//; $zone{$_}[-2] =~ s/, $/ and / if @{$zone{$_}} > 1; } # report which zone names were found @ARGV = 'zonelist.input'; while ( <> ) { chomp; if ( @{$zone{$_}} ) { print "Zone $_ was found in files ", @{$zone{$_}}, "\n"; } else { print "Zone $_ was not found\n"; } } __END__ John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]