Previous Thread
Next Thread
Print Thread
Rate Thread
Joined: Sep 2002
Posts: 5
Junior Member
Junior Member
Offline
Joined: Sep 2002
Posts: 5
hi guys i bought a text to teach myself the basics of perl.. .and so far i understand everything except i decided just for fun to type out one of the beginning sample programs directly from the text.. and well, it doesn't work

the sample is this:

Code
 
#!/usr/bin/perl

@array = ( "Hello", 283, "there", 16.439 );

$i = 0;

while ( $i < 4 ) {
print "$i $array[ $i ]n";
++$i;
}
do any of you programmers out there see anything wrong with it?

my server is set up fine and programs like UBB run perfect on it so it's not a problem with my setup or whatever.. and i chmodded 755... i just can't see why it's returning a 500 internal server error

needless to say this is discouraging since this is a very basic example and it's not working

Sponsored Links
Joined: Mar 2001
Posts: 7,394
LK Offline
Admin / Code Breaker
Admin / Code Breaker
Offline
Joined: Mar 2001
Posts: 7,394
It's fine (I even tested it). Just don't forget this code is for command-line perl, not on your server. If you want your site to work with it, don't forget to print content-type: text/plain.

Joined: Sep 2002
Posts: 5
Junior Member
Junior Member
Offline
Joined: Sep 2002
Posts: 5
thanks a lot

i guess i didn't get to the part yet that explains the difference between command-line perl and the type for my server... i thought the perl interpreter on my server would be able to read this basic thing and print the results onto the screen

*trying not to get overwhelmed already* tipsy

Joined: Aug 2000
Posts: 874
Moderator / Developer
Moderator / Developer
Offline
Joined: Aug 2000
Posts: 874
Quote
code:
Code
++$i;

That's probably giving the error, should be;

code:
[qb]
Code
$i++;
[/qb]
Though I could be wrong and it could be valid.

Joined: Mar 2001
Posts: 7,394
LK Offline
Admin / Code Breaker
Admin / Code Breaker
Offline
Joined: Mar 2001
Posts: 7,394
jordo, I tried it in my computer and it works with ++$i wink

Sponsored Links
Joined: Mar 2001
Posts: 7,394
LK Offline
Admin / Code Breaker
Admin / Code Breaker
Offline
Joined: Mar 2001
Posts: 7,394
Oh, I have just noticed it's in Chit Chat, moving to serversidescripting smile

Joined: May 2000
Posts: 1,356
Addict
Addict
Joined: May 2000
Posts: 1,356
Quote
quote:
Originally posted by Poe Reader:
thanks a lot

i guess i didn't get to the part yet that explains the difference between command-line perl and the type for my server... i thought the perl interpreter on my server would be able to read this basic thing and print the results onto the screen

*trying not to get overwhelmed already* tipsy

When the server runs it and submits data to your browser, you have to specify what type of content is. Is the data a text file? Is the data a html file? Is the data an image file?? You say 'this is a text file' first and then send the contents of this text file... This 'Content-Type' is an "HTTP HEADER" field:

code:
[qb]
Code
#!/usr/bin/perl
@array = ( "Hello", 283, "there", 16.439 );
$i = 0;
print "Content-Type: text/plainnn";
while ( $i < 4 ) {
print "$i $array[ $i ]n";
++$i;
}
[/qb]
you must send header messages before the content...

Joined: Aug 2000
Posts: 335
Member
Member
Offline
Joined: Aug 2000
Posts: 335
As a general rule, the preincrement operator (++$i) is more efficient than the postincrement ($i++) operator.

The reason is that when the postincrement operator is used in an expression, it involves saving a temporary value.

In this case, it doesn't really matter, since $i is a simple variable and it's not part of a larger expression.

Joined: Sep 2002
Posts: 5
Junior Member
Junior Member
Offline
Joined: Sep 2002
Posts: 5
thanks tons! when i added the print content type part, it worked on my server just fine! yay!


Link Copied to Clipboard
Donate Today!
Donate via PayPal

Donate to UBBDev today to help aid in Operational, Server and Script Maintenance, and Development costs.

Please also see our parent organization VNC Web Services if you're in the need of a new UBB.threads Install or Upgrade, Site/Server Migrations, or Security and Coding Services.
Recommended Hosts
We have personally worked with and recommend the following Web Hosts:
Stable Host
bluehost
InterServer
Visit us on Facebook
Member Spotlight
Bill B
Bill B
Issaquah, WA
Posts: 87
Joined: December 2001
Forum Statistics
Forums63
Topics37,573
Posts293,925
Members13,849
Most Online5,166
Sep 15th, 2019
Today's Statistics
Currently Online
Topics Created
Posts Made
Users Online
Birthdays
Top Posters
AllenAyres 21,079
JoshPet 10,369
LK 7,394
Lord Dexter 6,708
Gizmo 5,833
Greg Hard 4,625
Top Posters(30 Days)
Top Likes Received
isaac 82
Gizmo 20
Brett 7
WebGuy 2
Morgan 2
Top Likes Received (30 Days)
None yet
The UBB.Developers Network (UBB.Dev/Threads.Dev) is ©2000-2024 VNC Web Services

 
Powered by UBB.threads™ PHP Forum Software 8.0.0
(Preview build 20240430)