Re: foreach debate (was Re: -w vs. use warnings)
On Fri, 2003-08-29 at 08:21, David T-G wrote: Kevin -- ...and then K Old said... % ... % % The posting a few weeks ago about for vs. foreach was interesting and got % me thinking about warnings. That sounds really interesting; unfortunately I haven't kept up enough to see it. Do you recall some particularly-identifiable text from the thread that I could use to search it out? David, The posting was Re: Very slow array searching by George P. snip Or, for the memory conscious, (since foreach involves loading all elements into memory) $l_status = 'FALSE'; for (my $i=0; $i @numbers; $i++) { if ($numbers[$i] == $l_number) { $l_status = 'TRUE'; last; } } /snip I'm not sure how to benchmark this, but would be very interested if someone knew how. I'd like to see it just for fun. Hope this helps, Kevin -- K Old [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: -w vs. use warnings
K == K Old [EMAIL PROTECTED] writes: K Randal Schwartz uses this: K #!/usr/bin/perl -w K use strict; K $|++; K Is there any difference between the -w and use warnings declaration? Compatability with 5.005. use warnings was added in 5.6, and my ISP ran 5.005 only until a year ago, so I had to use 5.5-compatible code until recently. And, it's more typing. :) K One other item, Randal uses $|++; to turn off the buffering for STDOUT. K What exactly is buffering of standard output? Others have answered that here. I have nothing to add to that. -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 [EMAIL PROTECTED] URL:http://www.stonehenge.com/merlyn/ Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: -w vs. use warnings
Having been a Perl programmer for several years now I have become accustom to using the following as my normal start of any Perl script: #!/usr/bin/perl use warnings; use strict; Randal Schwartz uses this: #!/usr/bin/perl -w use strict; $|++; Is there any difference between the -w and use warnings declaration? I know that both turn on warnings and the -w is commonly used at the command line, but was just curious as to if one was better than the other. use warnings only exists in Perl 5.004_05 or later. If you want your scripts to work in Perl interpreters earlier than that (the still prevalent 5.004_04), then you'll need to use -w. Note: I may be slightly what crack is he smoking? on my version numbers - it's been a while. I prefer use warnings myself - people really should try their damndest to update. As for $|++, there was a recent debate (on Perlmonks.com, I believe) on how $|=1 may be a better visual choice than $|++. I haven't made up my mind either way - I still use ++ in my own scripts. Unfortunately, I couldn't find the Perlmonks.com link, so I may have just dreamt this. -- Morbus Iff ( i put the demon back in codemonkey ) Culture: http://www.disobey.com/ and http://www.gamegrene.com/ Buy My Book! http://amazon.com/exec/obidos/ASIN/0596004605/disobeycom icq: 2927491 / aim: akaMorbus / yahoo: morbus_iff / jabber.org: morbus -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: -w vs. use warnings
On 28 Aug 2003 16:17:21 -0400, K Old [EMAIL PROTECTED] wrote: Hello everyone, Having been a Perl programmer for several years now I have become accustom to using the following as my normal start of any Perl script: #!/usr/bin/perl use warnings; use strict; Randal Schwartz uses this: #!/usr/bin/perl -w use strict; $|++; Is there any difference between the -w and use warnings declaration? The one difference that I am aware of is the scoping. -w applies warnings to *all* code executed, whereas use warnings is file scoped (I believe) so that if you are working with a number of different modules that might cause warnings to be issued you will not see them under the 'use' method, but under -w you will. I prefer this because it gives me more direct control, but as the other poster mentioned I am only dealing with 5.6.0 and newer interpreters these days... I know that both turn on warnings and the -w is commonly used at the command line, but was just curious as to if one was better than the other. The posting a few weeks ago about for vs. foreach was interesting and got me thinking about warnings. One other item, Randal uses $|++; to turn off the buffering for STDOUT. What exactly is buffering of standard output? Its actually buffering of the currently selected file handle which is usually STDOUT. Output is buffered until there is a significant amount so that the relatively expensive output process doesn't happen over and over. Though in most cases these days I doubt it has a significant negative performance impact. Usually I leave things alone until I need them, but to each their own, and I think it is safe to assume Randal knows what he is doing :-). http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: -w vs. use warnings
On Thu, Aug 28, 2003 at 04:17:21PM -0400 K Old wrote: Having been a Perl programmer for several years now I have become accustom to using the following as my normal start of any Perl script: #!/usr/bin/perl use warnings; use strict; Randal Schwartz uses this: #!/usr/bin/perl -w use strict; $|++; Is there any difference between the -w and use warnings declaration? I know that both turn on warnings and the -w is commonly used at the command line, but was just curious as to if one was better than the other. They are not the same thing, although somewhat related. The warnings pragma gives you very fine-graned control. It turns on warnings for blocks and can likewise be switched off for them. Furthermore, you can surpress particular warning categories altogether as in use warnings; $a = $b = foobar; print undef; { no warnings 'uninitialized'; print undef; print $a + $b; } print undef; __END__ Use of uninitialized value in print at - line 3. Argument foobar isn't numeric in addition (+) at - line 7. Argument foobar isn't numeric in addition (+) at - line 7. Use of uninitialized value in print at - line 9. As you see, no warning for line 6, but a warning for the line 7 in the same scope. The various categories that exist are listed in perllexwarn.pod. -w on the other hand is truely global. Turn it on anywhere and suddenly warnings show up from code that you haven't even written (like warnings produced in modules you use). They can be turned off lexically scoped by issuing local $^W = 0; though. But you can't distinguish between a warning caused by comparing a string with a number and, for instance, one caused by using undefined values. One other item, Randal uses $|++; to turn off the buffering for STDOUT. What exactly is buffering of standard output? Buffering means that the data you send to a channel isn't going through right away but ends up in a buffer. STDOUT is typically line-buffered. That means, data go to STDOUT but wont be printed before a newline was sent (or the buffer is full). This is an efficiency thing because it reduces the number of syscalls. STDERR is typically not buffered which explains why you often get messages to STDERR before the regular output to STDOUT. Tassilo -- $_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({ pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#; $_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: -w vs. use warnings
K Old wrote: Hello everyone, Hello, Having been a Perl programmer for several years now I have become accustom to using the following as my normal start of any Perl script: #!/usr/bin/perl use warnings; use strict; Randal Schwartz uses this: #!/usr/bin/perl -w use strict; $|++; Is there any difference between the -w and use warnings declaration? I know that both turn on warnings and the -w is commonly used at the command line, but was just curious as to if one was better than the other. The warnings pragma was added to Perl5 to allow lexical scoping of warnings and allow finer control over which warnings to use/not use. #!Perl4 LOOP: { local $^W; # turn off ALL warnings # do something that will produce a warning message } #!Perl5 LOOP: { no warnings 'numeric'; # do something that will produce a 'numeric' warning message } perldoc perllexwarn The posting a few weeks ago about for vs. foreach was interesting and got me thinking about warnings. One other item, Randal uses $|++; to turn off the buffering for STDOUT. What exactly is buffering of standard output? It doesn't turn off buffering, it effects whether the currently selected file handle will autoflush its output. #!/usr/bin/perl $|++; # turn on autoflush for the currently selected filehandle (STDOUT). select STDERR; # select a different filehandle $| = 1; # turn on autoflush for the currently selected filehandle (STDERR). John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: -w vs. use warnings
Michael, Read 'perlexwarn' in the perl documentation for a complete discussion. HTH, Charles K. Clarkson -- Head Bottle Washer, Clarkson Energy Homes, Inc. Mobile Home Specialists 254 968-8328 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: -w vs. use warnings
Charles K. Clarkson wrote at Wed, 02 Jul 2003 13:43:26 -0500: Read 'perlexwarn' in the perl documentation ^ Better to read perldoc perllexwarn ^^ for a complete discussion. Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]