Re: file script and cmd script difference
- From: krahnj@xxxxxxxxx (John W. Krahn)
- Date: Thu, 29 Jun 2006 01:07:05 -0700
joseph wrote:
Hi list,
Hello,
I'd like to ask explaination/help regarding this:
1)perl -e '%hash; for (`arp`) {($addr,$mac) = (split(/\s+/))[0,2];
$hash{$addr}= $mac } foreach (keys %hash) { print "\t $_ => $hash{$_}\n";}'
Could be written more simply as:
arp | perl -lane'print "\t $F[0] => $F[2]"'
And if you don't want the header line:
arp | perl -lane'print "\t $F[0] => $F[2]" if $. != 1'
it emits the output which i'm hoping to see ex: wrkstation => MACADDR;
but this:
2)
#!/usr/bin/perl
use strict;
use warnings;
my %macs;
for (`arp`) {
my($addr,$mac) = (split(/s+/))[0,2];
You are telling split() to use one or more of the letter 's' to split on.
Better to use the default split behaviour:
my($addr,$mac) = (split)[0,2];
$macs{$addr} = $mac;
}
foreach my $key (keys %macs) {
print "\t $key => $macs{$key}\n";
}
John
--
use Perl;
program
fulfillment
.
- References:
- file script and cmd script difference
- From: Joseph
- file script and cmd script difference
- Prev by Date: Re: file script and cmd script difference (close)
- Next by Date: RE: cscope for perl?
- Previous by thread: Re: file script and cmd script difference (close)
- Next by thread: cscope for perl?
- Index(es):
Relevant Pages
|