in reply to Combining calls to a subroutine issue.

My first impulse would be to call that subroutine 3 times in one run:
if ( $page eq 'x1a.html' ) { $re_type = "a2"; $Q = ($prod) ? 'a0' : 'a0'; $send=$sec.$account.$year.$view; got_send(); # first "page" $re_type = "x2"; $Q = ($prod) ? 'p0' : 'w0'; $send=$sec.$account.$year.$view; got_send(); # second "page" $req_type = "y1"; $Q = ($prod) ? 'p0' : 'w0'; $send=$sec.$account.$year.$view.$action; got_send(); # third "page" }
(That's the "quickest" thing, though some rearrangement -- possibly using a loop over a data structure of call parameters -- would be worthwhile.)

But I suppose there might be something you haven't shown us in your "got_send()" sub that makes this impractical?

The way out would be to refactor the "got_send" sub to make it more modular: pass parameters to it on each call, instead of having it refer to global variables; have it return a string (or something), which the caller will know what to do with, based on the caller's knowledge of the context for each call, rather than trying to do everything inside of "got_send()".

Perhaps I'm misunderstanding the question? Or maybe you've left out some useful details...

Replies are listed 'Best First'.
Re^2: Combining calls to a subroutine issue.
by Anonymous Monk on Apr 14, 2010 at 17:28 UTC
    The trick part on this is that in the html file there are tags like, <!-- 2 --> and so forth that gets substituted by the value of the same tag number on this XML, and if the first call comes in with tag <2> equal something, how to get the second call having a different value on the same tag <2> and display on the same html page?
      Your description of the problem is too confusing (confused). What/where is this "html file" that has these comment tags like "<!-- 2 -- > and so forth"? Why are you using a format that is not really XML or HTML (or XHTML)? What does a client/user supply? What does the client/user want in response?

      Get down to first principles. Break things up into individual, modular components that do specific, simple parts of the task. Plug these components into subroutine calls in loops as needed, and make the code look like a natural-language description of the task. (I gather that English is not your first language, whereas it tends to be the first natural language for perl; this might be a problem, but sticking to simple "command-style" statements ("do this, then do that, then...") will serve you well enough.

      Separate the creation/management of data structure from the presentation of data, and set up a main-level controller that uses those two sets of functions ("model vs. view vs. control"). Based on what you've shown so far, I don't think there's anything else I can offer.

        What if I simplify or complicated my question where the end results on the tag numbers instead of duplicating they would increase, can this be done? What do you think?

        <1>66543 <2>2009 <3>TY <4>- <6> <7>TOM <8>2 - DUNDAS <8>100 - MAIN <9>ONT 00001 <10> <11>000-000-0000 <12> <13>12345 <14>1999 <15>PP <16>XLX - TEST <17>Comm <18> <19>1 BLVD <20>MA 00001 <21>CITI, INC. <22>000-000-0000 <23>

        Thanks!