in reply to Re: Splitting data into chunks!
in thread Splitting data into chunks!

Since this is the shortest code, I used it.

My question is how do I access the 3rd element (i.e. the UP value)?

This is what I did;
use strict; use warnings; use Data::Dumper; my ($Rec,$pc_name); while (<DATA>) { $pc_name = $1, next if (/(port-channel \d+)$/); $Rec->{$pc_name}->{$1} = $2 if (m|(fc\d+/\d+)\s+\[(\w+)\]|); } for my $data (keys %{$Rec}) { print "\n$data \n"; for my $data2 (keys %{$Rec->{$data}}) { print "\t$data2 : \n"; } } __DATA__ port-channel 1 Administrative channel mode is on Operational channel mode is on Last membership update succeeded First operational port is fc1/5 2 ports in total, 2 ports up Ports: fc2/5 [up] fc1/5 [up] * port-channel 3 Administrative channel mode is on Operational channel mode is on Last membership update succeeded First operational port is fc1/1 1 port in total, 1 port up Ports: fc1/1 [up] *
Output
C:\Perl\test>pm_data_chunks.pl port-channel 1 : fc2/5 : fc1/5 : port-channel 3 : fc1/1 :
Blackadder
************************UPDATE***********************

I've added this: print "\t$data2 : $Rec->{$data}->{$data2}\n";

Sorry for my hasty post...Many Thanks.

Replies are listed 'Best First'.
Re^3: Splitting data into chunks!
by sh1tn (Priest) on Sep 21, 2005 at 09:15 UTC
    Change the second print like that:
    ... no strict 'refs'; for my $data2 (keys %{$Rec->{$data}}) { print "\t$data2: \t $Rec->{$data}{$data2} \n"; } ...