Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
i am working on dynamically building a .conf file by using "include" like statements within a script. i read over this which pointed me towards reading this and got me off on the right foot. however, some of the scripts ran through 'do' need to be able to pull variable values from the original script. an example will hopefully clarify:

genconf.pl

#!/usr/bin/perl -w use strict; my $domain = "lunarmedia.net"; do 'genheader'; do 'genlimit'; do 'genfooter';

###

genheader

print "<VirtualHost $domain>\n";

the genconf.pl file executes and runs the three external scripts. each of the external scripts just prints out a line of text. however, as you can see in genheader, a portion of the text requires some sort of knowledge about a variable set within the main script.

the only way i figured i could get around this is to try something like:

genconf.pl

#!/usr/bin/perl -w use strict; require genheader; require genlimit; require genfooter; my $domain = "lunarmedia.net"; &genHeader($domain); &genLimit; &genFooter;

###

genheader

sub genHeader { my $domain = shift; print "<VirtualHost $domain>\n"; }

but i dont believe that i am really understanding require because the magic just isnt happening with this code either. i think using the require or even a 'use' statement for a future module possibility(?) may be the way i want to go, however, i am not certain what i am missing in my required file to make it work. could someone enlighten me?

humbly -c


In reply to Passing variables to scripts rans through 'do' by c

Title:
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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-04-24 05:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found