in reply to Bug with "last successfully matched regular expression" (empty regex)
The value of the flip-flop regex returns a line number like: 1,2,3,4E0 and that number can be tested in another regex.#!/usr/bin/perl -w use strict; use Data::Dumper; my @list= ("a".."c","DBIC","A".."C","DANCER","a".."c"); my @result; for (@list) { push @result,$_ if /DBIC/.. /DANCER/ and ! // } print Dumper \@result; # uses http://www.perlmonks.org/?node_id=525392 my @result2 = grep { (/DBIC/.. /DANCER/) =~ /^\d+(?<!^1)$/ }@list; print Dumper \@result2; __END__ $VAR1 = [ 'A', 'B', 'C' ]; $VAR1 = [ 'A', 'B', 'C' ];
As another note this "xE0" notation is used in other places in Perl. For example, the DBI can return 0E0 as the number of results which is 0 * 10**0 or numeric zero (0 * 1) although this evaluates to "true" when tested in a logical sense, meaning that that the statement "worked" but returned no results (numeric value is zero). Here the line number ending in E0 is the "last one". This is clever but it works.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Bug with "last successfully matched regular expression" (empty regex)
by LanX (Saint) on Feb 22, 2012 at 15:04 UTC | |
by LanX (Saint) on Feb 24, 2012 at 15:32 UTC | |
by tye (Sage) on Feb 24, 2012 at 20:49 UTC | |
by choroba (Cardinal) on Feb 24, 2012 at 15:40 UTC | |
by LanX (Saint) on Feb 24, 2012 at 15:48 UTC | |
|
Re^2: Bug with "last successfully matched regular expression" (empty regex)
by ikegami (Patriarch) on Feb 22, 2012 at 17:06 UTC |