Yes, use 'eq' instead of '=='. The former does a string comparison, whilst the second does a numerical comparison, which isn't what you want here.
Two other points worth noting:
Firstly, in your function you're writing
return (true);. What this will actually do is return the string 'true', and so whilst it will evaluate to true in a boolean context - it means that
return (false); will also return true.
Perl doesn't have any boolean 'true' or 'false'. Instead just use a '1' and a '0' to get the same effect - it's less typing anyway.
Also you're forgetting to
chomp() $get. This means getting rid of the newline (if any) on the end of the variable, which will cause all of your equality tests in the isOperator() function to return false, because "+\n" is not the same as "+". (The \n stands for newline).
So your script should probably look something like this:
Code:
sub isOperator
{
($who) = @_;
if($who eq "+" || $who eq "-" || $who eq "*" || $who eq "/" || $who eq "^")
{
return 1;
}
else
{
# because nothing is being returned, this will evaluate to false
return;
}
}
$get = <STDIN>;
chomp $get;
if(isOperator($get))
{
print $get;
}
Hope that helps a bit.