Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Undefined subroutine &main::

by davido (Cardinal)
on Aug 24, 2015 at 04:05 UTC ( [id://1139624]=note: print w/replies, xml ) Need Help??


in reply to Undefined subroutine &main::

You never declare and define getvalue1. This:

getvalue1{ print "$email : $token"; }

...should be this...

sub getvalue1{ print "$email : $token"; }

And your print statement probably would be better with a newline appended to the end:

print "$email : $token\n";

Another note: Though you are using lexical variables (my variables), you aren't using them effectively. One place where your use of lexicals could be improved upon is in how you pass values into subroutines. Instead of absorbing $email and $token into getvalue1(), pass values in:

sub getvalue1{ my ($e, $t) = @_; print "$e : $t\n"; }

...and invoke the subroutine like this:

getvalue1($email, $token);

In a small script like this it's not a big win, but in larger scripts (more than, say 100 lines), it becomes untenable trying to follow how a global variable's state gets manipulated throughout the course of the script. By keeping variable scopes small, and decoupling subroutines from the environment around them, you minimize action at a distance, and make it much easier to comprehend the program's logic, flow, and state.


Dave

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1139624]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2024-04-19 20:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found