On Thu, Feb 14, 2002 at 05:45:44PM -0800, Marc Morrison wrote:
> I tried the nongreedy modifier grep/@?/ but this
> didn't work.

? is a quantifier here, not a non-greedy modifier.  The non-greedy modifier
only works on quantifiers.

To break it down a bit, + * and ? are called quantifiers, because they say
how many of the preceding pattern can match.  They are greedy by default, so
you turn that off by appending a ?, e.g. +? *? and ??.  A simple character
in a regex can only match one time, so the greediness of it doesn't enter
into it.

/@?/ matches zero or one '@', which is probably not what you wanted.

If any of the above made any sense, great.  Anyways, back to your problem.


Given that you read the file into the array @lines:

    my @emails;
    foreach (@lines) {
        while (/(\S+@\S+)/g) {
            push(@emails, $1);
        }
    }

@emails will consist of all of the email-looking strings, defined here as
any non-whitespace characters around an '@'.  This definition is not
perfect; for example, it matches "[EMAIL PROTECTED]" in "Hi, my email
address is [EMAIL PROTECTED]".  It's also a pretty simplistic definition
of an email address, but will probably get you most of them.


You could also use something like this, which would save on memory:

    my @emails;
    while (<FILE>) {
        while (/(\S+@\S+)/g) {
            push(@emails, $1);
        }
    }

Where FILE is an open filehandle to your original file

That should give you a starting point that you can expand on.  Good luck.


Michael
--
Administrator                      www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to