use strict;
use warnings; # as well!
my $countline = 0; my $mytest; open (MYFILE,"<testing.txt")||die "Could not open input file\n";
(A matter of personal preference but
open my $fh, '<', "testing.txt" or die "Could not open input file: $!\ +n";
may be better. Pay attention to all the details...)
while($mytest = <MYFILE>) {
You may want
while( defined($mytest = <MYFILE>) ) {
to be more precise. Which is a good reason IMHO to use Perl's idiomatic
while(<MYFILE>) {
my @datas= split (/\s+/, $mytest); if ($datas[0] eq "Hello")
Incidentally, no need to create the array:
if ( (split /\s+/, $mytest)[0] eq "Hello" )
works just fine. Also, splitting on /\s+/ is actually different from splitting on ' ' (see perldoc -f split) but the latter is in most cases what one really wants, and in fact it is also the default. So, had you also used the topicalizer as hinted above, this may have been just as simple as
if ( (split)[0] eq "Hello" )
and in that case I would have used it as a statement modifier:
$countline++ if +(split)[0] eq "Hello";
my @test1 = $countline; print $test1[0];
Huh?!?

all in all if I understand correctly what that you want to achieve, this may have been just as simple as

while (<>) { push @wanted, $_ if +(split)[0] eq "Hello" }
(but you may also want to chomp.)

In reply to Re: help with an array by blazar
in thread help with an array by cravena

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.