in reply to passing variables between subroutines

&mailoff;

This syntax calls the named sub using the same @_ array as currently exists -- which doesn't since you aren't in a subroutine. Is that what you intended or are you just using the & calling style? (It is an older style held over from Perl 4 and generally not necessary unless you actually want to reuse @_.)

From reading the way your code is structured, it doesn't look like you're familiar with subroutine parameters. I think you might want to read perlsub, which talks about how subroutines pass arguments.

Here's some typical ways of passing and returning values:

sub some_function { my $arg1 = shift; # shift the first value off of @_ my ($arg2, $arg3, ) = @_; # or copy all of @_ at once # process stuff return $some_value; } # called like this $value = some_function( 1, 2, 3 );

For your problem, you probably want to store the result of IP_check and pass it to mailoff like this: mailoff( $ip_check_result ). mailoff will then need to shift the argument off of @_ as in the example above.

There are some other issues in your code around repeating my $info2, etc. -- you might want to also try use warnings as a learning tool

-xdg

Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Replies are listed 'Best First'.
Re^2: passing variables between subroutines
by budreaux (Initiate) on Jan 16, 2006 at 16:29 UTC
    Thanks to everyone for your help. It would appear I have some reading to do. I do have one more question though. Should I just call the mailoff sub from the IP_check sub instead of from the main body of the script? Would this be better?

      They're trying to explain you that you're using subs that are actually portions of code factorized away, but you're using them to manipulate "global" variables as a side effect. Sometimes it is sensible to do so, but it's rare: most often, and I mean most, you want to exploit a distinctive feature of them, precisely the one that makes them "functions", i.e. you give something to them to eat, and they spit out a result for you.

      Different languages use different mechanisms for parameter passing. Perl uses a special array called @_: there are several idioms in connection with it. To go on, I heartily recommend you read perldoc perlsub - you wrote that you're "self taught", so please (do a favour to yourself and) continue your self-teaching on that page!