in reply to help with an array

Use push(@array, $mytest); where you currently count:

use 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); }
or
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
    push was my first thought, but that would start the array off with element 0, not 1 as requested. The original post can have multiple interpretations though, so it's hard to say exactly what the desired result is without further clarification.
      so add an extra push at the top.