perl
Im trying to do something in perl but it doesn't seem to work..
im trying to run.. #!/usr/bin/perl @broswer = ("ns", "ie", "opera") foreach $broswer (@broswer) { print "$broswer\n" } but for some reason when i compile this i get.. systax error at test1.pl line 5, near "$browswer(" execution of test1.pl aborted due to comilation erros. can anyone help? |
ok, it's spelt "browser" first off, but change the variable name, you can't have the same name for two variables. you don't actually *need* a variable in the foreach:
Code:
@browser = ("netscape", "rubbish", "opera", "firebird"); |
i've tried that and it comes out to say..
syntax error at test1.pl line 6, near ") {" |
another questions.. if u dont use a name for the foreach loop.. will u still be able to create more than one foreach loop with out creating other complications?
|
??
|
could it be the compiler or is there something wrong with the codes?
|
i have perl v5.8.0
|
Up to your first example - you're simply missing an ; at the end of the assignment. ; may only be left off at the end of a block, but it's a good idea to put them there too, in case you add some commands. So the correct code reads (spellchecked :study: ):
Code:
#!/usr/bin/perl |
OOOH.. thank you SOO MUCH
|
To answer your other questions:
1) You can nest loops without naming then - you just can't refer to them should you want to end the loop or progress to the next item. 2) Perl is a scripting language nad is interpreted - not compiled. |
All times are GMT -5. The time now is 12:52 AM. |