![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Programmer
Join Date: May 2006
Posts: 49
Rep Power: 0
![]() |
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 ! |
|
|
|
|
|
#2 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#3 |
|
Programming Guru
![]() ![]() ![]() |
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." |
|
|
|
|
|
#4 |
|
Programmer
Join Date: Nov 2005
Location: Spring Valley, CA
Posts: 52
Rep Power: 3
![]() |
Exactly what do you want the program to do?
__________________
if (u=an_asshole) then GOTO (hell) |
|
|
|
|
|
#5 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#6 |
|
Programming Guru
![]() ![]() ![]() |
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." |
|
|
|
|
|
#7 | |
|
Programmer
Join Date: May 2006
Posts: 49
Rep Power: 0
![]() |
Quote:
__________________
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 ! |
|
|
|
|
|
|
#8 |
|
Programming Guru
![]() ![]() ![]() |
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." |
|
|
|
|
|
#9 |
|
Professional Programmer
Join Date: Mar 2005
Location: Glasgow, Scotland
Posts: 314
Rep Power: 4
![]() |
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?" |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
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 |