Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #55803 > unrolled thread

Perl Hacker, Python Initiate

Started byGary Chambers <gwchamb@gwcmail.com>
First post2011-02-01 23:36 -0500
Last post2011-02-03 08:12 -0800
Articles 4 — 4 participants

Back to article view | Back to comp.lang.python


Contents

  Perl Hacker, Python Initiate Gary Chambers <gwchamb@gwcmail.com> - 2011-02-01 23:36 -0500
    Re: Perl Hacker, Python Initiate Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-02-02 10:06 +0000
    Re: Perl Hacker, Python Initiate Ben Finney <ben+python@benfinney.id.au> - 2011-02-02 15:56 +1100
    Re: Perl Hacker, Python Initiate sturlamolden <sturlamolden@yahoo.no> - 2011-02-03 08:12 -0800

#55803 — Perl Hacker, Python Initiate

FromGary Chambers <gwchamb@gwcmail.com>
Date2011-02-01 23:36 -0500
SubjectPerl Hacker, Python Initiate
Message-ID<mailman.1576.1296621817.6505.python-list@python.org>
All,

Given the following Perl script:

#!/usr/bin/perl

%dig = (
     solaris => "/usr/sbin/dig",
     linux   => "/usr/bin/dig",
     darwin  => "/usr/bin/dig"
);

$DIG = $dig{"$^O"};
$DOMAIN = "example.com";
$DNS = "ns.example.com";
$DIGCMD = qq/$DIG \@$DNS $DOMAIN axfr/;

open DIG, "$DIGCMD|" or die "$DIG: $!\n";
while (<DIG>) {
     next if (/^;/); # Skip any comments
     # If we match a CNAME record, we have an alias to something.
     # $1 = alias (CNAME), $2 = canonical hostname
     if (/^(\S+)\.${DOMAIN}\.\s+\d+\s+IN\s*CNAME\s+(\S+)\.${DOMAIN}\.$/) {
         # Push an alias (CNAME) onto an array indexed on canonical hostname
         push(@{$cnames{$2}}, $1);
     }
     # Here's a standard A (canonical hostname) record
     # $1 = canonical hostname, $2 = IPv4 address
     if (/^(\S+)\.${DOMAIN}\.\s+\d+\s+IN\s*A\s+(\S+)$/) {
         $ip{$1} = $2;
     }
}
close DIG;

# Format and display it like niscat hosts:
# canonicalHostname alias1 [alias2 aliasN] ipAddress
for $host (sort keys %ip) {
     print "$host ";
     if (defined(@{$cnames{$host}})) {
         print join(' ', @{$cnames{$host}});
         print " ";
     }
     print "$ip{$host}\n";
}
exit 0;

Will someone please provide some insight on how to accomplish that task in
Python?  I am unable to continually (i.e. it stops after displaying a single
line) loop through the output while testing for the matches on the two
regular expressions.  Thank you.

-- Gary Chambers

[toc] | [next] | [standalone]


#55839

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2011-02-02 10:06 +0000
Message-ID<4d492cac$0$30000$c3e8da3$5496439d@news.astraweb.com>
In reply to#55803
On Tue, 01 Feb 2011 23:36:27 -0500, Gary Chambers wrote:

> All,
> 
> Given the following Perl script:

[snip line noise]

> Will someone please provide some insight on how to accomplish that task
> in Python?

No idea, I can't read Perl, and you shouldn't assume that people will be 
able to.

Can you simplify your problem to the smallest sub-task that you cannot 
perform? Focus on this part of the problem:

> I am unable to continually (i.e. it stops after displaying a
> single line) loop through the output while testing for the matches on
> the two regular expressions.  Thank you.

What Python code are you using to loop? Simplify the problem to focus on 
the fundamental problem, not the irrelevant details of looking up CNAME 
and A Records using dig.


-- 
Steven

[toc] | [prev] | [next] | [standalone]


#55851

FromBen Finney <ben+python@benfinney.id.au>
Date2011-02-02 15:56 +1100
Message-ID<87sjw7vxt6.fsf@benfinney.id.au>
In reply to#55803
Gary Chambers <gwchamb@gwcmail.com> writes:

> Given the following Perl script:
[…]
>
> Will someone please provide some insight on how to accomplish that
> task in Python? I am unable to continually (i.e. it stops after
> displaying a single line) loop through the output while testing for
> the matches on the two regular expressions. Thank you.

Insight will be easier to provide once we see your Python code.

-- 
 \              “In the long run, the utility of all non-Free software |
  `\      approaches zero. All non-Free software is a dead end.” —Mark |
_o__)                                                    Pilgrim, 2006 |
Ben Finney

[toc] | [prev] | [next] | [standalone]


#55896

Fromsturlamolden <sturlamolden@yahoo.no>
Date2011-02-03 08:12 -0800
Message-ID<e27628ac-76c6-4d4d-97cf-2504d402b3de@n11g2000vbm.googlegroups.com>
In reply to#55803
On 2 Feb, 05:36, Gary Chambers <gwch...@gwcmail.com> wrote:

> Given the following Perl script:

(...)

Let me quote the deceased Norwegian lisp hacker Erik Naggum:

"Excuse me while I barf in Larry Wall's general direction."


Sturla

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web