开发者

Searching a unknown substring in a string using perl

Im trying to download a file from a website. But i want to download only if the file version is latest than the same file I have.

The file name is CTP-Latest5.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";
 }

}

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 ?


Regex should do the work.


If some_version_number is only digits, you can do:

if ($simplePage =~ /CTP-LATEST-5\.3\.0\.\((\d*)\)\.iso/)
{
    $some_version_number = $1;
}

If not only digits, but there are no other parentheses in simplePage, you can do:

if ($simplePage =~ /CTP-LATEST-5\.3\.0\.\((.*)\)\.iso/)
{
    $some_version_number = $1;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜