Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
any idea why this might fail with a known match

open (WHITELIST, "<", "/home/ruben/mail/whitelist") or die;
my @oknames = <WHITELIST>;

        if( /(From: *"?[ \w-.].*"?)\b<?([\w].+\@[-a-z.A-Z=]+\.(\w.+))(?!<)/ ){
#               print  STDERR "HEY a WINNER\nONE $1 \n Two $2 \n Three $3";
                if ($2 =~ /ruben\@mrbrklyn\.com/){
                my @ret;
                if( @ret = grep( /.*$2.*/ , @oknames) ){
                        print STDERR "\n$2 WHITELISTED @ret\n";

The test program works:

  1 #!/usr/bin/perl -w
  3 my $mail = "ruben2\@mrbrklyn\.com";
  5 open (WHITELIST, "<", "/home/ruben/mail/whitelist") or die;
  6 my @oknames = <WHITELIST>;
  7 my @ret;
  8 if(@ret = grep( /.*$mail.*/ , @oknames)){
  9    print STDERR "\n$mail WHITELISTED @ret\n";
 10 }
 12 print "@ret";

Re: grep

Quoted text here. Click to load it


  (1) See difference (with your so-called-test-program-works)?

    % perl -wle '
    "abcdef" =~ m/(ab).*(ef)/ or die "foo";
    print $2;
    "abcdef" =~ m/ab.*ef/ or die "bar";
    print $2
    Use of uninitialized value $2 in print at -e line 5.

  (2) use-strict-use-warnings!  Even in production.  That's why your
      so-called-test-program-works works and your
      so-called-intest-program-works doesn't work.

  (3) I see that your gigantic regexp in all captures accepts
      metachaarcters.  Guess what will happen here?

    % perl -wle '
    "abc+++" =~ m/(\w)\w+(\W)\W+/ or die "foo";
    "abc+++" =~ m/(\w$2)/ or die "bar";
    print $1

  (4) Seriously, dude, seriously.  Email::Address->can( 'parse' )


Torvalds' goal for Linux is very simple: World Domination
Stallman's goal for GNU is even simpler: Freedom

Re: grep

On 02/22/2015 06:55 AM, Eric Pozharski wrote:
Quoted text here. Click to load it

why do you lose $2's value?

Re: grep

On Thursday, February 26, 2015 at 6:12:05 AM UTC-8, ruben safir wrote:
Quoted text here. Click to load it

From perldoc perlre:

 Capture group contents are dynamically scoped and available to you
       outside the pattern until the end of the enclosing block or until the
       next successful match, whichever comes first.  (See "Compound
       Statements" in perlsyn.)  

Charles DeRykus  

Site Timeline