sunadmn has asked for the wisdom of the Perl Monks concerning the following question:

Good day all I have a problem with a script I am using to
parse DNS zone data it looks as if my parse runs
but my output looks very strange instead of a
filename that looks like "file.com" I am getting
"file
.com"

readmore I have attached the code so you all can see it and
maybe give me some insite as to why my output is munged
#!/usr/bin/perl -w $| = 1; use DNS::ZoneParse; use Data::Dumper; $out_dir = "/var/tmp/abs"; $list = "/var/tmp/list"; open(IN, "$list"); @files = <IN>; for(@files) { $line = "$_"; $out = join('.', ( split('/', $line) )[-1,-2]); $dns = DNS::ZoneParse->new("$line"); open(OUT, ">$out_dir/$out") or die "Cant create $out_dir/$out: $!\n +"; print OUT Data::Dumper->Dump([$dns->soa]) . "\n"; close(OUT); } close(IN); exit;

Replies are listed 'Best First'.
Re: Parse output
by dragonchild (Archbishop) on Aug 11, 2003 at 18:52 UTC
    1. Although it's not your problem, use strict;
    2. Change @files = <IN>; to chomp(my @files = <IN>); - that will fix your problem.
    3. A style note: Change for(@files) { to for my $line (@files) { and get rid of the next line. :-)

    ------
    We are the carpenters and bricklayers of the Information Age.

    The idea is a little like C++ templates, except not quite so brain-meltingly complicated. -- TheDamian, Exegesis 6

    Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

Re: Parse output
by japhy (Canon) on Aug 11, 2003 at 20:15 UTC
    There's also no reason to slurp the contents of the file into an array.
    open IN, "< $list" or die "can't read $list: $!"; while (my $line = <IN>) { chomp $line; my $out = join ".", (split '/', $line)[-1,-2]; my $dns = DNS::ZoneParse->new($line); # ... }

    _____________________________________________________
    Jeff[japhy]Pinyan: Perl, regex, and perl hacker, who'd like a job (NYC-area)
    s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

Re: Parse output
by cbro (Pilgrim) on Aug 11, 2003 at 18:53 UTC
    You may need to do a chomp to delete trailing newlines on the list entries coming from @files.
    HTH,
    Chris
Re: Parse output
by CountZero (Bishop) on Aug 11, 2003 at 19:58 UTC

    Further to the comments hereabove (which will solve your problem), I may add that there is no reason to put quotes around $_ in $line = "$_".

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law