Hello all,
Been ages since I programmed. Appologize for my rustyness but I have the following text file:
What I need to do is extract the "Peers" and the number below associated with it (in this case 2 under it) and the "Established" and the number associated with that (in this case 1).
So the "Peers" and "Established" are on the first line of the file and the numbers that correspond with them are on the line below as in one is the column heading and the other is the value.
Seemed straight forward to me just load each line in an array and them extract the corresponding array element into a hash.
Not working.
Here is my code:
Output:
tried:
@array . "$i" = $_;
"@array" . "$i" = $_;
blah blah...no go.
Gotta be a better way!
Any help is appriciated (as always)
Nick
If at first you don't succeed, don't try skydiving.
Been ages since I programmed. Appologize for my rustyness but I have the following text file:
Code:
Group Type Peers Established Active/Received/Damped
BRIB_PEERS Internal 2 1
What I need to do is extract the "Peers" and the number below associated with it (in this case 2 under it) and the "Established" and the number associated with that (in this case 1).
So the "Peers" and "Established" are on the first line of the file and the numbers that correspond with them are on the line below as in one is the column heading and the other is the value.
Seemed straight forward to me just load each line in an array and them extract the corresponding array element into a hash.
Not working.
Here is my code:
Code:
use strict;
use warnings;
my @array1;
my @array2;
my %hash;
my %hash1;
my $logfile = "D:\\Stage\\out.log";
my $out_file = "D:\\Stage\\test5.txt";
open (IN, "$out_file") or die ("Error opening cli file $out_file: $1");
my $i = 0;
while (<IN>) {
$i++;
chomp;
@array$i = $_;
}
$hash{$array1[2]} = $array2[2];
$hash1{$array1[3]} = $array2[3];
my $k;
my $v;
while ( ($k,$v) = each %hash ) {
print "$k => $v\n";
}
Output:
Code:
D:\Stage>bpBellSouthCoyote_3.pl
Scalar found where operator expected at D:\Stage\bpBellSouthCoyote_3.pl line 42,
near "@array$i"
(Missing operator before $i?)
Global symbol "@array" requires explicit package name at D:\Stage\bpBellSouthCoy
ote_3.pl line 42.
syntax error at D:\Stage\bpBellSouthCoyote_3.pl line 42, near "@array$i "
Execution of D:\Stage\bpBellSouthCoyote_3.pl aborted due to compilation errors.
tried:
@array . "$i" = $_;
"@array" . "$i" = $_;
blah blah...no go.
Gotta be a better way!
Any help is appriciated (as always)
Nick
If at first you don't succeed, don't try skydiving.