blackadder has asked for the wisdom of the Perl Monks concerning the following question:
And I have this equally simple codeshow tech-support details -------------------- show switchname ------------------ CCC217_ANG_GREEN ****************************************************************** -------------------- show interface brief ------------------ ---------------------------------------------------------------------- +--------- mgmt0 up 10.33.81.54/20 100 Mbps 1500 ---------------------------------------------------------------------- +--------- Interface Vsan Admin Status Oper Oper IP Trunk Mode Speed Address Mode (Gbps) ---------------------------------------------------------------------- +--------- port-channel 1 1050 on trunking TE 4 -- port-channel 3 1 on trunking TE 2 -- ******************************************************************
The strange thing is; if I comment out undef $/ or local $/; then I would only get a value to either $Rec->{Switchname} or $Rec->{PortChannel_Num}! Never both at the same time! Not really sure why is this. I have tried anony-hashes before and they always worked, but not on this occasion.#! c:/perl/bin/perl.exe use strict; #undef $/; #local $/; my $eof_tmp = $/; #$/=""; open (FILE,"$ARGV[0]") || die "\n$!: $ARGV[0]\n"; my $Rec = {}; while (my $Info = <FILE>) { undef $/; $Rec->{Switchname} = $1 if ($Info =~ /-+ show switchname -+\n(\w+)/ +sm); $/ = $eof_tmp; $Rec->{PortChannel_Num} = $1 if ($Info =~ /^(port-channel \d+)$/); + } print "Switch Name: \t$Rec->{Switchname}\n"; print "Port Channel Number: \t$Rec->{PortChannel_Num}\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: $/ is playing havoc with my script.
by japhy (Canon) on Sep 26, 2005 at 13:02 UTC | |
|
Re: $/ is playing havoc with my script.
by graff (Chancellor) on Sep 26, 2005 at 13:09 UTC | |
|
Re: $/ is playing havoc with my script.
by sauoq (Abbot) on Sep 26, 2005 at 13:17 UTC | |
by chester (Hermit) on Sep 26, 2005 at 13:29 UTC | |
by sauoq (Abbot) on Sep 26, 2005 at 14:29 UTC | |
by chester (Hermit) on Sep 26, 2005 at 14:46 UTC | |
by sauoq (Abbot) on Sep 26, 2005 at 15:43 UTC | |
by Tanktalus (Canon) on Sep 26, 2005 at 19:09 UTC |