in reply to Re: Another Challenge: Splitting data into chunks part2
in thread Another Challenge: Splitting data into chunks part2

Yes, I have posted the wrong code!!!! It really has been very long day/night.

Your code works, but how can I combine 2 loops into one? What I mean is this
#! c:/perl/bin/perl.exe use strict; my ($Rec2, $pc_name); my ($hash,$key); open (LST,"c:/showtech".$ARGV[0].".txt") || die "$!\n"; while(<LST>) { $key = $1, next if (/interface port-channel (\d+)$/); $hash->{$key}->{$1} = $2 if (/switchport description To (\w+) ([\d +\.]+)/); } close LST; open (LST,"c:/showtech".$ARGV[0].".txt") || die "$!\n"; while(<LST>) { $pc_name = $1, next if (/(port-channel \d+)$/); $Rec2->{$pc_name}->{$1} = $2 if (m|(fc\d+/\d+)\s+\[(\w+)\]|); } for my $data (keys %{$Rec2}) { print "\n$data \n"; } for my $data (keys %{$hash}) { print "$data\n"; }
I am sure I don't have to open the file twice. but not sure on how to do it. If I merge both loops then only one loop works!
Blackadder

Replies are listed 'Best First'.
Re^3: Another Challenge: Splitting data into chunks part2
by goldclaw (Scribe) on Sep 21, 2005 at 16:11 UTC
    If you change your loop to something like this is should work:
    my $iname; while(<LST>) { $iname=$1, next if /port-channel (\d+)/; next if !defined $iname; $hash->{$iname}->{$1} = $2 if (/switchport description To (\w+) ([\d\.]+)/); $Rec2->{$iname}->{$1} = $2 if (m|(fc\d+/\d+)\s+\[(\w+)\]|); }
    Note, there is one small difference with the results you got from your code. Im sure you can see it, and fix it if its important:-)

    gc