Lori713 has asked for the wisdom of the Perl Monks concerning the following question:
I was thinking maybe a using a subroutine to call them in, but I can't figure out how to do that. Here's what I'm thinking:
This would be the sub:#!/usr/local/bin/perl5_8 use strict; use CGI; use CGI ':standard'; use CGI::Carp qw(fatalsToBrowser); my $CGI = CGI->new; $|=1; print $CGI->header; #call my variables that are always the same &call_variables; #do other stuff using these called-in variables #without having to declare "my $one" and "my $two" again $fred = $one . $two; #or some such silliness
BTW, it would be nice to figure out a way to iterate over the index numbers, but I think I can figure that out later.sub call_variables { #pick up a string I've passed from previous program via 'spec_vars' my $spec_vars = param('spec_vars'); my @variables_array = split /~/, $spec_vars; my $one = $variables_array[0]; my $two = $variables_array[1]; my $three = $variables_array[2]; my $four = $variables_array[3]; my $five = $variables_array[4]; return ($one, $two, $three, $four, $five); }
Would it be better to create a small .txt file, read that in, and then try to get it to spit it out each time I run &call_variables? Should I create a little package that contains all these?
I'm sure there's severals ways to do this. I read the section on subroutines in the Llama book but nothing seem to address the concept of just "reading in" lines into the main program and returning those values to the program (because it only returns the last value from what I understand, plus it doesn't allow me to just use the variables without "my"ing them again).
Thanks for any light you can shed!
Lori
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re-calling in a list of variables into different .pl's
by Abigail-II (Bishop) on Feb 06, 2004 at 14:26 UTC | |
by Lori713 (Pilgrim) on Feb 06, 2004 at 15:17 UTC | |
by Abigail-II (Bishop) on Feb 06, 2004 at 15:33 UTC | |
by Lori713 (Pilgrim) on Feb 06, 2004 at 16:07 UTC | |
by ysth (Canon) on Feb 06, 2004 at 16:45 UTC | |
| |
|
Re: Re-calling in a list of variables into different .pl's
by calin (Deacon) on Feb 06, 2004 at 14:48 UTC | |
|
Re: Re-calling in a list of variables into different .pl's
by hardburn (Abbot) on Feb 06, 2004 at 14:21 UTC | |
|
Re: Re-calling in a list of variables into different .pl's
by arden (Curate) on Feb 06, 2004 at 14:26 UTC |