in reply to Re: Re: Broken regexp
in thread Broken regexp

Besides that, $_ is the default variable. I prefer to see people take advantage of that...

Please note that the advantage in these cases is only in the number of characters that you need to type. And perhaps in readability (which some people might consider a disadvantage in these cases). For execution, there is no difference in the opcode tree generated, and thus no difference in execution. For example:

$ perl -MO=Deparse -e 'length' length $_;
Personally, I prefer to use an explicit $_ if I think it improves the readability of my code.

Liz

Replies are listed 'Best First'.
Re: Re: Re: Re: Broken regexp
by Juerd (Abbot) on Mar 09, 2004 at 14:47 UTC

    Please note that the advantage in these cases is only in the number of characters that you need to type.

    Reducing typing has always been its purpose and that is what it does well. I hate that you have to use parens here and would in practice probably indeed use length $_ instead of length(). (I find the latter rather unreadable the more I think about it. It looks as if I'm trying to explicitly pass NO arguments.)

    I prefer to leave out $_ when it can be implied, because that is what I think improves readability. I even like to abuse for for topicalization.

    Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }

Re: Re: Re: Re: Broken regexp
by ysth (Canon) on Mar 09, 2004 at 16:20 UTC
    This is true of most ops (e.g. "length($_)" compiles exactly the same as "length()").

    The exceptions are m//, s///, and tr///, where leaving out the implicit "$_ =~" will produce a leaner opcode tree that will be only slightly faster.