Gossamer Forum
Home : General : Perl Programming :

Illegal variable name.

(Page 1 of 2)
> >
Quote Reply
Illegal variable name.
I've got the following script that keeps returning the error "Illegal variable name.". The trouble is, I don't see any variables which might cause any conflicts with reserved names. Can anyone help? Thanks!
Code:
#/usr/local/bin/perl -w

#___________________________________________________________________________
#
# index.cgi
#
# Revision : 16:06 12/11/01
#
# Author : Wiliam Stephens
# E-Mail : wilstephens@hotmail.com
#
#___________________________________________________________________________


$| = 1;

use CGI;
$query = new CGI;

print $query->header;

@listhtml = (index.apricot.html,
index.butter.html,
index.garden.html,
index.greek.html,
index.maple.html,
index.raspberry.html,
index.strawberry.html,
index.natural.html
);

$htmlrand = $listhtml[int rand @listhtml];

open (FILE, "</home/fba/beta.rachelsorganic.co.uk/$htmlrand");
@html = <FILE>;
close FILE;

print "@html";

exit;

- wil
Quote Reply
Re: [Wil] Illegal variable name. In reply to
Try:

@listhtml = qw(
index.apricot.html,
index.butter.html,
index.garden.html,
index.greek.html,
index.maple.html,
index.raspberry.html,
index.strawberry.html,
index.natural.html
);

Last edited by:

RedRum: Nov 12, 2001, 8:49 AM
Quote Reply
Re: [RedRum] Illegal variable name. In reply to
No that doesn't work. The only thing qw does is to define the array as a Word List.

Thanks anyway.

Wil

- wil
Quote Reply
Re: [Wil] Illegal variable name. In reply to
I have it working on my pc.

http://213.106.6.135/cgi-bin/du.cgi


Last edited by:

RedRum: Nov 12, 2001, 9:01 AM
Quote Reply
Re: [RedRum] Illegal variable name. In reply to
Still doesn't work on mine -> http://beta.rachelsorganic.co.uk/index.cgi

Could be something to do with that paticular server running Perl version 5.005_03?

Wil

- wil

Last edited by:

Wil: Nov 12, 2001, 8:59 AM
Quote Reply
Re: [Wil] Illegal variable name. In reply to
Hmm I guess. I'm using the latest version.

Last edited by:

RedRum: Nov 12, 2001, 9:01 AM
Quote Reply
Re: [Wil] Illegal variable name. In reply to
Wil,

Did you check the syntax of the file? perl -c index.cgi

Did you check your Perl error logs?

I would recommend adding the call to FatalsToBrowser so that you can see the error message.
========================================
Buh Bye!

Cheers,
Me
Quote Reply
Re: [Chewbaca] Illegal variable name. In reply to
Im not try to cause an argument but Fatals must have a lowercase f
Quote Reply
Re: [Chewbaca] Illegal variable name. In reply to
Hi Eliot

Thanks for the reply. However I've tried all of these already.

perl -c index.cgi outputs index.cgi syntax OK

Apache error log outputs Illegal variable name.

I'm using use stricts;, use diagnostics; and the -w flag running.

I've changed all variable names a few times to see if that would make any difference, which it doesn't.

?

Wil

- wil
Quote Reply
Re: [Wil] Illegal variable name. In reply to
After illegal variable name does it not give a line number?

Run it from telnet/ssh
Quote Reply
Re: [RedRum] Illegal variable name. In reply to
I am, and no line number is given.

- wil
Quote Reply
Re: [Wil] Illegal variable name. In reply to
Changing:
Code:
@listhtml = ( index.apricot.html,
index.butter.html,
index.garden.html,
index.greek.html,
... );
to:
Code:
@listhtml = ( 'index.apricot.html',
'index.butter.html',
'index.garden.html',
'index.greek.html',
... );
works for me. Have you tried that yet?
Quote Reply
Re: [Wil] Illegal variable name. In reply to
I guess you'll have to upgrade the perl binary or re-write the code then as it seems to be an issue with the version rather than the code itself. You should try enclosing the values with ' '

I did notice that you have:

print "@html"; exit;

You don't need to enclose perl code with " ". Lots of people seem to do:

print "$bla"; and print "@foo"; ....perldoc does mention not to do that.

You should do print @html; and print $var; etc.

I don't see why you have an exit in there either.

Last edited by:

RedRum: Nov 12, 2001, 9:36 AM
Quote Reply
Re: [CP] Illegal variable name. In reply to
Tried that CP. I've also tried quotation marks ("").

Tried removing the quotation marks from my print statement, Paul. That didn't want to know either.

Hmm. I've always put exit; at the end of my scripts since I started authoring Perl. What is the advantage/disadvantages?

Wil

- wil
Quote Reply
Re: [Wil] Illegal variable name. In reply to
Quote:
Tried removing the quotation marks from my print statement, Paul. That didn't want to know either.

That was just a general comment.

Using exit dooesn't matter it just isn't needed.

Last edited by:

RedRum: Nov 12, 2001, 9:50 AM
Quote Reply
Re: [Wil] Illegal variable name. In reply to
Try using strict and my() to see if you can solve the problem.
Quote Reply
Re: [RedRum] Illegal variable name. In reply to
Hmm. I always thought it was needed.

Or maybe I'm mistaken. I've always put it in everywhere. I actualy used to use exit1;

- wil
Quote Reply
Re: [RedRum] Illegal variable name. In reply to
Still no luck.

I am compeltly stumped by this.

If you were to write a similar block of code yourself? You'd go about it the way I have done, right?

I can't see any major flaws in the code? Expect for the obvious security checks, file open check etc. which I don't really need.

- wil
Quote Reply
Re: [Wil] Illegal variable name. In reply to
No the script should exit itself after all code is executed. You only need to add an exit if you need to stop the execution for some reason like in error subs.
Quote Reply
Re: [Wil] Illegal variable name. In reply to
It works for CP and myself (with a little alteration) so it must be a perl version issue.

Last edited by:

RedRum: Nov 12, 2001, 9:56 AM
Quote Reply
Re: [RedRum] Illegal variable name. In reply to
Now I've got this code. Does this exact code work for you guys?

Code:
$| = 1;

use CGI;
$query = CGI::new();

print $query->header();

@allhtml = ('index.apricot.html',
'index.butter.html',
'index.garden.html',
'index.greek.html',
'index.maple.html',
'index.raspberry.html',
'index.strawberry.html',
'index.natural.html'
);

$randhtml = $allhtml[int rand @allhtml];

open (HTMLDAT, "</home/fba/beta.rachelsorganic.co.uk/$randhtml");
@html = <HTMLDAT>;
close HTMLDAT;

print @html;

- wil
Quote Reply
Re: [Wil] Illegal variable name. In reply to
Try this...I just wrote it quickly....

Code:
#!/usr/bin/perl

print "Content-type: text/html\n\n";

my %list = ( 0 => 'index.apricot.html',
1 => 'index.butter.html',
2 => 'index.garden.html',
3 => 'index.greek.html',
4 => 'index.maple.html',
5 => 'index.raspberry.html',
6 => 'index.strawberry.html',
7 => 'index.natural.html'
);

my $htmlrand = $list{int(rand(7))};

print $htmlrand;

Last edited by:

RedRum: Nov 12, 2001, 10:08 AM
Quote Reply
Re: [Wil] Illegal variable name. In reply to
When printing the file data use (it is quicker):

open (H, "</home/fba/beta.rachelsorganic.co.uk/$htmlrand");
read (H, my $html, -s H);
close H;

print $html;

Last edited by:

RedRum: Nov 12, 2001, 10:12 AM
Quote Reply
Re: [RedRum] Illegal variable name. In reply to
Hashes are slower than Arrays?

And I want the number of elements in my hash/array worked out by the script, because I want to make it as easy as possible for a non-programmer to add elements to it.

Cheers

Wil

- wil
Quote Reply
Re: [Wil] Illegal variable name. In reply to
>>Hashes are slower than Arrays?<<

....not when we are talking about 7 keys vs 7 elements

>>And I want the number of elements in my hash/array worked out by the script, because I want to make it as easy as possible for a non-programmer to add elements to it.
<<

eh?

my $total = scalar keys %list;

Last edited by:

RedRum: Nov 12, 2001, 10:27 AM
> >