perl if elsif statements

I have having problems with an IF statement in my perl script:

if ($model eq "N\\A") {}
  elsif ($kernel =~ m/xen/) {
    $model = ("Virtual Machine\n")};

What i am trying to accomplish is if the model is set to "N\A" and the kernel variable has xen somewhere in it i would like to change the variable to "virtual machine". Otherwise just leave it alone. The rest of my script works great this is the last part. The code above does not do what i want it to, it turns every model into a virtual machine regardless if it is set or not.

Thanks,

Sean

In your code you're saying if model equals N\A then do nothing or if kernel has xen in it change model to Virtual Machine.

You'll want something similar to the following I think:

if (($model eq 'N\A') && ($kernel =~ m/xen/)) {
    $model = "Virtual Machine\n";
}

Assuming "the variable" means "model" -

$
$
$ cat insania.pl
#!/usr/bin/perl -w
$model  = $ARGV[0];
$kernel = $ARGV[1];
print "Before if...\n";
print "model  = $model\n";
print "kernel = $kernel\n";
# if the model is set to "N\A" and the kernel variable
# has xen somewhere in it i would like to change the
# variable to "virtual machine".
# Otherwise just leave it alone.
if ($model eq "N\\A" and $kernel =~ m/xen/) {
    $model = "Virtual Machine";
}
print "\nAfter if...\n";
print "model  = $model\n";
print "kernel = $kernel\n";
$
$ # Case 1 : model is "N\A" and kernel has "xen" in it
$
$ perl insania.pl "N\A" abcxenabc
Before if...
model  = N\A
kernel = abcxenabc
 
After if...
model  = Virtual Machine
kernel = abcxenabc
$
$
$ # Case 2 : model is "N\A" and kernel does not have "xen" in it
$
$ perl insania.pl "N\A" abcyenabc
Before if...
model  = N\A
kernel = abcyenabc
 
After if...
model  = N\A
kernel = abcyenabc
$
$
$ # Case 3 : model is not "N\A" and kernel has "xen" in it
$
$ perl insania.pl "M\A" abcxenabc
Before if...
model  = M\A
kernel = abcxenabc
 
After if...
model  = M\A
kernel = abcxenabc
$
$
$ # Case 4 : model is not "N\A" and kernel does not have "xen" in it
$
$ perl insania.pl "M\A" abcyenabc
Before if...
model  = M\A
kernel = abcyenabc
 
After if...
model  = M\A
kernel = abcyenabc
$
$

HTH,
tyler_durden

Sweet, the following code worked:

  if (($model eq "N\\A\n") && ($kernel =~ m/xen/)) {
    $model = "Virtual Machine\n";
  }

Had to add the \n on the "N\\A" variable because that is how it is coded earlier in the script, i failed to mention that.

Thanks again for both of your help, if they assigned points like the ITRC, i would give you both 10's.

Sean