Can anyone explains why the first piece of code is working fine while the second is giving compilation error. Put both piece of codes in different pm files and try to compile it using perl command. The only difference in both the code snippets is order of sub-routines.
First code snippet:
Package one.pm
package one;
use strict;
sub authenticate {
my $login = {
uname => 'rajiv',
pwd => 'rajiv'
};
_validate($login);
}
sub _validate(){
my ($login) = @_;
if(($login->{uname} eq 'rajiv') && ($login->{pwd} eq 'rajiv')) {
print "Login success";
}
else {
print "Login failed";
}
}
1;
Second code snippet:
Package second.pm
package two;
use strict;
sub _validate(){
my ($login) = @_;
if(($login->{uname} eq 'rajiv') && ($login->{pwd} eq 'rajiv')) {
print "Login success";
}
else {
print "Login failed";
}
}
sub authenticate {
my $login = {
uname => 'rajiv',
pwd => 'rajiv'
};
_validate($login);
}
1;
Try compiling one.pm on shell.
shell>perl one.pm
shell>
Now try compiling two.pm on shell.
shell>perl two.pm
Too many arguments for two::_validate at two.pm line 21, near "$login)"
Execution of two.pm aborted due to compilation errors.
shell>
Please notice the empty parenthesis after _validate() sub.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.