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

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

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

 



etheracide
journeyman

Jul 7, 2001, 12:33 PM

Post #1 of 2 (914 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="http://etheracide.hypermart.net/cgi-bin/testetheracidebook/images/home.gif" 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 = 'http://etheracide.hypermart.net/cgi-bin/testetheracidebook';

and then:

$IMAGEBASEURL = '$BASEURL/images';

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/hypermart.net/username/cgi-bin/etc/etc/';

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.



mhx
Enthusiast / Moderator

Jul 7, 2001, 2:11 PM

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


In Reply To
I tried creating the following:

Code
$BASEURL = 'http://etheracide.hypermart.net/cgi-bin/testetheracidebook';

and then:

Code
$IMAGEBASEURL = '$BASEURL/images';

and then in the script I tried making each image link

Code
<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

Code
$BASEURL/images/imagename.gif

instead of

Code
http://etheracide.hypermart.net/cgi-bin/testetheracidebook/images/imagename.gif

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:

Code
$IMAGEBASEURL = "$BASEURL/images";

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

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

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

Code
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:

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

and so on instead of

Code
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