If I understand what you want, you just want to evaluate the fractions in each line as decimals, ignoring the "-x", "+Y" etc. Well, this does what you want:
while (<DATA>) { @fractions = m!(\d+/\d+)!g; print eval($_), " " foreach @fractions; print "\n"; } __DATA__ SYMM 1/8 - X, 1/8 + Y, 1/8 + Z SYMM 1/6 - X, 1/6 + Y, 1/6 + Z SYMM 1/4 - X, 1/4 + Y, 1/4 + Z SYMM 1/2 - X, 1/2 + Y, 1/2 + Z
This code takes advantage of the fact that the "match" operator (m//) provides an array of every match when used with the /g modifier. Doing it this way lets us dispense with all those messy splits. The "eval" command tells Perl to actually "do the math" with the resulting fractions, printing (for example) "0.5" rather than just the string "1/2".

Your next question might be on how round the resulting fractions accordingly. For that, I point you to perfunc and the sprintf function.

Enjoy!

Gary Blackburn
Trained Killer


In reply to Re: Help with loops by Trimbach
in thread Help with loops by harry34

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.