Hello John.
John W. Krahn wrote:
>> 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 <>;
I like:
/^zone\b/ and /"(.+?)"/ and push @{$zone{$1}}, "$ARGV," while <>;
Also you don't need a space after the comma if you're stringifying the
array in the final print().
>
> # adjust output format
> for ( keys %zone ) {
> $zone{$_}[-1] =~ s/, $//;
> $zone{$_}[-2] =~ s/, $/ and / if @{$zone{$_}} > 1;
> }
>
Hmm. It works but, being a purist, I don't like using 'decorated'
filenames as hash keys. I came up with this:
my $files;
$files = join ' and ', (join ', ', @a), $_ for pop @files;
An interesting point here. I don't think there's a way to persuade
loops to return a value.
$a = do { 'abc' foreach (1) };
gives 'useless use of a constant' for 'abc', but it seems a reasonable
thing to do. Any ideas?
Another option to all this is to use the field separator:
local $" = ', ';
leaving only the ultimate ' and ' separator as a special case
> # report which zone names were found
> @ARGV = 'zonelist.input';
> while ( <> ) {
> chomp;
> if ( @{$zone{$_}} ) {
One hole, two programmers! If the zone wasn't found then $zone{$_}
is undefined and Perl dies trying to dereference it. That's why I
postponed the dereference in my V2. How about:
if (my $zone = $zone{$_} and @$zone) {
print "Zone $_ was found in files ", @$zone, "\n";
}
> print "Zone $_ was found in files ", @{$zone{$_}}, "\n";
> }
> else {
> print "Zone $_ was not found\n";
> }
> }
>
> __END__
Did somebody say this was a beginners' group :-?
Cheers,
Rob
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]