I am trying to put a condition to check whether two strings are equal or not? By using eq
I am checking whether the Scalar variable is having the string 'png' but it does not seem to be working as it should be. When I am printing the scalar on the terminal it shows that it contains 'png'. The default IF statement is: if($fileEnding eq "png")
then I manipulated by using single quotes enclosing the png: if($fileEnding eq 'png')
but it didn't work that way either. I also however, did something like my $png = "png"
initializing a scalar with 'png' and then checking the scalar by putting it in IF statement if($fileEnding eq $png)
. Nothing Happened!
Below is my code:
$fileEnding = `basename -s $ending`;
if($fileName !~ /(.*)?\.(.*)/) #This is just for checking if a file has an extension.
{
print $fileEnding;
if($fileEnding eq "png")
{
print "Yes it's a Png File\n";
}
if($fileEnding eq "gif")
{
print "Yes it's a Gif File\n";
}
}
When I use ne
instead of eq
, the code executes, which is extremely weird and repetitive. Please see the attached image:
The $fileEnding
scalar does contain both 'png' and 'gif' which you can see on terminal.
I am not able to figure out where I'm going off the rails.? Some help will be highly appreciated.
Aucun commentaire:
Enregistrer un commentaire