----- Original Message -----
From: Brent Buckalew <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Sunday, June 03, 2001 9:28 AM
Subject: probably a simple matter but...


> Hello all,
>
> I've constructed a perl script which takes number from a large text file
> and prints them as well as manipulates them later on.  I've use a crude
> way of getting the data but it's working for one set of files but not the
> other.  What happens is that it reads in the numbers until there is a
> negative number.  When it reaches a negative number, it places the
> remaining text in that variable.
>
> Here's a sample of the text file and the program where that data should be
> read.
>
> #sample of the text
> Nitrogen 0.0  -5.78  0.0  0.0  0.0
>
> #sample of the program.
> while(<COMP2FILE>){
>
> if (/(Nitrogen) *([0-9.\-]*) *([0-9.\-]*) *([0-9.\-]*) *([0-9.\-]*)
> *([0-9.\-]*)
> /) {
> if ($2 <= 0.0) {
> $name = $1; $nitrogen1 = $2; $nitrogen2 =$3; $nitrogen3 = $4; $nitrogen4 =
> $5;
> $nitrogen5 = $6;}}
> }
>
>
> I thoguht placing the \- would get rid of the problem but it didn't.
> So, the end result is that $nitrogen1 = 0.0 and $nitrogen2 = -5.78  0.0
> 0.0  0.0.  the other variables after that are undefined.

The * is greedy.
which means that:

(Nitrogen) will match "Nitrogen"
\s* will match any number of spaces
([0-9.\-]*) will match the largest sequence of any character since there is
a dot in the expression.....






Reply via email to