Hi, I'm working with a line of numbers from a file in the form:
( 0, 670); 3.2; 7.8; 9.4; 10.2; 12.6;
I know that I can use these lines:
$line = <FILE>; @split1 = split(/;/, $line);
which will result in the array @split1 containing:
@split1[0] = ( 0, 670) @split1[1] = 3.2 @split1[2] = 7.8 etc.
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:
$line = <FILE>; @split1 = split(/;/, $record); @split2 = split(/,/, @split1[0]); @split3 = split(/\(/, @split2[0]); @split4 = split(/\)/, @split2[1]); $test1 = @split3[1]; $test2 = @split4[0];
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.

In reply to splitting lines a number of times by perl-rob

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.