in reply to Problem with $1

Read the docs for Net::POP3. get returns a reference to an array of lines, not the whole message.

get ( MSGNUM [, FH ] ) Get the message MSGNUM from the remote mailbox. If FH is not given + then get returns a reference to an array which contains the lines of + text read from the server. If FH is given then the lines returned fr +om the server are printed to the filehandle FH.

You just need to search through those lines for the subject.

my $msg = $pop->get($msgnum); for my $line ( @$msg ) { if( $line =~ /^Subject:(.*)/ ) { print "Subject is $1"; last; } }

Or, similarly, use print grep { /^Subject:/ } @$msg;

Update: I should add that when I first read the subject "Problem with $1", my first thought was, "It's not $1,000,000?"

Update: grep doesn't terminate after the first match. List::Util and first is better.

-xdg

Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Replies are listed 'Best First'.
Re^2: Problem with $1
by w3b (Beadle) on Dec 03, 2005 at 14:48 UTC
    Ok!now it's good... thank you very very much... now i can think about add next functions;) Thank you one more time!

      Hi,

      I would also use my ($subject) = $line =~ ...
      It's cleaner than making the person examine the regex...

      Regards,

      fmerges at irc.freenode.net