Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jun 13th, 2007, 4:11 PM   #1
teishu
Programmer
 
Join Date: May 2006
Posts: 49
Rep Power: 0 teishu is on a distinguished road
small error..

hi, just learning perl can someone tell me whats wrong with this:


print "The months of the year are: \n";
@months = ("January \n", "Febuary \n", "March \n", "April \n", "and so on... \n")
for $i (1, 2, 3, 4, 5) {
	print "@months \n";
	}

i get this error:

teishu@debian:~/prl$ perl months.pl
syntax error at months.pl line 5, near "$i ("
Execution of months.pl aborted due to compilation errors.

thanks
__________________
Intel Pentium M 1.73Ghz -- Sony Vaio -- 1024MB Ram -- Ubuntu 8.04
AMD Athlon X2 4200+ -- Asus V3-M2V890 -- 2GB Kingston -- Vista Ultimate 32bit
Intel C2D E4400 -- 2048MB GeIL - Windows XP SP2

ASCII stupid question, get a stupid ANSI !
teishu is offline   Reply With Quote
Old Jun 13th, 2007, 4:48 PM   #2
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
No error that trashes your program is a small error. The forum gets lebenty-jillion posts that claim failures are a bug. Bugs are relatively common, but they don't hold a candle, percentage-wise, to the mistakes that are programmer generated. Instead of asking "What's wrong with this", would you care to explain the difference between what you expect and what you get?

If not, we'll have to presume what you want versus what you get. At zero dollars per hour, that's not very profitable. Regardless of our altruistic propensities, that's not very satisfying.

Your move.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Jun 13th, 2007, 9:17 PM   #3
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
You are missing a ; after your array list. It should run then, but you probably won't get what you expect.
__________________
http://jasonpowers.net

"There are a thousand hacking at the branches of evil to one who is striking at the root."
Infinite Recursion is offline   Reply With Quote
Old Jun 14th, 2007, 12:24 AM   #4
snipertomcat
Programmer
 
snipertomcat's Avatar
 
Join Date: Nov 2005
Location: Spring Valley, CA
Posts: 52
Rep Power: 3 snipertomcat is on a distinguished road
Exactly what do you want the program to do?
__________________
if (u=an_asshole) then GOTO (hell)
snipertomcat is offline   Reply With Quote
Old Jun 14th, 2007, 12:52 AM   #5
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Every language and every application has fuck-ups. Ninety-nine percent of them are upstream, between the user's fingertips and the user's purported brain. Would you care to expand upon your problem, in some sort of meaningful detail?
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Jun 14th, 2007, 2:03 AM   #6
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
Lets take a random stab in the dark and assume he wants to print out the contents of the month array accessing one element at a time. If this is not what you want, elaborate.

#!/usr/bin/perl

print "The months of the year are: \n";
@months = ("January", "Febuary", "March", "April", "and so on...");
for ($i = 0; $i < 5; $i++) 
{
        print "$months[$i]\n";
}

On a side note, why even include a newline in the values of the array? This is more of a formatting option than it is part of the data... so imho, its best left for the print statement to handle.

On another side note, why even care how many elements the array has when printing it, if you are going to print them all anyway... do this:

#!/usr/bin/perl

print "The months of the year are: \n";
@months = ("January \n", "Febuary \n", "March \n", "April \n", "and so on... \n");

foreach $myMonth (@months)
{
        print "$myMonth\n";
}
__________________
http://jasonpowers.net

"There are a thousand hacking at the branches of evil to one who is striking at the root."
Infinite Recursion is offline   Reply With Quote
Old Jun 15th, 2007, 7:08 PM   #7
teishu
Programmer
 
Join Date: May 2006
Posts: 49
Rep Power: 0 teishu is on a distinguished road
Quote:
Originally Posted by Infinite Recursion View Post
Lets take a random stab in the dark and assume he wants to print out the contents of the month array accessing one element at a time. If this is not what you want, elaborate.

#!/usr/bin/perl

print "The months of the year are: \n";
@months = ("January", "Febuary", "March", "April", "and so on...");
for ($i = 0; $i < 5; $i++) 
{
        print "$months[$i]\n";
}

On a side note, why even include a newline in the values of the array? This is more of a formatting option than it is part of the data... so imho, its best left for the print statement to handle.

On another side note, why even care how many elements the array has when printing it, if you are going to print them all anyway... do this:

#!/usr/bin/perl

print "The months of the year are: \n";
@months = ("January \n", "Febuary \n", "March \n", "April \n", "and so on... \n");

foreach $myMonth (@months)
{
        print "$myMonth\n";
}
yeh, thats what i was trying to do... im just learning the basic syntax at the moment...
__________________
Intel Pentium M 1.73Ghz -- Sony Vaio -- 1024MB Ram -- Ubuntu 8.04
AMD Athlon X2 4200+ -- Asus V3-M2V890 -- 2GB Kingston -- Vista Ultimate 32bit
Intel C2D E4400 -- 2048MB GeIL - Windows XP SP2

ASCII stupid question, get a stupid ANSI !
teishu is offline   Reply With Quote
Old Jun 17th, 2007, 9:47 AM   #8
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
Perl is a good language... it gets more cryptic as you go. Glad it worked out for ya.
__________________
http://jasonpowers.net

"There are a thousand hacking at the branches of evil to one who is striking at the root."
Infinite Recursion is offline   Reply With Quote
Old Jul 10th, 2007, 5:54 PM   #9
mackenga
Professional Programmer
 
Join Date: Mar 2005
Location: Glasgow, Scotland
Posts: 314
Rep Power: 4 mackenga is on a distinguished road
Yeah, good luck with Perl - it's actually quite a gentle learning curve and very rewarding, but there's an enormous amount of it to learn. I've been programming in Perl for years now and still feel like I've just scratched the surface - but that's not to say it hasn't already been incredibly useful to me. Nice choice. When you meet regular expressions, don't run for the hills: read slowly, understand them a bit at a time and they're amazing.
__________________
"I'm not a genius. Why do I have to suffer?"
mackenga is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Header file internal errors kruptof Coder's Corner Lounge 2 Jan 14th, 2007 1:12 PM
C# corruption!!! Kilo C++ 32 May 21st, 2006 8:44 PM
Masm rsnd Assembly 4 May 20th, 2006 9:05 PM
libraries matko C 1 Jan 22nd, 2006 2:12 PM
HELP please!!! hamacacolgante C 7 Nov 21st, 2005 5:36 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:33 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC