|
Hi all, I'm new to Perl and can't figure this one out. I downloaded what I believe to be the current stable version of ActivePerl for Windows (version 5.8.x, I think; how do I find out what version I have? The download file is called ActivePerl-5.8.8.820-MSWin32-x86-274739.zip) I also downloaded OpenPerlIDE, since I wanted a Windows IDE- I have no particular reason for choosing this one except that it is free, and because it was apparently written in Delphi, which I am familiar with). After some experimentation and consulting of manual pages, and posting a question to this form, I've gotten some simple things to work. Every attempt I've made to use a for loop has produced wierd results, such as the peice of code following. When I rewrite the code using a while loop, everything looks okay. Have i stumbled onto a bug in ActivePerl or in the OpenPerlIDE, or am I making some newbie mistake??
[code] # testforloop.pl for ($i=1,$i<=10,$i++) { print ('loop number: ',$i,"\n"); }
[result output] loop number: 2 loop number: 2 loop number: 2
# strange, wouldn't you say? # or try this one
# examine representation of numerical values for ($i=1,$i<=10,$i++) { $result1=sprintf("%d","$i"); $result2=sprintf("%e","$i"); $result3=sprintf("%f","$1"); print ($result1," ",$result2," ",$result3,"\n"); } print ("\n"); # strange results! # now try a while loop- this seems to work $i=1; while ($i<=10) { $result1=sprintf("%d","$i"); $result2=sprintf("%e","$i"); $result3=sprintf("%f","$1"); print ("$i: ",$result1," ",$result2," ",$result3,"\n"); $i++; }
[result output] 2 2.000000e+000 0.000000 2 2.000000e+000 0.000000 2 2.000000e+000 0.000000
1: 1 1.000000e+000 0.000000 2: 2 2.000000e+000 0.000000 3: 3 3.000000e+000 0.000000 4: 4 4.000000e+000 0.000000 5: 5 5.000000e+000 0.000000 6: 6 6.000000e+000 0.000000 7: 7 7.000000e+000 0.000000 8: 8 8.000000e+000 0.000000 9: 9 9.000000e+000 0.000000 10: 10 1.000000e+001 0.000000
[\code]
Thanks for the help.
|