perl-rob has asked for the wisdom of the Perl Monks concerning the following question:
I know that I can use these lines:( 0, 670); 3.2; 7.8; 9.4; 10.2; 12.6;
which will result in the array @split1 containing:$line = <FILE>; @split1 = split(/;/, $line);
the 1st and 2nd elements are already fine, but I need to get the numbers out of the 0th element. If I then combine the following:@split1[0] = ( 0, 670) @split1[1] = 3.2 @split1[2] = 7.8 etc.
then $test1 and $test2 then contain the numbers I want. Two questions, is there a more elegant way to do this, I'm sure there must be. Second question, can I then use $test1 and $test2 just like numbers, i.e. perform operations on them like +, -, * and /? Thanks in advance for any help.$line = <FILE>; @split1 = split(/;/, $record); @split2 = split(/,/, @split1[0]); @split3 = split(/\(/, @split2[0]); @split4 = split(/\)/, @split2[1]); $test1 = @split3[1]; $test2 = @split4[0];
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: splitting lines a number of times
by kennethk (Abbot) on Apr 01, 2009 at 15:51 UTC | |
Re: splitting lines a number of times
by ELISHEVA (Prior) on Apr 01, 2009 at 16:03 UTC | |
Re: splitting lines a number of times
by jethro (Monsignor) on Apr 01, 2009 at 16:03 UTC | |
Re: splitting lines a number of times
by Nkuvu (Priest) on Apr 01, 2009 at 16:06 UTC | |
Re: splitting lines a number of times
by jwkrahn (Abbot) on Apr 01, 2009 at 16:37 UTC | |
Re: splitting lines a number of times
by repellent (Priest) on Apr 01, 2009 at 17:02 UTC | |
Re: splitting lines a number of times
by linuxer (Curate) on Apr 01, 2009 at 17:46 UTC | |
by Anonymous Monk on Apr 06, 2009 at 09:16 UTC | |
Re: splitting lines a number of times
by Bloodnok (Vicar) on Apr 01, 2009 at 16:46 UTC |