i am very very new to perl and need some help !. I have the following lines in a file:
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
..and I am using the following script below to initially undef SYMM and store the lines in the 4 variables $symmetry. Then by numerous splits (excuse the temporary and crude names of the variables!) I isolate the individual fractions and calculate their values (i.e 1/8)=($frac1[0]/$frac2[0])=(0.125). Question: How would I modify the script below to give me a loop which prints out of all the fraction values. At the moment I can only get print out of 0.5 0.5 0.5 for the last line as the others are overwritten. Hope this is clear ! Any takers ! cheers
if (/SYMM/) { (undef, $symmetry[$i]) = split /SYMM\s+/; ($symm[$i], $symm[$i], $symm[$i]) = split /,\s+/, $symmetry[$i]; $i++; next LOOP; } } close (IN); foreach $i(0..$symm) { if ($symm[$i] !~ /\d{1}/) { ($tmp2[$i], $tmp3[$i]) = split /\s+/, @symm[$i]; $tmp1[$i] = 0; }else{ ($tmp1[$i], $tmp2[$i], $tmp3[$i]) = split /\s+/, @symm[$i]; } ($frac1[$i], $frac2[$i]) = split (/\//, @tmp1[$i]); } print @value[0] = ($frac1[0]/$frac2[0]); print "\n"; print @value[2] = ($frac1[1]/$frac2[1]); print "\n"; print @value[3] = ($frac1[2]/$frac2[2]);

Edit Masem 2001-12-15 - Added CODE tags in text description


In reply to 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.