1748244 Members
3953 Online
108760 Solutions
New Discussion

Re: Perl Help

 
SOLVED
Go to solution
James R. Ferguson
Acclaimed Contributor

Re: Perl Help

Hi Allan:

# cat ./fetch
#!/usr/bin/perl
use strict;
use warnings;
my $uri = q(cgi-bin/jboss/apps.joa/health?method=checkurl);
my $res;
my @names;
while ( $res = ) {
push @names, $res =~ m{^".+apps.*"\s*=\s*"(.+:\d+/)};
}
for (@names) {
my $wget = $_ . $uri;
print "$wget\n";
}
__DATA__
{
"_exp" = "81652254";
"apps" = {
"AcctInfoapps" = "http://spaceqa3-svc.corp.zaphida.com:7322/cgi-bin/jboss/OrderManagementapps-MEA.joa/accountInfo";
"StatContentapps" = "http://egq3-wsf-5001.corp.zaphida.com:8531/service/staticcontent";
"ContappsB2B" = "http://spaceqa3-svc.corp.zaphida.com:9203/jboss/apps.joa/content";
"CommQandAStatisticapps" = "http://spaceqa3-svc.corp.zaphida.com:8546/service/qastats";
"SerialNberapps" = "http://spaceqa3-svc.corp.zaphida.com:8341/jboss/apps.joa/serial";
};
}

# ./fetch
http://spaceqa3-svc.corp.zaphida.com:7322/cgi-bin/jboss/apps.joa/health?method=checkurl
http://egq3-wsf-5001.corp.zaphida.com:8531/cgi-bin/jboss/apps.joa/health?method=checkurl
http://spaceqa3-svc.corp.zaphida.com:9203/cgi-bin/jboss/apps.joa/health?method=checkurl
http://spaceqa3-svc.corp.zaphida.com:8546/cgi-bin/jboss/apps.joa/health?method=checkurl
http://spaceqa3-svc.corp.zaphida.com:8341/cgi-bin/jboss/apps.joa/health?method=checkurl

...the regular expression matches the URL that begins a line (^) with a double quote; followed by one or more characters (.+); the sequence "apps"; zero or more characters (.*); a double quote; optional whitespace (\s*); an equal sign; some more optional whitespace; and a double quote. The next sequence in parentheses is captured in a variable named $1. We look for one or more characters; a colon; one or more digits; and a forward slash. This is the URL we will stuff into our array.

m{^".+apps.*"\s*=\s*"(.+:\d+/)};

Having loaded an array with the URLs we want, we can loop through that array and concatenate (that's the dot operator) the URI you want to form a new variable to pass to a wget().

If you like, you could extract the URL and concatenate before stuffing your array variable, or simply extract and concatenate into a variable that you immediately use with wget().

Regards!

...JRF...