Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Mac > Perl on OSX > Re: Re: Leopard...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 5 Topic 1000 of 1075
Post > Topic >>

Re: Re: Leopard Perl version... @ 1192462023

by chas.owens@[EMAIL PROTECTED] (Chas. Owens) Oct 15, 2007 at 01:48 PM

On 10/15/07, Johan Meskens CS3 jmcs3
snip
> > I *wish* it was 5.10 as that has some
> > very nice features that I am excited about.
>
> like what for example ?
snip

Here are some of the things that are coming in Perl 5.10.

* a switch statement:

           given($string) {
               when (/^abc/) { $abc = 1; }
               when (/^def/) { $def = 1; }
               when (/^xyz/) { $xyz = 1; }
               default { $nothing = 1; }
           }

* The // and err operators (like || and or, but tests for defined
rather than truth)

my $sleep = ****ft // 10; #does not overwrite 0 like (****ft || 10) would

* alternations in regexes are significantly more efficient due to the
use of tries
* recursive regexes

           It is now possible to write recursive patterns without using
the
           "(??{})" construct. This new way is more efficient, and in many
           cases easier to read.

           Each capturing parenthesis can now be treated as an independent
           pattern that can be entered by using the "(?PARNO)" syntax
("PARNO"
           standing for "parenthesis number"). For example, the following
pat$B!>(B
           tern will match nested balanced angle brackets:

               /
                ^                      # start of line
                (                      # start capture buffer 1
                   <                   #   match an opening angle bracket
                   (?:                 #   match one of:
                       (?>             #     don't backtrack over the
inside of
this group
                           [^<>]+      #       one or more non angle
brackets
                       )               #     end non backtracking group
                   |                   #     ... or ...
                       (?1)            #     recurse to bracket 1 and try
it aga
in
                   )*                  #   0 or more times.
                   >                   #   match a closing angle bracket
                )                      # end capture buffer one
                $                      # end of line
               /x

* named regex captures

           It is now possible to name capturing parenthesis in a pattern
and
           refer to the captured contents by name. The naming syntax is
           "(?<NAME>....)".  It's possible to backreference to a named
buffer
           with the "\k<NAME>" syntax. In code, the new magical hashes
"%+"
           and "%-" can be used to access the contents of the capture
buffers.

* relative backreferences

           A new syntax "\g{N}" or "\gN" where "N" is a decimal integer
allows
           a safer form of back-reference notation as well as allowing
rela$B!>(B
           tive backreferences. This should make it easier to generate and
           embed patterns that contain backreferences. See "Capture
buffers"
           in perlre. (Yves Orton)

* "\K" escape
           The functionality of Jeff Pinyan's module Regexp::Keep has been
           added to the core. You can now use in regular expressions the
spe$B!>(B
           cial escape "\K" as a way to do something like floating length
pos$B!>(B
           itive lookbehind. It is also useful in substitutions like:

             s/(foo)bar/$1/g

           that can now be converted to

             s/foo\Kbar//g

           which is much more efficient. (Yves Orton)

* UNITCHECK blocks

       "UNITCHECK", a new special code block has been introduced, in
addition
       to "BEGIN", "CHECK", "INIT" and "END".

       "CHECK" and "INIT" blocks, while useful for some specialized
purposes,
       are always executed at the transition between the compilation and
the
       execution of the main program, and thus are useless whenever code
is
       loaded at runtime. On the other hand, "UNITCHECK" blocks are
executed
       just after the unit which defined them has been compiled. See
perlmod
       for more information. (Alex Gough)

* the smart match operator (~~)

       The behaviour of a smart match depends on what type of thing its
       arguments are. It is always commutative, i.e. "$a ~~ $b" behaves
the
       same as "$b ~~ $a". The behaviour is determined by the following
table:
       the first row that applies, in either order, determines the match
       behaviour.

           $a      $b        Type of Match Implied    Matching Code
           ======  =====     =====================    =============
           (overloading trumps everything)

           Code[+] Code[+]   referential equality     $a == $b
           Any     Code[+]   scalar sub truth         $b->($a)

           Hash    Hash      hash keys identical      [sort keys
%$a]~~[sort key
s %$b]
           Hash    Array     hash value slice truth   grep $_, @[EMAIL PROTECTED]
           Hash    Regex     hash key grep            grep /$b/, keys %$a
           Hash    Any       hash entry existence     exists $a->{$b}

           Array   Array     arrays are identical[*]
           Array   Regex     array grep               grep /$b/, @[EMAIL PROTECTED]
           Array   Num       array contains number    grep $_ == $b, @[EMAIL PROTECTED]
           Array   Any       array contains string    grep $_ eq $b, @[EMAIL PROTECTED]
           Any     undef     undefined                !defined $a
           Any     Regex     pattern match            $a =~ /$b/
           Code()  Code()    results are equal        $a->() eq $b->()
           Any     Code()    simple closure truth     $b->() # ignoring $a
           Num     numish[!] numeric equality         $a == $b
           Any     Str       string equality          $a eq $b
           Any     Num       numeric equality         $a == $b

           Any     Any       string equality          $a eq $b


        + - this must be a code reference whose prototype (if present) is
not ""
            (subs with a "" prototype are dealt with by the 'Code()' entry
lower
 down)
        * - that is, each element matches the element of same index in the
other
            array. If a circular reference is found, we fall back to
referential
            equality.
        ! - either a real number, or a string that looks like a number
* state variables (like static in C)
* the say function (like print, but with a newline)
 




 5 Posts in Topic:
Re: Re: Leopard Perl version... @ 1192462023
johanmeskenscs3@[EMAIL PR  2007-10-15 17:28:48 
Re: Re: Leopard Perl version... @ 1192462023
chas.owens@[EMAIL PROTECT  2007-10-15 13:48:09 
Re: Re: Leopard Perl version... @ 1192462023
david@[EMAIL PROTECTED]   2007-10-16 15:29:42 
Re: Re: Leopard Perl version... @ 1192462023
douglist@[EMAIL PROTECTED  2007-10-16 12:10:25 
Re: Leopard Perl version... @ 1192462023
david@[EMAIL PROTECTED]   2007-10-17 23:24:27 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sun Oct 12 22:21:32 CDT 2008.