Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String found where operator expected

Status
Not open for further replies.

NashTrump

Technical User
Jul 23, 2005
38
GB
Hi Guys,

Im trying to build a small test function.
Im (trying to) passing a variable to the function, then have that function check the string to see if it matches anything. Once the check has finished, i want it to pass a variable back.

Heres my code:

sub Check{
my ($CheckDetail) = @_;

switch ($CheckDetail){
case "ThisisCorrect" {
$Useit = "Yes"}
case "ThisisWrong" {
$Useit = "No"}
}

}

I have saved this as a module and are 'using' it in another program.

I am calling this aboe function by using this code:

my $doweUse = Check($Checktype)

However i am getting these errors:

String found where operator expected at /perl/site/lib//findlinks.pm line 68, near "case "case1""
(Do you need to predeclare case?)
String found where operator expected at /perl/site/lib//findlinks.pm line 70, near "case "case2""
(Do you need to predeclare case?)
syntax error at /perl/site/lib//findlinks.pm line 67, near "){"
syntax error at /perl/site/lib//findlinks.pm line 70, near "case "case2""
Compilation failed in require at C:\Documents and Settings\Lee Nash\Desktop\GAF Projects\Betting\Perl\script2.pl line 8.

I'm struggling to find what it means and what i have done wrong.

All help would be appreciated!! :)

Thank you in advance!

Nash
 
Do you have the Switch.pm module installed and are you calling it in your script?

Code:
use Switch;


my $CheckDetail = "ThisisCorrect";

      switch ($CheckDetail){
        case "ThisisCorrect" {
            $Useit = "Yes"}
        case "ThisisWrong" {
            $Useit = "No"}
    }
print $Useit;

You will get errors if you do not have "use Switch" because the switch statement is not native to perl.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top