Gossamer Forum
Home : General : Perl Programming :

Illegal variable name.

(Page 2 of 2)
> >
Quote Reply
Re: [RedRum] Illegal variable name. In reply to
Ah. Shucks. Still no answer. I reckon it's my local copy of perl. Time for an upgrade I think.

- wil
Quote Reply
Re: [Wil] Illegal variable name. In reply to
Because you haven't enclosed the file names with " " or ' ' perl gives the illegal variable error as it thinks that the file name is supposed to be a variable.

You can't create an array like that - only perl variables can be ($var, $bla), everything else needs to be enclosed by ' ' or " " (or use qw)

So that is the cause. Upgrading perl is a good idea though.

Last edited by:

RedRum: Nov 12, 2001, 1:48 PM
Quote Reply
Re: [RedRum] Illegal variable name. In reply to
even quicker (maybe):
Code:
while (<FV>) { print }

--Philip
Links 2.0 moderator
Quote Reply
Re: [PerlFreak] Illegal variable name. In reply to
I _think_ read is faster.

Where did FV come from? ....have you been copying code from comp.lang.misc.perl Cool

Last edited by:

RedRum: Nov 12, 2001, 3:19 PM
Quote Reply
Re: [RedRum] Illegal variable name. In reply to
Paul, I've tried:

Code:
@allhtml = 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
);

and

Code:
@allhtml = ('index.apricot.html',
'index.butter.html',
...
);

Still no luck.

Can you run the following *exact* code on your system:

Code:
$| = 1;

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

print $query->header();

@allhtml = 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
);

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

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

print @html;

??

Cheers

Wil

- wil
Quote Reply
Re: [Wil] Illegal variable name. In reply to
I have done already and it works.
Quote Reply
Re: [RedRum] Illegal variable name. In reply to
That *exact* code? Hmph.

- wil
Quote Reply
Re: [Wil] Illegal variable name. In reply to
That code is longer and slower than it needs to be. All you need is:

Code:

#!/usr/bin/perl

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

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


my $rand = $html[rand @html];

open (H, "</home/fba/beta.rachelsorganic.co.uk/$rand");
while (<H>) { print; }
close H;

That will work with any version of perl. If it doesn't you screwed up your perl installation.

Also you don't need the int in [int rand @html] seeing as you aren't dealing with an integer Tongue

Last edited by:

RedRum: Nov 13, 2001, 5:35 AM
Quote Reply
Re: [RedRum] Illegal variable name. In reply to
You don't need int but it's good practice to include it.

I'll try your code.

The perl installation is fine, btw.

- wil
Quote Reply
Re: [RedRum] Illegal variable name. In reply to
Although, I don't see any difference with your code except for the file handling? Why would that work with "any version of perl" and mine not?

- wil
Quote Reply
Re: [Wil] Illegal variable name. In reply to
>>You don't need int but it's good practice to include it.
<<

Really? Not when you are using words and int() is for numbers.

>>Why would that work with "any version of perl" and mine not?
<<

Because my version is correctly formatted

Did you try it?


Last edited by:

RedRum: Nov 13, 2001, 5:50 AM
Quote Reply
Re: [RedRum] Illegal variable name. In reply to
Yep, doesn't work on two different machines. The machines are running:

perl -v 5.005_03
perl -v 5.6.0

Cheers

Wil

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

I tried your code and it worked fine for me. The only thing I changed was the path to the files. perl -v: This is perl, v5.6.1 built for MSWin32-x86-multi-thread. Don't know if that really helps or not :/

Regards,
Charlie
Quote Reply
Re: [Wil] Illegal variable name. In reply to
>>Yep, doesn't work on two different machines. The machines are running:

perl -v 5.005_03
perl -v 5.6.0
<<

You must be doing something wrong as it works for me with 5.6.0, 5.6.1 and 5.005

Last edited by:

RedRum: Nov 13, 2001, 6:17 AM
Quote Reply
Re: [RedRum] Illegal variable name. In reply to
Ah well. Thanks for all your help guys!

- wil
I'm going to come back to this one. Leave it for a few hours I think. Might fix itself :-)

Last edited by:

Wil: Nov 13, 2001, 6:30 AM
Quote Reply
Re: Illegal variable name. In reply to
Hahaha!!! I found the problem.... Look at the first line of my original code. Look at the shebang. Missing a !? :-)

I wrote:

#/usr/local/bin/perl

instead of

#!/usr/local/bin/perl

Took me absolute ages to figure that out! In end it becamse obvious that it wasn't a Perl problem but the system couldn't figure out what on earth I was tyring to do :-\

ROFL! Grrrrrrrrr......

Cheers

Wil

- wil
Quote Reply
Re: [Wil] Illegal variable name. In reply to
How annoying. It is always the most obvious things that take the longest to find.
Quote Reply
Re: [RedRum] Illegal variable name. In reply to
Yep. Thanks for your help, though. Much appreciated.

- wil
Quote Reply
Re: [RedRum] Illegal variable name. In reply to
huh? it was a type... I meant to type <FH>. I haven't visited comp.lang.perl in months.

--Philip
Links 2.0 moderator
Quote Reply
Re: [PerlFreak] Illegal variable name. In reply to
Chill Drew, I was pullin ya chain.
Quote Reply
Re: [Wil] Illegal variable name. In reply to
Wil, the only error wasn't just the missing ! so you must have changed what CP and myself suggested too about the missing ' ' or " "

The file names would have caused errors the way you had them

As this shows:

Not enough arguments for index at e:\apache\cgi-bin\du.cgi line 12, near "index."
Not enough arguments for index at e:\apache\cgi-bin\du.cgi line 13, near "index."
Not enough arguments for index at e:\apache\cgi-bin\du.cgi line 14, near "index."
Not enough arguments for index at e:\apache\cgi-bin\du.cgi line 15, near "index."
Not enough arguments for index at e:\apache\cgi-bin\du.cgi line 16, near "index."
Not enough arguments for index at e:\apache\cgi-bin\du.cgi line 17, near "index."
Not enough arguments for index at e:\apache\cgi-bin\du.cgi line 18, near "index."
Not enough arguments for index at e:\apache\cgi-bin\du.cgi line 19, near "index."

Last edited by:

RedRum: Nov 13, 2001, 11:53 AM
Quote Reply
Re: [RedRum] Illegal variable name. In reply to
Yep, I chaned that to include '' straight away after posting. I don't like "" (quotation marks) and I don't like using qw when I want to astheticaly lay out the array on the page. It makes me nervous about Perl not reading them correctly.

In response to an earlier post. You are right about hashes being faster han arrays. The difference is neglibale to the size of my array, nut in a different situation it would make a difference.

The funny thing is I downloaded ActivePerl for Win32 so I had to change the shebang line to #c:/ or whatever, and that's where I noticed the error.

Where would I be without Windows? <g>.

- wil
Quote Reply
Re: [Wil] Illegal variable name. In reply to
Yes, large arrays are much faster than large hashes
Quote Reply
Re: [RedRum] Illegal variable name. In reply to
You mean hashes are faster than arrays.

Look it up in your Camel book.

Wil

- wil
> >