in reply to Retrieving information from an executable program

The easiest way is to use backticks (or qx):

my $number = "2301"; my @output = `./retrive $number`; chomp @output; # remove line endings

The second step would be then to separate the keys and values into pairs. This is easiest done with split:

use Data::Dumper; my %data; for my $line (@output) { my ($key, $value) = split /:/, $line, 2; $data{ $key } = $value; }; print Dumper \%data;

Replies are listed 'Best First'.
Re^2: Retrieving information from an executable program
by kitifu (Initiate) on Jul 25, 2010 at 18:58 UTC
    Thanks for your quick reply. I will give it a try. Now suppose I want to set two parameters, say
    my $name=; my $status;
    Is there a way of assigning them inside a for loop, say using switch or if-else

    Sam

      No, there basically is no way to assign your variables that way. Well, you could store the names and references in a hash and then use that:

      my ($name, $status, $cid); my %vars = ( 'NAME' => \$name, 'CID' => \$cid, 'STATUS' => \$status, ); for my $line (@output) { my ($key, $val) = split /:/, $line, 2; if ($vars{ $key }) { ${ $vars{ $key } } = $val; } else { warn "Unknown key '$key', discarded"; }; };

      I'm not sure whether that's worth the trouble though.

        You are correct, it seems nothing is populated in @output variable
        CID:2301 NAME: Jane STATUS=OK $VAR1 = [];

        May you please advice how i can get @output filled by ./retrieve 2301
        Hello Corion
        May you please advice how i can assign this $vars{ $key } to my own variable, say my $newstatus=$status or something like that. I want to do some extra manipulation with the retrieved data?

        Sam