in reply to reading from middle of file

my %hash; open(ANSWERTALLY, "answertally.dat"); while(<ANSWERTALLY>) { next unless /^Running totals:/ .. /^Averages:/; next if /^Running totals:/; last if /^Averages:/; my ($key, $value) = split(/\s=\s/); chomp($value); $hash{$key} = $value; } close(ANSWERTALLY);
--
<http://www.dave.org.uk>

"The first rule of Perl club is you do not talk about Perl club."
-- Chip Salzenberg

Replies are listed 'Best First'.
Re^2: reading from middle of file
by guisilva (Initiate) on Aug 12, 2004 at 16:36 UTC
    Thank you, it has worked!! I only have two more questions.

    Question 1:
    First, if I'm printing a string and the value of a calculation of 2 variables, as in:

    print "The average is $total/$count";
    ...how can I do it so that the value of the calculation shows up?? Right now I'm getting something like:
    The average is 60/9
    Do I have to use PRINTF??? In fact, while we're on this subject, how can I format the value so that it only has two decimal places?

    Question 2:
    What are these NEXT, UNLESS and LAST statements? In my whooping 1 week of PERL, I haven't yet come across these statements. I'd like to learn. Can you suggest a good place for looking up PERL syntax/statements?

    Thanks a bunch

      Question 1:
      First, if I'm printing a string and the value of a calculation of 2 variables, as in:
      print "The average is $total/$count";
      ...how can I do it so that the value of the calculation shows up?? Right now I'm getting something like:
      The average is 60/9

      Just take the calculation out of the quoted string.

      print "The average is ", $total/$count;
      Do I have to use PRINTF??? In fact, while we're on this subject, how can I format the value so that it only has two decimal places?

      That you can do with printf.

      printf "The average is %.2f", $total/$count;
      Question 2:
      What are these NEXT, UNLESS and LAST statements? In my whooping 1 week of PERL, I haven't yet come across these statements. I'd like to learn. Can you suggest a good place for looking up PERL syntax/statements?

      Type perldoc perltoc at your command line to see the table of contents for the Perl documentation. For the loop control statements, see the "Loop control" section in perldoc perlsyn.

      --
      <http://www.dave.org.uk>

      "The first rule of Perl club is you do not talk about Perl club."
      -- Chip Salzenberg

      print "The average is " . $total/$count . "\n";

      -or a little more fun-

      print "The average is @{[$total/$count]}\n";

      but as you say this is floating point output so printf it:

      printf ("The average is %2.2f",  $total/$count)

      Cheers,
      R.