Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^2: subroutine bewilderment: how to mimic builtins

by ysth (Canon)
on Feb 08, 2006 at 02:43 UTC ( [id://528697]=note: print w/replies, xml ) Need Help??


in reply to Re: subroutine bewilderment: how to mimic builtins
in thread subroutine bewilderment: how to mimic builtins

Note that ;$ doesn't parse the same as a builtin like uc:
$ perl -we'print uc 1, 2' 12 $ perl -we'sub myuc(;$) { $_[0]||$_ } print myuc 1, 2' Too many arguments for main::myuc at -e line 1, at EOF
Also, in the presence of my $_, myuc won't be able to see the right $_. Implementing a _ prototype is on the todo list, but not on any particular person's plate that I know of.

Replies are listed 'Best First'.
Re^3: subroutine bewilderment: how to mimic builtins
by ikegami (Patriarch) on Feb 08, 2006 at 03:55 UTC

    I know, but it's as close as possible. Considering the case that is different is an illegal case, I didn't bother confusing the issue by mentioning it.

    my $_; doesn't compile for me with Perl v5.8.6. Did you mean tie $_? There's some kind of problem with local $_ when $_ is tied, but 1) that's not likely, and 2) it can be avoided by localizing *_ instead of $_ (as I did in one of my examples).

      my $_; is intended as a replacement for the not-ideal local $_; or local *_;.

      perl591delta:

      =head2 Lexical $_

      The default variable $_ can now be lexicalized, by declaring it like any other lexical variable, with a simple

      my $_;
      The operations that default on $_ will use the lexically-scoped version of $_ when it exists, instead of the global $_.

      In a map or a grep block, if $_ was previously my'ed, then the $_ inside the block is lexical as well (and scoped to the block).

      In a scope where $_ has been lexicalized, you can still have access to the global version of $_ by using $::_, or, more simply, by overriding the lexical declaration with our $_.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://528697]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-04-16 10:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found