in reply to Simple hash assignment...or is it?

One of Perl's cooler selling points is being able to substitute for programs like cut, grep, uniq, and sort by using native Perl functions.

I've rewritten what you have a little (the output is different, but I think I get the gist of what you're trying to do) so that the only shell is for the netstat command.

#!/usr/bin/perl use strict; my %adapter_names = (); for (split /\n/, `netstat -i`) { next if /lo|sit|link|Name/; /(\S+)/; # Takes first block of non-spaces, assigns to $1 my $interface = $1; my $adapter = $interface; $adapter =~ s/^en/ent/; # Add other substitutions here $adapter_names{$adapter} = $interface if !defined $adapter_names{$ad +apter}; } print "$_ : $adapter_names{$_}\n" for sort keys %adapter_names;

Replies are listed 'Best First'.
Re: Re: Simple hash assignment...or is it?
by arootbeer (Novice) on Nov 22, 2003 at 06:35 UTC
    Yeah...Perl is really cool. As I said before (see above) I come from a functional/procedural background, so that's what my code tends to look like. (Personally, I like parenthesizing... :)

    This code is very nice, very clean. I wonder what the speed difference is? I may adopt this style in a later revision (although possibly still pre-production) because the program is part of a stress level monitoring toolkit, with the obvious desire to keep the induced stress as low as possible. So, if I can exec 1 program instead of 5, I lower the induced stress quite a bit.