I tried reading the perldoc, but it came up all screwy
on my screen. Lines ran over the end. I'm having
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:
#!/usr/bin/perl
#################################
# Subroutine prototypes
################################
sub FoulParser($$$);
#############################
# Main Program
#############################
use warnings;
use strict;
open(STATS, "stats.txt") or die "statfile\n";
#my %fouls;
#my ($type, $totalFouls);
my $foul;
#my $total;
my $foultype;
my $player;
my @stuff;
while (<STATS>)
{
if ($_ =~ /(\w+) (Foul:) (\w+)/)
#if ($_ =~ /Foul/)
{
$foul = "$_";
$player = $1;
$foultype = $3;
print "line to be passed: $foul";
# %fouls = FoulParser($foul, $player, $foultype);
FoulParser($foul, $player, $foultype);
}
}
############################
# Subroutine Definitions
###########################
sub FoulParser($$$)
{
#my %foulsData;
#my %fouls;
my ($foul, $typefoul, $player, @stuff);
# $fouls{$foultype}{$player}++;
print "from sub, passedLine: $foul\n";
$stuff[0] = $foul;
$stuff[1] = $typefoul;
$stuff[2] = $player;
#<STDIN>;
print "sub this arra: @stuff\n";
return @stuff;
}
--- "John W. Krahn" <[EMAIL PROTECTED]> wrote:
> Stuart White wrote:
> >
> > Hello all,
>
> Hello,
>
> > I seem to be stuck on subroutines. I've read the
> Perl
> > for Beginners Wrox chapter on them, and I'm still
> a
> > bit lost.
>
> The first thing that you should read is the
> documentation supplied with
> Perl. The document describing subroutines is
> perlsub.pod.
>
> perldoc perlsub
>
>
> > My problem is passing a scalar to a
> > subroutine, doing calculations therein, and then
> > returning a value; or basically, subroutines in
> > general.
>
> Subs in Perl are pretty simple. All arguments to
> the sub are flattened
> to a list and are available inside the sub in the @_
> array but be
> careful because modifying the contents of @_ will
> modify the contents of
> the original variables. All return values are also
> flattened to a list
> when the sub ends.
>
>
> John
> --
> use Perl;
> program
> fulfillment
>
> --
> To unsubscribe, e-mail:
> [EMAIL PROTECTED]
> For additional commands, e-mail:
> [EMAIL PROTECTED]
>
__________________________________
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]