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

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

Thread Previous | Thread Next
From:
Abigail
Date:
November 1, 2009 14:36
Subject:
Re: sixteen embracing uses (was: "If" your subscript goes bump inthe night)
Message ID:
20091101223559.GE24264@almanda
On Sun, Nov 01, 2009 at 11:56:09AM +0100, Abigail wrote:
> On Sat, Oct 31, 2009 at 10:37:59PM -0600, Tom Christiansen wrote:
> > 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
> 
> 
> 16. REGEXP CODE BLOCK:
>     /(?{ say "foo" })/
> 
> 
> 17. DELAYED REGULAR EXPRESSION
>     /(??{ "foo" })/
> 
> 
> Although it could be argued that they don't really count, as the '{'
> isn't a token in itself, just part of a token.


18. HERE-DOC TERMINATOR
    print <<'{'
    Hello, world
    {


Abigail

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