|
Joined: Sep 2002
Posts: 5
Junior Member
|
Junior Member
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: #!/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
|
|
|
|
Joined: Mar 2001
Posts: 7,394
Admin / Code Breaker
|
Admin / Code Breaker
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
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* 
|
|
|
|
Joined: Aug 2000
Posts: 874
Moderator / Developer
|
Moderator / Developer
Joined: Aug 2000
Posts: 874 |
code:
That's probably giving the error, should be; code: [qb][/qb] Though I could be wrong and it could be valid.
|
|
|
|
Joined: Mar 2001
Posts: 7,394
Admin / Code Breaker
|
Admin / Code Breaker
Joined: Mar 2001
Posts: 7,394 |
jordo, I tried it in my computer and it works with ++$i 
|
|
|
|
Joined: Mar 2001
Posts: 7,394
Admin / Code Breaker
|
Admin / Code Breaker
Joined: Mar 2001
Posts: 7,394 |
Oh, I have just noticed it's in Chit Chat, moving to serversidescripting 
|
|
|
|
Joined: May 2000
Posts: 1,356
Addict
|
Addict
Joined: May 2000
Posts: 1,356 |
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*
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]#!/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
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
Joined: Sep 2002
Posts: 5 |
thanks tons! when i added the print content type part, it worked on my server just fine! yay!
|
|
|
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.
|
|
Posts: 449
Joined: February 2008
|
|
Forums63
Topics37,575
Posts293,930
Members13,823
|
Most Online6,139 Sep 21st, 2024
|
|
Currently Online
Topics Created
Posts Made
Users Online
Birthdays
|
|
|
|