in reply to Re: quoted-printable, and ugly code
in thread quoted-printable, and ugly code

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.

Replies are listed 'Best First'.
Re: Re: Re: quoted-printable, and ugly code
by japhy (Canon) on Feb 22, 2001 at 20:07 UTC
    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