in reply to help with an array
Use push(@array, $mytest); where you currently count:
oruse strict; use warnings; my $mytest; my @array; open(MYFILE, '<', 'testing.txt') || die "Could not open input file\n"; while ($mytest = <MYFILE>) { my @datas = split(/\s+/, $mytest); push(@array, $mytest) if $datas[0] eq "Hello"; } # my $countline = @array; print("The matching lines:\n"); foreach my $line (@array) { print($line); }
use strict; use warnings; open(MYFILE, '<', 'testing.txt') || die "Could not open input file\n"; my @array = grep { my @datas = split(/\s+/, $_); $datas[0] eq "Hello" } <MYFILE>; # my $countline = @array; print("The matching lines:\n"); foreach my $line (@array) { print($line); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: help with an array
by kwaping (Priest) on Jul 29, 2005 at 15:12 UTC | |
by ikegami (Patriarch) on Jul 29, 2005 at 15:44 UTC |