[comp.lang.perl] Problems with "report"

brian@bkj386.uucp (Brian Jenkins) (05/22/91)

This problem occurs in both 3.0pl44 and 4.0pl3 under both 386 Xenix
(2.3.2 with the 2.2 development system), and ISC Unix (current
release). I thought I had problems with understanding how report
worked, so I bought the book, typed in programs and eventually
downloaded the programs from osu-cis.  I do not think the problem is
me, I think it is something in the format lines.

The following is the text of the report program in Chapter 2 of the
Book. The original program issued an out-of-memory message on both
systems and then the program core dumped. Very minor changes made it
work.

#!/usr/local/bin/perl

eval "exec /usr/local/bin/perl -S $0 $*"
    if $running_under_some_shell;
			# this emulates #! processing on NIH machines.
			# (remove #! line above if indigestible)

eval '$'.$1.'$2;' while $ARGV[0] =~ /^([A-Za-z_]+=)(.*)/ && shift;
			# process any FOO=bar switches


    # Set configuration parameters.

$ANNUAL_PAY_RATE = 52 * 5;      # That's 5 shekels per week.

    # First open my database.  Complain if unable.

open(STUFF, "stuff") || die "Can't open stuff: $!\n";

    # Now process each line.

while (<STUFF>) {

    # Split the record into its fields.

    ($beastie, $noses, $hazard, $premium, $servants)
	= split(/:/, $_);

    # Derive some fields.

    $totprem = $premium * $noses;
    $cost = $totprem + $servants * $ANNUAL_PAY_RATE;

    # Write a formatted record to STDOUT.

    write STDOUT;
}
exit;

################################################################

    # Here is the top of form format, with column headings.

format top =
                         Job's Stuff, Inc.
Beastie     Nose Insured       Premium    Servants  Total Est.
Name       Count Against    Each    Total           Yearly Cost
-------    ----- ---------- ----  -------  -------  -----------
.

   # Here is the format for each record.

format STDOUT =
#the original line which causes an out-of-memory and a core dump
#@<<<<<<<< @##### @<<<<<<<<<@#.## @####.##  @>>>>>>  @#######.##
#the one that works
@<<<<<<<< @##### @<<<<<<<<< @#.## @####.##  @>>>>>>  @########.##
$beastie, $noses,$hazard,$premium,$totprem,$servants,$cost
.

I think that I have missed something obvious, or there may be a
problem in the interpretation of the report format line.  I could
certainly use assistance on how to do things correctly (being
personally brain-dead most of the time).

Thank you for your help in advance.

And Larry - I know you are too busy to reply, but I truly enjoy
Perl.

_____________________________________________________________________________

print "not yet a perl hacker";
_____________________________________________________________________________

Brian Jenkins                      brian@bkj386
..hacking around the basement at   ...!uunet!attcan!telly!moore!bkj386!brian

-- 
----------------------------------------------------------------------------
from the basement of               brian@bkj386    - or -
Brian Jenkins                      ...!uunet!attcan!telly!moore!bkj386!brian
----------------------------------------------------------------------------