biscarri has asked for the wisdom of the Perl Monks concerning the following question:
Hi, I'm trying to read numbers from a file with the following format: 25 ((18 25 4) (3 12 1)) I use the following code:
open (INFILE,$post) or die "**| Couldn't open file general: $post"; while (<INFILE>) { @words = split; } close (INFILE); $L=($words[2]+$words[5]); $D=($words[1]+$words[4]); $M=($words[3]+$words[6]);
$L and $M get the right value (L=37, M=5) but $D=0 instead of the expected value of 21. I guess this is due the presence of parentheses. How can I read the correct values? How to specify that parentheses should not be read? Thank you very much, Lluis
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Trying to read numbers from a text file
by toolic (Bishop) on Feb 28, 2016 at 19:04 UTC | |
|
Re: Trying to read numbers from a text file
by hippo (Archbishop) on Feb 28, 2016 at 19:09 UTC | |
|
Re: Trying to read numbers from a text file
by AnomalousMonk (Archbishop) on Feb 28, 2016 at 19:21 UTC | |
|
Re: Trying to read numbers from a text file
by Laurent_R (Canon) on Feb 28, 2016 at 21:14 UTC | |
|
Re: Trying to read numbers from a text file
by GrandFather (Saint) on Feb 29, 2016 at 00:37 UTC | |
|
Re: Trying to read numbers from a text file
by johngg (Canon) on Feb 28, 2016 at 23:48 UTC | |
|
Re: Trying to read numbers from a text file
by jdporter (Paladin) on Feb 29, 2016 at 03:24 UTC | |
|
Re: Trying to read numbers from a text file
by jcb (Parson) on Feb 29, 2016 at 05:06 UTC | |
|
Re: Trying to read numbers from a text file
by biscarri (Initiate) on Mar 01, 2016 at 17:17 UTC |