简体   繁体   中英

new to Perl - having trouble with a floating point comparison

I'm new to Perl, writing a simple script that checks to see if the installed version of VMware Fusion is greater than 8.4. I'm getting this error:

syntax error at ./test.pl line 8, near ");"

This is the script:

 @vmVersion = `defaults read /Applications/VMware\ Fusion.app/Contents/Info CFBundleShortVersionString`;

 @vmMinimum = 8.4;

if($vmVersion > $vmMinimum);

then print "compliant";

 else print "update required";

 fi

That code you have isn't Perl. Here's what might look more like Perl:

my $vmVersion = `defaults read '/Applications/VMware Fusion.app/Contents/Info' CFBundleShortVersionString`;
if ($vmVersion > 8.4) {
    print "compliant";
} else {
    print "update required";
}

Note two things:

  1. Version numbers are not floating point numbers. You should really use a semantic version library, such as SemVer , for version comparison.
  2. Your messages should probably include newline characters ( \\n ). Without those, when a user runs your program, their prompt will print in a funny location afterwards. :-)

I've never seen

if($vmVersion > $vmMinimum);
...
fi

In perl before, replace with block braces.

if($vmVersion > $vmMinimum) {
...
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM