Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Perl Script to write a perl script

by Limbic~Region (Chancellor)
on Dec 03, 2009 at 03:12 UTC ( [id://810731]=note: print w/replies, xml ) Need Help??


in reply to Perl Script to write a perl script

electroman00,
Everyone has suggested using some form of templating and I agree. I also know that sometimes learning method X when what I want to do is Y can be frustrating. Here is an example using HTML::Template - When should I use a dispatch table?. It isn't particularly good but it shows how easy it is and was one I remembered off the top of my head. Don't get frustrated, take things 1 step at a time.

Cheers - L~R

Replies are listed 'Best First'.
Re^2: Perl Script to write a perl script
by electroman00 (Novice) on Dec 03, 2009 at 15:40 UTC
    First, thanks for the responses. After posting this I did do further research and found HTML::Template. Not sure it's what I'm looking for though. The code I provided was an example of the task at hand. Basically, it's to take a perl script and treat it as a flat text file and read it in substituting the vars as needed from the perl script creator. I do have a working bash script that was very easy to make.
    #!/bin/bash APPNAME="AnyApp" screen=1 if [! screen ]; then { cat > /tmp/new_prog_file << EOF } else { cat << EOF } print "This is the var \$APPNAME and this is what needs to get substit +uted $APPNAME\n"; EOF
    Works a treat with little effort (max efficiency) the goal. However perl seems to be a cronic complainer. It seems from tests so far the only way to get perl to sub the vars is to make prog_files an include, then perl complains about everything in prog_files. As a note.... \$APPNAME results in $APPNAME.... $APPNAME results in AnyApp.... Bash just eats, digests and spits out the result. Simple, my favorite method KISS. Now I also tried the equiv in perl....
    #!/usr/bin/perl $APPNAME="AnyApp" require "prog_file.lib"; read_prog
    prog_file.lib
    sub read_prog print <<"EOF"; print "This is the var \$APPNAME and this is what needs to get substit +uted $APPNAME\n"; EOF 1;
    The problem is getting an "if" to print to screen or to a file to work, either from the require sub or from the perl creator prog. Easy using bash, not so with perl....at least not for me. My mind is already boggled by the var substitutions that needed to be done throughout. Solved the var boggle issue using a var naming convention. Thanks in advance...
Re^2: Perl Script to write a perl script
by electroman00 (Novice) on Dec 04, 2009 at 18:07 UTC
    Thanks for the advice, however the server that is going to be running the prog doesn't have, nor will it have the mods loaded by default. So it kinda rules out using the mod, at least for now.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://810731]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2024-04-23 06:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found