in reply to Re: Removing data from a string with Regex
in thread Removing data from a string with Regex

Taking this approach one step further, the original loop could be simplified to:

while (<FILE>) { my ($name) = /^--from\s*([^@]+)/; print ($name) if defined $name; }

pike

Replies are listed 'Best First'.
Re: Re: Re: Removing data from a string with Regex
by CharlesClarkson (Curate) on Nov 15, 2001 at 23:01 UTC

    That regex would allow --from @something.com to pass and assign ' ' to $name. It would likely be better to use:/^--from\s*([^@\s]+)/ which fails for --from @something.com and could simplify the code further.

    while ( <FILE> ) { print $1 if /^--from\s*([^@\s]+)/; } or: print $1 if /^--from\s*([^@\s]+)/ while <FILE>;



    HTH,
    Charles K. Clarkson