Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^2: Bug with "last successfully matched regular expression" (empty regex)

by LanX (Canon)
on Feb 22, 2012 at 15:04 UTC ( #955543=note: print w/ replies, xml ) Need Help??


in reply to Re: Bug with "last successfully matched regular expression" (empty regex)
in thread Bug with "last successfully matched regular expression" (empty regex)

Good catch, but the whole implementation is annoyingly inconsistent.

I thought I could make this more obvious by implementing functions like nodege(), noflip(), and noflop() to write something like

grep { noedge(/DBIC/ .. /DANCER/)  }@list;

but try guessing which magic behavior hinders that:

DB<52> @list= ("a".."c","DBIC","A".."C","DANCER","a".."c"); DB<53> sub ff { print $_[0]} DB<54> grep { ff(/DBIC/ .. /DANCER/) } @list; 0000000000 DB<55> grep { my $x=(/DBIC/ .. /DANCER/); ff($x) } @list; 12345E0

Of course I could also use something like compiled regexes for EDGE, FLIP, FLOP to be able to type something like:

grep { (/DBIC/ .. /DANCER/) !~ EDGE  } @list;

but that doesn't seem to be trivial, too :-(

Thanks anyway!

Cheers Rolf


Comment on Re^2: Bug with "last successfully matched regular expression" (empty regex)
Select or Download Code
Re^3: Bug with "last successfully matched regular expression" (empty regex)
by LanX (Canon) on Feb 24, 2012 at 15:32 UTC
    ARGH!!!!!!!!!

    DB<52> @list= ("a".."c","DBIC","A".."C","DANCER","a".."c"); DB<53> sub ff { print $_[0]} DB<54> grep { ff(/DBIC/ .. /DANCER/) } @list; 0000000000 DB<55> grep { my $x=(/DBIC/ .. /DANCER/); ff($x) } @list; 12345E0

    ff() evaluates the range operator in list context!

    applying prototypes solves this "problem":

    DB<182> @list= ("a".."c","DBIC","A".."C","DANCER","a".."c"); DB<183> sub ff ($) { print $_[0]} DB<184> grep { ff(/DBIC/ .. /DANCER/) } @list; 12345E0

    Cheers Rolf ( ...banging his head against the table...)

      You can also use scalar to force scalar context:
      grep { ff(scalar(/DBIC/ .. /DANCER/)) } @list;

      Sorry, I thought your "guess which magic" was "an exercise for the reader" and that you already knew the answer or else I would've told you that when you posted.

      - tye        

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://955543]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2014-08-01 03:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (256 votes), past polls