thanks for the help so far. the program is much
closer to what I want it to be now. the last thing is
to count the total number of fouls committed, send
them back to the 'main' program, and print them there.
I can do the sending back and printing, I'm not sure
how to do the counting. Essentially, it would be
counting the number of instances of the $typefoul
variable in the FoulParser subroutine. Can I get some
help?
You'll see in the code how I've attempted to put
$typefoul and $player into a @stuff array, return
that, and print the instances of $typefoul. YOu'll
also notice that I tried a failed attempt at counting
with a $count variable, but that failed. I only keep
those in to show I tried different things.
HEre is the code:
Note: Though I have been told twice, maybe 3x that I
do not need to declare the number of variables that I
am passing, my book, Perl for Beginners, says I do,
and, the program doesn't print anything when I leave
the declarations out. This is in 5.8.0.
Thanks in advance for your help. -stu
------------------------------------
# Subroutine prototypes
################################
sub FoulParser($$$);
#############################
# Main Program
#############################
use warnings;
use strict;
open(STATS, "stats.txt") or die "statfile\n";
my $foul;
my $foultype;
my $player;
my $count;
my @stuff;
while (<STATS>)
{
if ($_ =~ /(\w+) (Foul:) (\w+)/)
{
$foul = "$_";
$player = $1;
$foultype = $3;
print "\nline to be passed: $foul";
@stuff = FoulParser($foul, $player, $foultype);
my ($space1, $space2) = @stuff;
print "space1: $space1\n";
print "space2: $space2\n";
}
}
print "type of foul count: $count";
############################
# Subroutine Definitions
###########################
sub FoulParser($$$)
{
my ($line, $player, $typefoul) = @_;
my $count;
my @stuff;
print "selected line: $line";
print "Player's Name: $player\n";
@stuff = $player;
print "Type of foul committed: $typefoul\n";
@stuff = $typefoul;
$count = $typefoul;
$count++;
return @stuff;
}
----------------------------------------
--- Jeff 'japhy' Pinyan <[EMAIL PROTECTED]> wrote:
> 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. ]
>
__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]