develooper Front page | perl.beginners | Postings from March 2002

RE: Using strict and getting return values

Thread Previous | Thread Next
From:
Jason Larson
Date:
March 4, 2002 09:58
Subject:
RE: Using strict and getting return values
Message ID:
9F560B2FB311D6119A7D00204840E2059F20FC@swbtexch2.swbanktx.com
> -----Original Message-----
> From: Dermot Paikkos [mailto:dermot@sciencephoto.com]
> Subject: Using strict and getting return values
> 
> Hi Gurus,

Well, I'm definitely not a guru, but I think I might be able to help... :)
> 
> I am trying to get tidy with my scripts and want to use Strict but am 
> having difficulty with return values from subroutines. I have the 
> following snippet:
> 
>   while (defined(my $i =<$fh>)) {
>     chomp($i);
>     my @a = split(/|/,$i);
>     my $last = $a[1];
>     my $first = $a[0];
>     if ( $name =~ /$last/i ) {
>           return($first,$last);
>     }
>  and get the error:
> Global symbol "$last" requires explicit package name at 
> /var/www/perl/reply.pl line 16.

Where is line 16?  Can you post the whole code?  How did you call the sub
before getting the error?  Without knowing that, I'm going to make an
assumption that you did not assign values to the return from the sub.

> 
> When I later:  print "Hello $first $last\n";
> 
> I know it is out of the scope but I thought I could pass the 
> results of 
> a sub to main.
> 
> What am I doing wrong??
> Dp.

Assuming the name of your subroutine is SomeSub, the piece of your code that
calls the sub should look something like:

my ($FName, $LName) = SomeSub();

Then you can do:
print "Hello $FName $LName\n";


Hope this helps....
Jason


CONFIDENTIALITY NOTICE:

************************************************************************

The information contained in this ELECTRONIC MAIL transmission
is confidential.  It may also be privileged work product or proprietary
information. This information is intended for the exclusive use of the
addressee(s).  If you are not the intended recipient, you are hereby
notified that any use, disclosure, dissemination, distribution [other
than to the addressee(s)], copying or taking of any action because
of this information is strictly prohibited.

************************************************************************

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About