Any suggestions on how to declare a variable in a loop without overwriting it. I have to go through this report and pull data off of each line. So, if I store the data in variable and goes through the loop again, it re-initializes my variable.
open TESTFILE, "Y:/Perl Projects/TEST" or die "Couldn't open Test Repo
+rt file: $!";
my ($variable1, $variable2);
my @return_details,
while (my $test = <TESTFILE>) {
#if i delcare the variable here it will re-inialize it next tim
+e it loops through to an undef.
next if ($returns =~ m/^(\s)*$/);
print $returns;
if (substr($test , 80, 26) =~ m/1ST VARIABLE/) {
$variable1 = substr($returns, 113, 18);
next;
};
if (substr($test , 80, 25) =~ m/2ND VARIABLE/) {
$variable2 = substr($test, 113, 18);
$rt_flg = 1;
};
if ($rt_flg eq 1) {
push @return_details,
{ variable1 => $variable1,
variable2 => $variable2
};
$rt_flg = 0;
};
};
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.