Dear monks, Warning I am very new to perl! I am basically writing a CGI application where a file is submitted contianing 96 lines of numbers (plus a bit of junk) - i am filtering out the junk and then finding the single highest number on each line - i am currently using a foreach loop to do this but am not getting very far. I would be very grateful if someone could pick out where i'm going wrong. ;-) I am having no problems displaying the actual file, it is within the foreach loop where i am struggling, especaially picking out the highest number (also the CGI is very slow at processing so many numbers in the foreach loop). Thanx.
$data =~ s/([^\n]) (\n) ([^\n]) /$1$3/g; # data contains the input f +ile $data =~ s/\n+/\n/g; my @data = split /\n/, $data; my $in_derivative = 0; my $info; my $element; my @numbers; foreach my $line (@data) { if ($line =~ m/^\S{4}(\s+)Derivative(.*)/) { $in_derivative = 1; } if ($in_derivative) { $info .= "$line\n"; } } my @derivative = split (/\n/, $info); my $highest; my $i; foreach my $well (@derivative) { if ($well =~ s/^\S{4}(\s+)Derivative(.*)//) { next; } $well =~ s/^(\d+){1,2}//; my $well_no = $1; my @well = split ('', $well); $highest = $well[0]; # definately problems here, cant pick out $ +well[0] for ($i = 0; $i < @well; $i++) { if ($well[$i] > $highest) { $highest = $numbers[$i]; } } print $highest; }

In reply to foreach nightmare! by Anonymous Monk

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.