Gossamer Forum
Home : General : Perl Programming :

else / elsif ...

Quote Reply
else / elsif ...
Hi

I tryed to include the elsif and else command but the complier always tell me that I have a syntax error near my elsif (in my first script list bellow) and near the else in the second one ...

#1
#!/usr/bin/perl -w
#
# trying to include the if else into my code !

my @list = ('A','B')

# I puted the folloing command because I want the complier to
# execute the print command...

if ($list[0] eq "A"); {
print "$list[0]\n";
}
elsif ($list[1] eq "B"); {
print "$list[1]\n";
}

and #2

#!/usr/bin/perl -w
#
#try if & else command

my @list = ('A','B','C')

if ( $list[0] eq "A" ) {
print "$list[0]\n\n";
}
else {
print "@list\n\n";
}

the complier aslo 'complaint' angainst my last curly brace ... please help me cause I'm completly out of ressource ...
Quote Reply
Re: else / elsif ... In reply to
You have extra semicolons.

Code:
#!/usr/bin/perl -w
#
# trying to include the if else into my code !

my @list = ('A','B')

# I puted the folloing command because I want the complier to
# execute the print command...

if ($list[0] eq "A"); {
print "$list[0]\n";
}
elsif ($list[1] eq "B"); {
print "$list[1]\n";
}

and #2

#!/usr/bin/perl -w
#
#try if & else command

my @list = ('A','B','C')

if ( $list[0] eq "A" ) {
print "$list[0]\n\n";
}
else {
print "@list\n\n";
}
Should be..
Code:
#!/usr/bin/perl -w
#
# trying to include the if else into my code !

my @list = ('A','B')

# I puted the folloing command because I want the complier to
# execute the print command...

if ($list[0] eq "A") {
print "$list[0]\n";
}
elsif ($list[1] eq "B") {
print "$list[1]\n";
}

and #2

#!/usr/bin/perl -w
#
#try if & else command

my @list = ('A','B','C')

if ( $list[0] eq "A" ) {
print "$list[0]\n\n";
}
else {
print "@list\n\n";
}


------------------
Chris
Quote Reply
Re: else / elsif ... In reply to
Hi Chris

If I use your codes the complier call a syntax error on line 9 near "}"

#!/usr/bin/perl -w
#try if & else command

my @list = ('A','B','C')

if ( $list[0] eq "A" ) {
print "$list[0]\n\n";
}
else {
print "@list\n\n";
}
---------------------------------------------
and I have the same result for the other code...

Quote Reply
Re: else / elsif ... In reply to
there is no semicolon after
my @list = ('A','B','C')
should be
my @list = ('A','B','C');


------------------
LookHard Search
lookhard.hypermart.net
Lavon Russell