Dear monks
I am not able to figure out how to give a new name to array for each iteration of 'for' loop. Below is the part of a big code so pl bear with me. I am concerned with
'LINE C' only. This works for LINE A and B perfectly but for LINE C, it is showing
Type of arg 1 to push must be array (not concatenation (.) or string)
+at avgshuffle.pl line 36, near "})"
Execution of avgshuffle.pl aborted due to compilation errors.
Pl tell me how can I change the array of the problem in every iteration.. and if possible what is the better way of solving this mess.
Thank you for taking out time to read this
for (my $x=1; $x<=5; $x++)
{
open (AA, "shuffle$x"); # LINE A
my $Sequence;
while (<AA>)
{
$Sequence=$_;
}
close(AA);
my %Winenergy = Energy($Sequence,$dinu_r);
open (OUT, ">shuffle$x.stb"); # LINE B
foreach my $el1(sort{$a <=> $b} keys %Winenergy)
{
print @energy.$x;
push(@energy.$x , $Winenergy{$el1}); #LINE C
# print OUT "$el1\t $Winenergy{$el1}\n";
}
#print OUT "\n";
close (OUT);
}
sub Energy
{
....
}
open(FILE,">total_shuffle.stb");
$m=8;
for($j=0;$j<$i;$j++)
{
$avg = ($energy1[$j]+$energy2[$j]+$energy3[$j]+$energy4[$j]+$energy5[$
+j])/5;
print FILE "$m\t$avg\n";
$m++;
}
close (FILE);
formatting added by GrandFather
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.