But i want to download only if the file version is latest than the same file I have.
The file name is CTP-LATEST-5.3.0.37.iso
I need to check the string "37" in the file name.
So if the number 37 is greater than the version Im already having then only I download.
Once I download the file I want to store the string "37" is a file so that I can read it next time when I run the perl code to check for version
Here is my code Im trying with
#!/usr/bin/perl
use LWP::Simple;
#my $version =37;//this whole line is commented
Open file version.txt and get the version number(say 37)and store it in $version
$pageURL="http://www.google.comisos/psfsS5.3/LATIMGODCVP/";
$simplePage=get($pageURL);
Now $simplePage has the substring "CTP-LATEST-5.3.0.(some_version_number).iso"
I need to get that "some_version_number". HOW ?
if(some_version_numner > $version)
{
#-- fetch the zip and save it as perlhowto.zip
my $status = getstore("http://www.google.com/isos/psfsS5.3/LATIMGODCVP/CVP-LATEST-5.3.0."$version".iso", "CTP-Latest5.3.0.$version.iso");
if ( is_success($status) )
{
print "file downloaded correctly\n";
Store the "some_version_number in file version.txt (for next time use)
}
else
{
print "error downloading file: $status\n";
}
}
Please not that In the website there are other files with .iso extension , But I need the only the file with "CTP-LATEST-5.3.0." prefix
I hope everything is clear in code. The version.txt has only 1 string stored that is any number (say 37 or 45 or 89 etc )
Can someone help me on how to do the rest of the code ?
my $oldVersion="38";##Version.txt File Version
my $simplePage ="CTP-LATEST-5.3.0.37.iso";
my $str = (split("CTP-LATEST-5.3.0.",$simplePage ))[1];
my $version = substr("$str",0,2);
if($version > $oldVersion )
{
print "NewVersion\n";
####Proceed your further code
}
else
{
print "old Version\n";
####Proceed your further code
}
#!/usr/bin/perl
use LWP::Simple;
my $oldversion =36;
$pageURL="http://www.google.com/isos/preFCS5.3/LATESTGOODCVP/";
my $simplePage=get($pageURL);
#my $simplePage ="CTP-LATEST-5.3.0.37.iso";
my $str = (split("CTP-LATEST-5.3.0.",$simplePage ))[1];
my $version = substr("$str",0,2);
if($version =! $oldVersion )
{
print "$version";
##-- fetch the zip and save it as perlhowto.zip
my $status = getstore("http://www.google.com/isos/preFCS5.3/LATESTGOODCVP/CTP-LATEST-5.3.0.$version.iso", "CVP-LATEST-5.3.0.$version.iso");
}
else
{
print("Currently new version\n");
}
but its printing $version as 1 , which is not the correct value. The correct value is 37 which its not able to print.
here is the content of my page. You can see the filename marked in red. I want to extract only that file name and then from that filename I want to extract the number "37" or anyother number that is there is that place and then compare with already stored number.
my $newPage = "$simplePage";
my $str = (split("href=\"CVP-LATEST-5.3.0.",$simplePage ))[1];
my $version = substr("$str",0,2);
print "Version: <$version>\n";
I think variable $simplePage doesn't have string data so need to convert to string. Try the above code.i assume href=\"CVP-LATEST-5.3.0. wont change in future.
#!/usr/bin/perl
use LWP::Simple;
my $oldversion =36;
$pageURL="http://www.google.com/isos/preFCS5.3/LATESTGOODCVP/";
my $simplePage=get($pageURL);
my $newPage = "$simplePage";
my $str = (split("href=\"CVP-LATEST-5.3.0.",$simplePage ))[1]; //here its again $simplePage or $newPage ?
my $version = substr("$str",0,2);
print $version; // This displays 37 which is correct
if($version =! $oldVersion )
{
print $version; // Here it displays 1 which is wrong and so the file dont download.
##-- fetch the zip and save it as perlhowto.zip
my $status = getstore("http://www.google.com/isos/preFCS5.3/LATESTGOODCVP/CVP-LATEST-5.3.0.$version.iso", "CVP-LATEST-5.3.0.$version.iso");
}
else
{
print("Currently new version\n");
}
Should I convert the value to integer or something ?
Yes I get it, but whether to use != or ne . Becuase $version is in the form of string and $oldversion is integer.
So eventhough both are equal the IF condition is getting TRUE and the file is downloading.
any idea how to convert to integers ? i tried int() and sprintf both did not work .