#!/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]}
In reply to Re: Simple iteration problem
by Anonymous Monk
in thread Simple iteration problem
by Etbr77
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |