vendredi 8 novembre 2019

Is it possible to match a partial word in perl when using an if statement (bash example included)

What's is the correct way to match a partial word in perl? For example I want to match "CentOS" so results like CentOS 6, CentOS 7 and CentOS 8 are matched.

I know how to do this in bash, like this:

if [[ "$os" == *"CentOS"* ]]; then
   echo $centosversion
else
   echo $differentos
fi

With the above bash example it will find any result with "CentOS" inside.

How do I achieve this with the perl code below?

if ($os eq "CentOS") {
    print "$centosversion";
} else {
    print "$differentos";
}

I tried using:

($os eq *"CentOS"*)

and

(($os eq *"CentOS"*))

But that seems to be incorrect?

Maybe I am doing it completely wrong, but I don't know much about perl. I am hoping someone can point me in the right direction.

Aucun commentaire:

Enregistrer un commentaire