OK, I added the return line to sub. But I'm getting an error on the line
require "mycommon.pl" of the tst.pl file. It say something about @INC
cannot find mycommon.pl
any help here?
How can I reuse a subroutine?
My environment is redhat 9, apache2, perl-5.8.0-88, mod_perl-1.99_07-5.
I've tried to put the sub in a separate file and call it from another as
below. Please modify the snipet below to make it work.
mycommon.pl
-----------
#!/usr/bin/perl
#return a value wrapped by single quotes
#should this be declare package something?
sub doWrap
{ my $retval;
if(length($_[0]) == 0) { $retval = "null"; }
else { $retval = "'" . $_[0] . "'"; }
}
tst.pl
------
#!/usr/bin/perl
require "mycommon.pl";
print &doWrap("hello"); #should output 'hello' with single quotes
thanks,
-rkl
> On Sep 26, [EMAIL PROTECTED] said:
>
>>#!/usr/bin/perl
>>#return a value wrapped by single quotes
>>#should this be declare package something?
>>sub doWrap
>>{ my $retval;
>>
>> if(length($_[0]) == 0) { $retval = "null"; }
>> else { $retval = "'" . $_[0] . "'"; }
>>}
>
> You need to RETURN $retval. It's always a wise idea to explicitly state
> the return value of a function.
>
> And your file should end in 1;, so that Perl knows the file works right.
>
> sub doWrap {
> # ...
> return $retval;
> }
>
> 1;
>
> --
> Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/
> RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/
> <stu> what does y/// stand for? <tenderpuss> why, yansliterate of course.
> [ I'm looking for programming work. If you like my work, let me know. ]
>
>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]