Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I want to modify this so it executes on each variable passed to it, e.g. $c1, then $c2, $c3, etc. This works for $c1:
$c1 = $query->param( 'c1' ); @cand_info = &get_cand_info( $c1 ); ..... sub get_cand_info() { my ( $c1 ) = @_; my @cand_info = (); my $pq_out; # Gather the information from a POST query. if( length($c1) == 7 ) { push( @cand_info, 'HRID' ); $pq_out = `/opt/bin/pq -o '%last:%first:%loc:%room:%te +l:%id' hrid=$c1`; } chomp $pq_out; # Put the data into the list. @cand_info = ( @cand_info, split(/:/, $pq_out) ); ($cand_info[1] = $cand_info[1]) =~ s/_/ /g; # name massage return @cand_info; }
I've been trying to do this by calling the subroutine in a loop, and passing it a variable which changes value each time through the loop, but with no success:
for ($gi = 1; $gi <= $tno; $gi++ ) { $tnum = "c".$gi; $tnum2 = $query->param( '$tnum' ); @cand_info = &get_cand_info( $tnum2 ); }
I'm worn out with trying different variations on how to pass the value(s) to the subroutine, help would be greatly appreciated.

Originally posted as a Categorized Question.

In reply to How do I pass a sequence of variable names to a subroutine one at a time? by guzz1

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2024-05-30 21:38 GMT
Find Nodes?
    Voting Booth?

    No recent polls found

    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.