Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mod_perl subs 1

Status
Not open for further replies.

perl21

Programmer
Jul 13, 2005
22
US
Hi all,

Just started with mod_perl a month ago and still wondering about something.

I had to move my code from my .pm files because when I required them the sub routines weren't accessible from the main program I had now run in mod_perl

I moved them into a library and brought the code in with 'use' and assigned the scalar $standardLibrary to the library so I can get subroutines with $standardLibrary->SubRoutine('test','test2')

But when I bring the information, test & test2 into the sub routine with my usual $test1=shift; $test2=shift; and I print $test2 it will print out the text 'test' instead of the second item I passed to the sub routine. I got it to work by shifting the first element which seems to be nothing.

So my question is why are three items passed when I only want two. I'm worried about this because it's vital it work 100% of the time. Otherwise my database will have fields in the wrong place.

Thanks a lot everyone. if I find the answer first I'll post the fix
Tony
 
i don't know why this is happening - but in a worst case scenario could you use this:-

Code:
[b]#!/usr/bin/perl[/b]

&subRoutine('', '', '', 'a', 'b');

sub subRoutine {
  do {
    $test1 = shift; 
  } until $test1 ne '';
  $test2 = shift;
  print "\$test1 = $test1 | \$test2 = $test2";
}

this would just keep getting rid of empty initial values until there is some data there


Kind Regards
Duncan
 
Because you're actually calling your functions with object method syntax, the object name is implicitly supplied as the first variable. This would be the value of $standardlibrary.

f

"As soon as we started programming, we found to our surprise that it wasn't as easy to get programs right as we had thought. Debugging had to be discovered. I can remember the exact instant when I realized that a large part of my life from then on was going to be spent in finding mistakes in my own programs."
--Maurice Wilkes
 
Thanks fishiface

I'm ok with it now that I know it's supposed to do that and I'll always shift once before reading the rest of my data.

Thanks,
Tony
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top