I wonder if someone could provide me with an explanation for the following:

(I have left in my debugging print statements.)

#!/usr/bin/perl -w use strict; use CGI ':standard'; my $data="/path/data_add.txt"; my $checkthree = param('check'); my $num = param('num'); my $action = param('action'); my @line1 = (); my @line_no = (); my ($one,$two,$three,$four,$five); print header(), start_html; open (FILE,"$data") || die "whoops: $!"; while (my $line =<FILE>) { ($one,$two,$three,$four,$five) = split "\t",$line; if (($action eq 'Put') && ($three eq $checkthree)) { $five = $five + $num; print "we have $five on line $.<br>"; @line1 = ($one,$two,$three,$four,$five); push (my @line_no, $.); print "Did this work @line_no<br>"; last; } elsif (($action eq 'Take') && ($three eq $checkthree)) { $five = $five - $num; @line1 = ($one,$two,$three,$four,$five); push (@line_no, $.); last; } } close FILE; if ($five < 0) { print "message: can't do this"; } else { my $line1 = join "\t", @line1; print "taking it out of the loop we have @line_no<br>"; my $line_no = join " ", @line_no; print "we have $five on line $line_no<br>"; open (FILE,"$data") || die "whoops 1: $!"; my @all=<FILE>; close (FILE); $all[$line_no-1] = $line1; open (FILE2,">$data.tmp") || die "whoops 2: $!"; foreach my $line (@all){ $line=~s/\n//g; print FILE2 "$line\n";} close(FILE2); rename("$data.tmp", "$data") || die "whoops 3: $!"; print "the field now contains: $five"; } print end_html();

My first question is:
having declared

my @line1 = (); my @line_no = ();
I had expected both values to exit the loop - only @line1 does.
(The print statement in the loop shows that @line_no works properly there).
Why is it subsequently unseen, and what can I do to remedy this?
Thanks very much.

In reply to Picking up information coming out of a loop by jonnyfolk

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.