Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^2: Running out of memory while running this for loop

by Ppeoc (Beadle)
on Nov 01, 2015 at 21:57 UTC ( [id://1146639]=note: print w/replies, xml ) Need Help??


in reply to Re: Running out of memory while running this for loop
in thread Running out of memory while running this for loop

Yes! You are right. Thank you for catching that error. I was adding index value to array reference. How can I change my for loop to make it work?
  • Comment on Re^2: Running out of memory while running this for loop

Replies are listed 'Best First'.
Re^3: Running out of memory while running this for loop
by AnomalousMonk (Archbishop) on Nov 01, 2015 at 22:45 UTC

    The "Perlish" way to iterate element-by-element over an array is:

    c:\@Work\Perl\monks>perl -wMstrict -le "my @array = qw(zero one two three); ;; for my $element (@array) { print qq{element '$element'}; } " element 'zero' element 'one' element 'two' element 'three'
    If each "element" of  @array is actually an array reference, you might then need to iterate in turn over the referenced array in similar fashion:
    c:\@Work\Perl\monks>perl -wMstrict -le "my @array = ( [ 1, 2, 3, ], [ 'v' .. 'z' ], [ qw(one two) ], ); ;; for my $arrayref (@array) { for my $element (@$arrayref) { printf qq{'$element' }; } print ''; } " '1' '2' '3' 'v' 'w' 'x' 'y' 'z' 'one' 'two'
    Please see perldsc for more info and examples.


    Give a man a fish:  <%-{-{-{-<

      Thank you so much! I now understand what I was doing wrong. Got it to work with the following piece of code
      for my $i ( 2033 .. $#data ) { if (($i-$n)%6267== 0) { $color = $data[$i][0]; $order= $data[$i+1][0]; $shape = $data[$i+3][0]; $name = $data[$i+4][0]; } print $out_ph1 $predata,",", $color,"," ,$order,"," ,$shape,", +" ,$name,","; for my $j ( 4 .. $#{ $data[$i] } ) { print $out_ph1 $data[$i][$j],"\_"; } print $out_ph1 "\n"; }
      Thank you monks!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1146639]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2024-04-16 18:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found