http://www.perlmonks.org?node_id=965352


in reply to Re: Perlplexation - foreach shoulda Known
in thread Perlplexation - foreach shoulda Known

I've had Effective Perl Programming for a year now, and really enjoyed it, but for some reason missed the detail until just this last week... I was "whoah!" and decided to try out a bunch of examples. :)

So are "aliases" used in other Perl commands besides these sorts of loops? Is that what $a and $b are considered to be in the sort command?

  • Comment on Re^2: Perlplexation - foreach shoulda Known

Replies are listed 'Best First'.
Re^3: Perlplexation - foreach shoulda Known
by eyepopslikeamosquito (Archbishop) on Apr 16, 2012 at 21:09 UTC

    So are "aliases" used in other Perl commands besides these sorts of loops? Is that what $a and $b are considered to be in the sort command?
    Yes and yes. Some places aliases are used:
    • $_ in foreach, map and grep
    • $a and $b in a sort block
    • $a and $b in List::Util's reduce function and List::MoreUtils's pairwise function
    • Each element of @_ for the actual arguments in a subroutine call
    • By packages importing symbols
    • By an our declaration, which creates a lexically scoped alias
    • You can explicitly create an alias via typeglobs

    See also "alias" in perlglossary and Item 118 "Access the symbol table with typeglobs" in Effective Perl Programming.