CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner:
base paths/URLs



Jul 7, 2001, 12:33 PM

Post #1 of 2 (987 views)
base paths/URLs Can't Post

I am going to try to to make this understandable heh

Well Marcus had asked about my extensive use of globals in my current script. My reason is that this script is distributed to anyone who wants to use it and I found that it is easier for people to change what they need in order to customize the output if i include them as variables. But this is personal experience and I am open to arguments. Anyway:

I use this 'global' scalar to call up an image.
$HOMEIMAGE = '<img src="" border=0 alt="Click here to visit their site">';

And of course later I refer to it as $HOMEIMAGE and this always works. Currently I have only two images so there were just two globals like this so it remained relatively neat. however, my current upgrade should include the use of emoticons. I plan to offer quite a few emoticons and this would become messy.

I tried creating the following:

$BASEURL = '';

and then:


and then in the script I tried making each image link

<img src=\"$IMAGEBASEURL/imagename.gif\">

I end up with a broken image link. I see a couple places where I could have one or multiple errors.

I have also tried a combination of using base paths such as:
BASEPATH = '/data1/';

I guess I am going back to Perl 101 and say that I wasn't sure when to use the path or the URL.

When I had originally written the script, I didn't think far enough ahead about what people might want in the script so I set it up with the whole global which called the direct URL to the image. This worked, but I need to change it for the new images and such. Thank you for your time.

Enthusiast / Moderator

Jul 7, 2001, 2:11 PM

Post #2 of 2 (984 views)
Re: base paths/URLs [In reply to] Can't Post

In Reply To
I tried creating the following:

$BASEURL = '';

and then:


and then in the script I tried making each image link

<img src=\"$IMAGEBASEURL/imagename.gif\">

If this is really what's in your source code, the problem is the non-interpolative single quotes. Because only double quotes (or the regex quotes or the qq operator) interpolate Perl variables, your image source URL would have been


instead of


and the first one does of course not exist.
To solve this problem, simply put the strings you use variables in in double quotes or equivalent:


If you use the qq operator, you can arbitrarily choose your quoting symbol, so you don't have to escape the double quotes, like

print qq(<img src="$IMAGEBASEURL/imagename.gif">);

The best alternative would be to use the CGI package and write:

print img( {src => "$IMAGEBASEURL/imagename.gif"} );

Hope this helps.

-- Marcus

P.S.: Concerning your globals, I always find hash tables very appropriate for configuration purposes. You could write:

my %config = ( 
BASEPATH => "whatever",
TITLE => "Welcome wherever you are!",

and so on instead of

my $BASEPATH = "whatever"; 
my $TITLE = "Welcome wherever you are!";

This is my own, humble opinion. Perhaps you like it ;-)

(This post was edited by mhx on Jul 7, 2001, 1:19 PM)


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives