in reply to Simple iteration problem
#!/usr/bin/perl
The next two lines should be:
use warnings; use strict;
open TAB, "test.txt";
You should always verify that the file opened correctly:
open TAB, '<', 'test.txt' or die "Cannot open 'test.txt' $!";
$diff = "$tab[0]" - "$seed";
You are converting the contents of the variables to strings and then subtracting which converts them back to numbers. Just use the variables directly:
$diff = $tab[0] - $seed;
if ($diff ge 0.1)
You are using a text comparison operator on numeric data when you should be using a numerical comparison operator:
if ($diff >= 0.1)
{print "@tab\n" && $seed eq $tab[0]}
The logical AND operator && has relatively low precedence so it is evaluated first and the result of "@tab\n" && $seed eq $tab[0] is passed to the print operator.
{print "@tab\n"; $seed eq $tab[0]}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Simple iteration problem
by toolic (Bishop) on Nov 29, 2007 at 14:53 UTC | |
by Eimi Metamorphoumai (Deacon) on Nov 29, 2007 at 17:08 UTC | |
by Etbr77 (Initiate) on Nov 29, 2007 at 16:53 UTC | |
|
Re^2: Simple iteration problem
by Anonymous Monk on Nov 29, 2007 at 14:49 UTC | |
by roboticus (Chancellor) on Nov 29, 2007 at 16:51 UTC | |
by toolic (Bishop) on Nov 29, 2007 at 14:59 UTC |