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 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>