fritsimeel has asked for the wisdom of the Perl Monks concerning the following question:

Dear monks, I am a noob in Perl. I am also not a programmer.... From a file i have to extract 2 emailaddresses. I know they end with @dh.nl. So i wrote this little (ugly) script.
#finding @dh.nl #!/usr/bin/perl -w my $file="logs1"; chomp $file; open (FILE, $file) || die "Can't open logs file: $!\n"; my @line =(<FILE>); chomp (@line); foreach (@line){ if (/(\D+)(@)(dh.nl)/) { $a=$1; $b=$2; $c=$3; } } print "$a"."$b"."$c"."\n"; close FILE;
The result is: JT; qwerty@dh.nl,abcde@dh.nl I just need: qwerty@dh.nl,abcde@dh.nl The (part of) file is:
193.10.168.23 - - [07/Jan/2013:00:07:48 +0000] "GET /UserFiles/File/Ra +dio%203rd%20Newsletter%20for%20web.pdf HTTP/1.0" 304 - "-" "gsa-crawl +er (Enterprise; M2-N7RQ5RABCA2JT; qwerty@dh.nl,abcde@dh.nl)"
What am I doing wrong? Please advice me. Thanks in advance. fritsimeel.

Replies are listed 'Best First'.
Re: using regular expressions showing just the hits.
by choroba (Cardinal) on Apr 05, 2013 at 14:52 UTC
    \D+ stands for "non-digit repeated". You want "alphanumeric repeated", so try
    while ( /([[:alnum:]]+)(\@dh\.nl)/g ) { my ($name, $domain) = ($1, $2); print "$name$domain\n"; }
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
      Hello Choroba, thanks for the quick reaction.

      When i run your code i get this message: Use of uninitialized value $_ in pattern match (m//) at dh.pl in line 8

      Sorry, i'm overlooking something....
        The code shown should replace the if part in the original code.
        لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ