This is perl, v5.6.1 built for MSWin32-x86-multi-thread
(with 1 registered patch, see perl -V for more detail)
------------------------------------------
what is the difference b\w subroutine calls:
normally a sub can be called like a function - without the & in front as long as you have the ( ) part at the end so the interpreter can figure out it's a subroutine.
You must have the & when:
you call a subroutine without parameters: ⊂
you call a subroutine indirectly by name &$subref(args);
you call a subroutine by reference &$subref;
normally a sub can be called like a function - without the & in front as long as you have the ( ) part at the end so the interpreter can figure out it's a subroutine.
The fact is a little bit more complicated.
The ( ) can be omitted as well, as long as the subroutine has already been defined at the point of the call.
Code:
#!/usr/bin/perl -w
use strict;
sub echo {
my $str = shift;
print $str if (defined $str);
}
echo;
echo "Hello World!\n";
will not give any warnings at all. But if you put the sub at the bottom:
Code:
#!/usr/bin/perl -w
use strict;
echo;
echo "Hello World!\n";
sub echo {
my $str = shift;
print $str if (defined $str);
}
The solitary "echo;" will give an error for bareword usage (if you remove the use strict, it will be a warning instead). If you place the & back in, it will now be okay:
Code:
#!/usr/bin/perl -w
use strict;
&echo;
echo "Hello World!\n";
sub echo {
my $str = shift;
print $str if (defined $str);
}
So to "&" or not sometimes depends on the order you define and use subroutine and their references. For the other case, see below.
Quote:
Originally Posted by jim mcnamara
you call a subroutine without parameters: ⊂
you call a subroutine by reference &$subref;
Also note that in these two cases the current @_ as a list of params will be passed to the called subroutine. So
⊂
&$subref;
is the same as
sub(@_); OR &sub(@_);
&$subref(@_);
but not the same as
&sub();
&$subref();
respectively.
See perlsub manpage for total treatment of the subject.
Hi,
I am an occasional PERL user. I am trying to call a sub routine (passing parameters) in perl module from a driver .pl file. I have been "tinkering" for a while now and have confused myself.
Could someone please look at the code below and spot where I am going wrong.
testPerl.pl
... (0 Replies)
Hi,
Please help me here while passing the paramert to fuction i am facing problem.
i tryied passing 7 PARAMeter in side single quote,double quate even tried tild sign not working.
how can assign it properly .
usage ()
{
typeset -i NumPARAMs=$1
typeset -i PARAM1=$2
typeset PARAM2=$3... (3 Replies)
hello,
i am new to scripting and would like to know how to return a hash table from a sub routine.
i tried the following,
my %hash_function = ();
hash_function = &return_hash();
sub return_hash
{
my %hash = ();
///populate the hash
return %hash;
}
but it dosent seem to... (1 Reply)
Hi all
I have written a simple perl script that has different options i.e. myscript -l -p etc
i have it so when it runs without any switches it runs a subroutine called nvrm_norm
i want to be able to do a -p option and run
pall -w -f and then called the subruotine
pall is... (1 Reply)
Hi,
I use awk but not as a programming language. Just generally in piplelines to split things out by fields.
I am trying to accomplish this one thing that I think a short awk routine would do great for, but can't figure it out.
Lets say I have a file that contains database columns. The file... (25 Replies)
Hello experts,
I need some help here..
I've written the following routine to check for existence of files. The routine does the following. It will look for a compressed ( .Z ) file and if it exists, then it will uncompress it, if it is already uncompressed, then it will just diplay a message... (9 Replies)
hi all,
I wanted to know how we can copy files to dirs, through a routine and when the file and the dir are specified as parameters for that routine and explicitly called?
Eg: suppose i want to copy file1 to /tmp then
myproc()
{
.
.
}
myproc /path/file1 /tmp/
These parameters when... (4 Replies)
hi all,
I wanted to know how we can copy files to dirs, through a routine and when the file and the dir are specified as parameters for that routine and explicitly called?
Eg: suppose i want to copy file1 to /tmp then
myproc()
{
.
.
}
myproc /path/file1 /tmp/
These parameters when... (1 Reply)
How do we pronounciate bdevsw and cdevsw Kernel resources ?
I presume it as block or charcter device software table. Am I Correct in my assumption ?
Thanks in advance. (9 Replies)