APM: Austin Perl Mongers Wed. Dec. 9 7-9pm

Thomas L. Shinnick tshinnic at io.com
Mon Dec 7 11:41:31 PST 2009


At 07:47 AM 12/2/2009, jameschoate at austin.rr.com wrote:
>Good Morning,
>
>The December APM meeting will once again occur at Mangia Pizza on 
>Gracy Farms at Burnet and MoPac from 7-9pm.
>
>http://www.pm.org/
>
>(I wonder why they don't have any PUGs in Africa?)
>
>http://www.mangiapizza.com/33/Gracy_Farms.html
>
>Reminder - I won't be making the announcements or managing the 
>meetings at least through the first few months of 2010 as I have 
>other priorities.

I won't be able to make the meeting (as I'm literally 1000 miles 
away), but I wanted to share something I'd put together for last 
time.  It came out of a discussion on Perl5-Porters maillist, with 
contributions by several people, as everyone tried to remember all 
the ways that braces {} can be used.

What I'd love to see is a comparison where other languages explain 
how they satisfy the function of each of these uses for braces.  I'm 
sure they all can do these, but if it takes up a whole line with just 
a class.subclass.object.method.method call to do the same thing, it 
kinda makes succinctness - even at the peril of punctuation - more compelling.

Pasted below and attached:


http://www.nntp.perl.org/group/perl.perl5.porters/2009/10/msg152943.html


From: Tom Christiansen
Date: October 31, 2009 21:38
Subject: sixteen embracing uses (was: "If" your subscript goes bump 
in the night)

 >* George Greer <perl at 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

So hey, anybody forget any of those? :)

/ducks

--tom



     4b. GLOB ELEMENT
         *foo{IO}


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
     {


19. ($s = q{general purpose peared delimiter}) =~ s(pear){pair};

     19b.
     ($s = q}general purpose peared delimiter, but singled out}) =~ 
s}pear}pair};

-------------- next part --------------

http://www.nntp.perl.org/group/perl.perl5.porters/2009/10/msg152943.html


From: Tom Christiansen
Date: October 31, 2009 21:38
Subject: sixteen embracing uses (was: "If" your subscript goes bump in the night)

>* George Greer <perl at 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

So hey, anybody forget any of those? :)

/ducks

--tom



    4b. GLOB ELEMENT
        *foo{IO}


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
    {


19. ($s = q{general purpose peared delimiter}) =~ s(pear){pair};

    19b. 
    ($s = q}general purpose peared delimiter, but singled out}) =~ s}pear}pair};



More information about the Austin mailing list