Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
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
Replies are listed 'Best First'.
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...)

      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        

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

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 making s'mores by the fire in the courtyard of the Monastery: (12)
As of 2015-07-28 23:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (260 votes), past polls