Hey david,

this regexp will do the trick for you:
$_ = '    [EMAIL PROTECTED] (mike smith)    ';
s/^\s+|\s+$//g;

you dont need the parenthesis around it, unless you want to capture the
whitespace (which seems futile)
i'd say compiling a regexp twice would be more of a drain on system
resources then an | actually, but if you'd like you can use the benchmark
module to time it.

<snip>
> $data = "    [EMAIL PROTECTED] (mike smith)    "
>
> $data =~ s/(^\s+)|(\s+$)//g;
>
> or would it be more efficient to it thus:
>
> # two passes
> $data =~ s/^\s+)//;
> $data =~ s/\s+$)//;
</snip>

if you're concerned with system performance, then you do NOT want to put an
entire file into memory (especially using an array). it's concidered bad
practice and there've beeen quite a few posts on this list about it.

so here's what you should do in this case, seeing you're testing each
element one by one anyway:

while (<EL>) {
    next if /test/;
    s/^\s+|\s+$//g;
    other_stuff;
}

escaping the @ is not needed, perl will Do The Right Thing for you =)


 <snip>
> Final comment when I am reading from a loop:
>
>
> open(EL,"$emailLog") ||  &errorLog( "Read in, Could not find $emailLog,
$!");
> my @lines = <EL>;
>
>  foreach(@lines){
>     next if /test/;
>     $_ =~ s/^\s+(.*)\s+$/\1,/;
>
> .... other code....
>
> Do I need to escape the '@' as my data will be of format:
> [EMAIL PROTECTED] (name)
</snip>

hth,

Jos Boumans

Reply via email to