develooper Front page | perl.perl5.porters | Postings from November 2009

Re: sixteen embracing uses (was: "If" your subscript goes bump in the night)

Thread Previous | Thread Next
From:
demerphq
Date:
November 1, 2009 04:07
Subject:
Re: sixteen embracing uses (was: "If" your subscript goes bump in the night)
Message ID:
9b18b3110911010407i1079ac16ldc1915b794a59b9a@mail.gmail.com
2009/11/1 Tom Christiansen <tchrist@perl.com>:
> In-Reply-To: Message from Aristotle Pagaltzis <pagaltzis@gmx.de>
>   of "Sun, 01 Nov 2009 04:11:30 BST." <20091101031130.GA5708@klangraum.plasmasturm.org>
>
>>* George Greer <perl@greerga.m-l.org> [2009-10-31 22:50]:
>>> After all the pains, it looks less painful if hashes
>>> subscripted with a different character
>
>> Not just hashes. Curlies in Perl source can have something like
>> 7 different meanings (if memory serves) depending on context.
>
> Just seven, you say?  'Pends how you count 'em, but I'm
> afraid seven's just a wee bit on the conservative side...
>
>  0. NOTHING:
>    $i++;  #  } don't look at {this} here {
>    / foo (?# silly }{ brackets ) bar /x
>
>  1. LITERAL:
>    print "This {STU}{FF} means what it means!\n";
>    m/foo\{nuff}/;
>    #line 1066 "waysilly{file}name"
>    =pod
>    this is an em{pod}ded literal
>    =cut
>    __END__
>    prithee what is this { matter } here?
>
>  2. HEADED BLOCK:
>    if/do/eval/sub/etc { ... }
>
>  3. PROPER LOOP:
>    while/foreach/etc { }
>    {  }   # bare block for last/redo or scoping
>
>  4. HASH SUBSCRIPT:
>    $h{string}
>    $hr->{string}
>
>  5. ANON HASH ALLOCATOR:
>    $new  = { LIST  };
>
>  6. DEREF ISOLATION:
>    @{ fn(x) }[0,0,1,-1]
>
>  7. VARIABLE ISOLATION:
>    print "Let's go to ${name}'s place.\n";
>    ${^PREMATCH}
>
>  8. NAME OF A DISTINCT main'VARIABLE:
>    $} = "whacked";
>
>  9. PYOQ DELIMS:
>    qq{....}
>    m{foo|bar}x
>    q{.{ ... } ...}  # 9 + 1
>    ($rot13ed = $it) =~ y{a-zA-Z}{n-za-mN-ZA-M}
>
> 10. REGEX QUANTIFICATION: {m,n} {m.n}? {m.n}+
>    m/ ( (?:foo|bar){4,9}? ) /x
>
> 11. REGEX NAME-GROUPED STUFF:
>    m/ \x{DEADBEEF} /x
>    m/ \p{Digit} /x
>    m/ \g{-1} /x
>    m/ \g{NAMEDREF} /x
>
> 12. FORMAT VALUE-LIST GROUPING:
>    format =
>    This @<<<<< is aligned to @>>>>
>    {
>        some_really_long_expression_that_returns_a_scalar,
>                              and_another_aligned_thingie
>    }
>    .
>
> 13. ARBITRARY STRING GENERATION:
>    print for <{big,little}-{men,women,children}>;  # 6 strings
>
> 14. EXISTENT FILENAME EXPANSION:  (paths must -e)
>    print for </{,usr{,/local}}/{{s,}bin}/*perl*>;
>
> 15. INDIRECT FILEHANDLE vs INDIRECT FILEGLOB:
>    $ perl -e  '$in = "STDIN"; print scalar <$in>' < /etc/motd
>    OpenBSD 4.4 (GENERIC) #0: Tue Oct 21 10:02:18 MDT 2008
>    $ perl -le '$in = "/etc/*"; print scalar <${in}>' < /etc/motd
>    /etc/adduser.conf

IMO, \x{...} deserves its own category as it applies in more places
than just strings.

Yves

-- 
perl -Mre=debug -e "/just|another|perl|hacker/"

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About