Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

While I understand that perl6 will have this feature, I belive there will be less need for it because of the other changes in the language.

The times I feel the need of lexical aliases (in perl5) most are nested datastructures and lexical subs.

For example, when I have a ref-to-hash $h, I can only access elements like $$h{"foo"} (or the arrow notation), which is ugly. It would be much simpler to alias it to %h and then I could just access the elements as $h{"foo"}. Of course, you can make a copy like my %h = %$h;, but that can be slow, and you have to copy it back with %$h = %h; if you modifiy %h. In perl6, however, $$h{"foo"} will become $h{"foo"}, which is a simple enough notation so the problem will be gone. (As a sidenote, there are nonstandard modules for perl5 that allow lexical aliasing.)

Lexical subs are very similar. Today, the way to create lexical subs is my $frobnicate = sub { ... }; and we call them by &$frobnicate(@args) (or the arrow notation), which is, again, ugly. In perl6, this shall simplify to $frobnicate(@args).

Of course, perl6 will have lexical aliases like my %h := %$h and true lexical &-variables in addition to $, @, % so you can use aliasing to solve either of these too. TIMTOWTDI.

Update: lexical aliases wouldn't solve my second problem. We'd need lexical subs for that.


In reply to Re^2: Aliasing bites by ambrus
in thread Aliasing bites by ambrus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (2)
As of 2024-04-24 13:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found