[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



Peter Makholm wrote:
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.

Nej det er klart, når jeg piller noget ud af listen ved hver gennemkørsel er det da klart at det går op i fisk.



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";
}


Jep, det hjalp straks på resultatet, mange tak :-)


/Magnus


-- "Ford, you're turning into a penguin. Stop it."

Douglas N. Adams (1952-2001)

 
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] *