--- Alan Ivey <ai4891@yahoo.com> wrote:
>
> $Author="";
> while($Author eq "") {
> $line = <INPUT>;
> if($line=~m/[A-Z,a-z]/) {
> $Author=$line;
> chomp $Author;
> last;
> }
> }
>
Hope you don't mind a bit of feedback on the Perl code...
The above will either cause an error or an infinite loop if the Author
is not found in the input.
I suggest rewriting it to:
$Author="";
while( $line = <INPUT> ) {
if( $line =~ m/[A-Z,a-z]/ ) {
$Author=$line;
chomp $Author;
last;
}
}
Also, are you sure that the regexp is right? You are saying that $line
is a match if it "contains any (english) letter or a comma". So if the
line is just "A" it is a match. If the line is just "," it is a match.
Might you mean: m/[A-Za-z]+,[A-Za-z]+/ ??
( or even m/[:alpha:]+,[:alpha:]+/ )
Same while-loop and regexp questions for the $Title.
Also, the last while loop (@tempBody) could be replaced with either a
foreach:
@tempBody=<INPUT>;
$Body = "";
foreach $i (@tempBody) {
$Body .= $i;
}
or better yet remove the loop and use a join:
@tempBody=<INPUT>;
$Body = join("", @tempBody);
or even better, don't use the @tempBody array at all:
$Body = "";
while(<INPUT>) {
$Body .= $_;
}
Hope this helps,
greg_fenton.
=====
Greg Fenton
greg_fenton@yahoo.com
__________________________________
Do you Yahoo!?
New and Improved Yahoo! Mail - 100MB free storage!
http://promotions.yahoo.com/new_mail
Received on Tue Aug 10 08:12:09 2004