"JupiterHost.Net" wrote: > Hello List, > > It just occurred to me that many Perl functions use $_ if not other > value is supplied. chomp for instance..., which is very handy...
Yes. Like the peaceful feeling that comes the first time one shoots up junk. > If one wanted to write a function that used either the given argument or > $_ how would you do that? Don't > myfunc($myvalue); > or > myfunc; #uses the current value of $_ > > sub myfunc { > > my $func_arg = shift || 'some constant default value'; # you wouldn't just > do '|| $_;' would you? If you are going to use a construct like the above, you should have a constant default value. The loop variable $_ is for loop, not functions Be careful about what you ask for. While there is a good use for both the loop variable $_ and default values for certain cases where there may or may not be an argument offered, both approaches also present some serious dangers. It is much better to explicitly pass arguments. Dependency on magic effects can make your code very fragile and very hard to debug. Joseph -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>