On Jul 21, Stuart White said:

>I tried reading the perldoc, but it came up all screwy
>on my screen.  Lines ran over the end.  I'm having

Then you can read them online at http://www.perldoc.com/.

>trouble passing variables into a subroutine.    Also,
>once I get it passed, I want to pass it from there
>back to the main function.  Can someone help me figure
>this out?  This is the code that I have:

>sub FoulParser($$$);

You don't NEED function prototypes.  In fact, they're probably confusing
more than you need to be confused right now.  They're for very SPECIFIC
purposes, and I doubt you need them.

>use warnings;
>use strict;
>
>open(STATS, "stats.txt") or die "statfile\n";

You might want to include $! in your error message.

>my $foul;
>my $foultype;
>my $player;
>my @stuff;

You might want to define these variables in the block at which they're
needed.  That is, I don't think you use them outside this while() loop, so
why not wait until you're inside that if block?

> while (<STATS>)
> {
>       if ($_ =~ /(\w+) (Foul:) (\w+)/)
>       {
>        $foul = "$_";
>        $player = $1;
>        $foultype = $3;
>        print "line to be passed: $foul";
>       FoulParser($foul, $player, $foultype);
>  }
>       }

  while (<STATS>) {
    if (/(\w+) Foul: (\w+)/) {
      my $foul = $_;  # why not just use $_ instead of $foul?
      my $player = $1;
      my $foultype = $2;  # notice I got rid of the ()'s around Foul:

      FoulParser($foul, $player, $foultype);
    }
  }

>sub FoulParser($$$)
>{
> my ($foul, $typefoul, $player, @stuff);

Ok, the problem is that you don't ever give these variables values!  You
need to get them from @_, which is the array that function arguments are
placed into (automatically, by Perl).

  sub FoulParser {
    my ($line, $who, $type) = @_;

Now, it looks like you wanted to do $fouls{$foultype}{$player}++.  That's
fine.  Just declare %fouls beforehand, outside the subroutine (if you want
it to exist outside the subroutine, which I think you do).

    $fouls{$type}{$who}++;
  }

Please read the documentation, and RE-read the chapters of the book you're
using.

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
<stu> what does y/// stand for?  <tenderpuss> why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to