Can anybody help to perform the below operation in Perl?
- Read a set of numbers or chars from a file (ex. 2021.2.3.0 / 2.8.1 / 2021.3.1_alpha ).
- Compare it with number 2.4.0. (always the same number) if greater or smaller.
- Ex: (2.4.0 < 2021.2.3.0) --> this is false. so do nothing.
- if (2.4.0 > 2.3.0) --> True - So do some operation.
- For 3 digit numbers with dot separated we can do this. (actually we are doing).
- But how to compare for digits and alpha numeric which has more that 3 digits.
Here i need to always compare with 2.4.0. Can any one guide me on how to do this in Perl?
My existing code is below:
use strict;
use warnings;
my $path_ice = $ARGV[0];
my $filename = ($#ARGV == 0) ? $ARGV[0]."\\medc17_tools.ini" : $ARGV[1];
my $flag = 0;
my $buld_ver = "";
my @buld_very = "";
my $status = 55;
if (open(my $fh, '<:encoding(UTF-8)', $filename))
{
while (my $line = <$fh>)
{
chomp $line;
if($line=~m/^PRJ_BUILD_NAME=mdgb/) {$flag = 1;}
if($line=~m/^PRJ_BUILD_VERSION=/)
{
@buld_very = split('=',$line);
$buld_ver = substr($buld_very[1], 0, 5);
$buld_ver =~ tr/.//d;
if ($buld_ver < 240 ) {$status = 44;}
last;
}
}
}
else {
warn "Could not open file '$filename' $!";
}
if ($flag == 1)
{
exit(1);
}
else
{
exit(0);
}
Here we are converting dot separated to whole number and comparing. It works well for 3 digit values. But don't know how to handle for alphanumeric and >3 digit dot separated numbers.
Any help?