1825781 Members
2077 Online
109687 Solutions
New Discussion

Perl help

 
SOLVED
Go to solution
Allanm
Super Advisor

Perl help

Hi ALL,

I have a piece of perl code which makes a http call to a URL and in return gets a bunch of data related to application version.

There is a string which gets returned from the http call -

"BuildVersion" = "/tmp/maven-build-nHNMkWwtlz/applicationABC-20101029-105300-31abb9224ff046fe84f3914293a8cae0";

I have made a piece of code which returns this information for me but I need it to return just "maven-build-.....cae0" and not /tmp.

Here is the snippet of the code -

my $BV = $httpmethod->objectForKey("BuildVersion");
if ($BV && $$BV) {
if ($version) {
$version .= ", ";
}
$BV = $BV->UTF8String();
$version .= "BV=$BV";

I want the output to return -

BuildVersion = "maven...."

Thanks,
Allan.
10 REPLIES 10
Horia Chirculescu
Honored Contributor

Re: Perl help

Hello Allan,

Just add:

print "BuildVersion=";
$BV =~ m/^\/(.*)\/(.*)\/(.*)/;

print $2;
print "\/";
print $3;

$OUT = "BuildVersion=".$2."\/".$3;

in $OUT var. you would have the string you are looking for.

Best regards
Horia.
Best regards from Romania,
Horia.
James R. Ferguson
Acclaimed Contributor

Re: Perl help

Hi Allan:

# BV='"BuildVersion" = "/tmp/maven-build-nHNMkWwtlz/applicationABC-20101029-105300-31abb9224ff046fe84f3914293a8cae0"'

# echo ${X} | perl -nle 'm{(".*[^"]\s*=\s*")/.*?/(.*)} and print "$1$2"'
"BuildVersion" = "maven-build-nHNMkWwtlz/applicationABC-20101029-105300-31abb9224ff046fe84f3914293a8cae0"

Regards!

...JRF...
Horia Chirculescu
Honored Contributor

Re: Perl help

@James:

># echo ${X} | ...

This is a shell code. Please provide a perl code, as Allan asked from the first time.

Best regards
Horia.
Best regards from Romania,
Horia.
James R. Ferguson
Acclaimed Contributor

Re: Perl help

@ Horia:

> @James: ># echo ${X} | ...This is a shell code. Please provide a perl code, as Allan asked from the first time.

I'll leave that to Allan to decide what helps him or doesn't. I don't need to be told what to post and what not to post.

If you look more closely at what I posted, the only shell code is the 'echo' into a pipe for Perl to read from its STDIN.

...JRF...

Horia Chirculescu
Honored Contributor

Re: Perl help

>the only shell code is the 'echo' into a pipe for Perl to read from its STDIN.

Of course, this is it. This is a shell code.

My point was that you assumed too much. Maybe Allan really needed a plain perl code. Maybe he does not know at all how to write a script in shell code.

If someone is asking for help, he expects to receive what he asked for.

Best regards,
Horia.

Best regards from Romania,
Horia.
James R. Ferguson
Acclaimed Contributor
Solution

Re: Perl help

Hi (again) Allan:

See if this addresses your need more directly:

#!/usr/bin/perl
use strict;
use warnings;
my $BV=q("BuildVersion" = "/tmp/maven-build-nHNMkWwtlz/applicationABC-20101029-105300-31abb9224ff046fe84f3914293a8cae0");
print "BEFORE: $BV\n";
$BV =~ s{(".*[^"]\s*=\s*")/.*?/(.*)}{$1$2};
print "AFTER : $BV\n";
1;

Regards!

...JRF...
Horia Chirculescu
Honored Contributor

Re: Perl help

Thank you for understanding, James.

Have a nice day.
Horia.
Best regards from Romania,
Horia.
Allanm
Super Advisor

Re: Perl help

Thanks JRF!

I am able get the BV but only thing is that I want /tmp/ removed...

Regards,
Allan.
Horia Chirculescu
Honored Contributor

Re: Perl help

>I want /tmp/ removed...

Have you tried my piece of script?

Best regards
Horia.
Best regards from Romania,
Horia.
Horia Chirculescu
Honored Contributor

Re: Perl help

.. just to be clear: The piece of code JRF provided should work as expected (like mine, /tmp/ should be removed...).

Best regards,
Horia.
Best regards from Romania,
Horia.