[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [PROGRAMMERING] [perl] for lykke stoppe i utide



Magnus Pedersen <sslug@sslug> writes:

> for (@liste) {
> 	
> 	$total = ((shift @liste)+$total);
> 	
> 	#Lad os lige teste og se om den gør det rigtigt undervejs.
> 	print "$total", "\n\n";
> }

Jeg tror ikke det er helt veldefineret at ændre den liste du itererer
over.

"shift @liste" ændrer på på den liste som du løber igennem 'for
(@liste)' og jeg har ingen ide om hvordan perl skulle opfører sig på
en fornuftig måde i det tilfælde.

Udnyt hellere at for hver gang rundt i løkken bliver den magiske
variabel $_ knyttet til et nyt element i listen. Det du vil er altså
noget ala:

for (@liste) {
    $total = $total + $_;

    # test...
    print "$total\n\n";
}

-- 
 Peter Makholm     |               Vi smider blade allesammen - hele tiden
 sslug@sslug |                      som et konstant spirende efterår
 http://hacking.dk |                 Og hele tiden vokser nye frugter frem
                   |                  og vi finder nogen til at plukke dem
                   |                            -- Tilt, Perkussive popler


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-09-01, 02:01 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *