Rob Dixon wrote:
>
> Hello John.
Well hello Rob,
> 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 <>;
I still like /"([^"]+)/ better than /"(.+?)"/. :-)
> 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;
I think you mean:
$files = join ' and ', (join ', ', @files), $_ for pop @files;
But that will prepend ' and ' if there is only one file name in @files.
It also doesn't seem right to use a loop just to force 'pop @files' to
evaluate first.
> An interesting point here. I don't think there's a way to persuade
> loops to return a value.
I think you mean "I don't think there's a way to persuade loops to
return a scalar." and no, you have to use join/concatenation to
transform a list/array to a scalar.
> $a = do { 'abc' foreach (1) };
>
> gives 'useless use of a constant' for 'abc', but it seems a reasonable
> thing to do.
It does?
> Any ideas?
Sorry, no.
> 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.
It will if strictures are enabled. :-)
> That's why I postponed the dereference in my V2. How about:
if ( ref $zone{$_} and @{$zone{$_}} ) {
> 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 :-?
Don't forget -- TMTOWTDI
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]