Passing a Variable or Value to a Subroutine in Perl
To pass a value to a
subroutine in Perl:
&gy("Hiya");
sub gy {
print "$_[0]";
}
Which Prints:
Hiya
-We called, or executed, the subroutine
gy and passed the value
Hiya.
-When a subroutine is called, whatever is inside the parenthesis is accessible in the built-in variable $_[0]
-In our subroutine
gy we said to print whatever is passed to it.
Copy and Paste Perl Code:
#!/usr/bin/perl
print "Content-type:text/html\n\n";
&gy("Hiya");
sub gy {
print "$_[0]";
}
exit;
Resources:
Create a Subroutine in Perl
Click HERE to comment or discuss at iLoveTheCode GOOGLE Group
| | | |
| | | HTML Gary B. Shelly, Th... |
| | | |