At 11:15 AM 1/30/02 -0800, Christopher Solomon wrote:

>I'm not well versed on the versions of Perl, but I don't think that was
>a particularly bug-free version.  I would recommend upgrading to at
>least 5.005_03

Actually 5.004_04 was quite stable.  'exists' was not extended to apply to 
arrays until a later version, that's all.  To some of us, it still looks at 
best misleading.

>On Wed, 30 Jan 2002, Nikola Janceski wrote:
>
> > I have two versions of perl (5.004_04, and 5.6.1)
> >
> > it seems the older one doesn't like the following code:
> >
> > sub somefunction {
> >       if(exists $_[0]){
> >               print "$_[0]\n";
> >               }
> >       }
> >
> > Output of perl -c (of 5.004_4):
> > exists operator argument is not a HASH element at ....
> >
> > any ideas why the old version dies and the new version has no problems?

I would write this as

sub somefunction {
     if (@_) {
         print "$_[0]\n";
     }
}

although unless the first argument might be false it's more readable to say

sub somefunction {
     if (my $arg = shift) {
         print "$arg\n";
     }
}

(Alters @_, of course.)
--
Peter Scott
Pacific Systems Design Technologies
http://www.perldebugged.com


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to