develooper Front page | perl.beginners | Postings from September 2003

how to reuse sub

Thread Next
From:
perl
Date:
September 26, 2003 23:13
Subject:
how to reuse sub
Message ID:
1484.66.93.71.122.1064643320.squirrel@webmail.swanmail.com
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

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About