I've no idea what you want to do. &call_variables doesn't expose any variables to the outside - all it does is return values.

Exactly my problem. I'll try to further (and hopefully better) explain what I want to do.

I have a section of code that I'm using in several programs. The section looks exactly like what is inside the sub I described above (no variation nor different values assigned, etc). If it were possible, I would copy and paste that section into every program it needs to go into. Of course, while you're running programs you can't very well say, "Hold on, I need to copy and paste that text into the program before you run it!" I'm using the same 25 lines of code (get the param, split the array, assign the variables their $array values), so I was looking for a way to somehow automagically insert that section each time.

I read the POD about Exporter. If I understand Abigail-II and arden correctly, Exporter will let me put my repeating section of code in a .pm package that I use or require. However, it seems like I'll still need to declare all the variables (my $one, my $two) near the beginning of each program that will be calling the sub. Do I have that right?

So, I would end up with something like:

#!/usr/local/bin/perl5_8 use strict; use Exporter; use myVars; #this would be my own myVars.pm use CGI; use CGI ':standard'; use CGI::Carp qw(fatalsToBrowser); my $CGI = CGI->new; $|=1; print $CGI->header; my ($one, $two .... $twenty-five); #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
This would be in the myVars.pm file:
sub call_variables { #pick up a string I've passed from previous program via 'spec_vars' my $spec_vars = param('spec_vars'); return (split /~/, $spec_vars)[0,1,2,3,4 .. 25]; }
That means that the above new stuff would be the same as if I had typed in this section into a program instead of calling the sub - is that right?
$one = $spec_vars[0]; $two = $spec_vars[1]; etc.

In the meantime, I'll be reading up on use and require to better understand the difference.

Lori


In reply to Re: Re: Re-calling in a list of variables into different .pl's by Lori713
in thread Re-calling in a list of variables into different .pl's by Lori713

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.