in reply to quoted-printable, and ugly code


Slightly modified/simplified it gives :
if ( /From:/ ) { s/^\w+\:(.*)$/$1/gs; push my @addr, Mail::Address->parse($_); $address = $addr[0]->address(); $debug_text .= "Found address at line $.: $string\n"; }

I only use the fact that m// (ie //) and s// use $_ as default argument...
(So using $line is useless)

But what is $string ?

MIME::QuotedPrint is probably (one of) the answer(s) to your second question...

Replies are listed 'Best First'.
Re: Re: quoted-printable, and ugly code
by deprecated (Priest) on Feb 22, 2001 at 18:54 UTC
    Might this work as well and be further simplified?
    if (/From:/) { m/^\w+:(\S+)$/ && push my @addr, Mail::Address->parse($1); $address = $addr[0]->address; $debug_text .= "Found $address at line $.\n"; }
    two notes. first, I dont see mention of $string anywhere so I am assuming you meant $address. second, im not sure why you needed to modify $_, when you could just stuff the match into $1, etc. third, semantically I didnt see any reason to say "Found address" when its clear that's what this codelet is doing. :) ymmv of course. also, from perldoc perlop:
    s/PATTERN/REPLACEMENT/egimosx s Treat string as single line. g Replace globally, i.e., all occurrences.
    not quite sure why youre using either switch since youre matching a "From: foo@bar.com" not a "From: foo@bar.com baz bletch blah blah From: bar@brak.org".

    sorry, this wasnt meant to be a round of perl golf, but there were a few simplifications i caught. :)

    brother dep.

    minor update:

    would it be possible to just do this?

    if (/^From:(\S+)$/) { push my @addr, Mail::Address->parse($1); $address = $addr[0]->address; $debug_text .= "Found $address at line $.\n"; } else { next }

    --
    transcending "coolness" is what makes us cool.

      I would shrink:
      push my @addr, Mail::Address->parse($1); $address = $addr[0]->address; # to $address = (Mail::Address->parse($1))[0]->address;
      But that's because I kinda abhor such ephemeral temporary variables. At the very least, that push() is useless.

      japhy -- Perl and Regex Hacker