in reply to Command Parsing

You can use a 'while' loop to read your output file you have generated, from the CLI, then use a regex to pick out the values you are want like this:

use warnings; use strict; while (<>) { chomp; if (m/(.+?)\s+?=\s+?(\d+?).?$/) { print $1, " : ", $2, $/; } }

Or you could decide to pipe in your command in your script, then *work on* each of the line as you want like this: Just run your script i.e >my_script.pl

#!/usr/bin/perl use warnings; use strict; open my $fh,'-|', q[xgridstatus -h localhost -A] or die "can open this + file: $!"; while (<$fh>) { chomp; if (m/(.+?)\s+?=\s+?(\d+?).?$/) { print $1, " : ", $2, $/; } } close $fh or die "can't close this file:$!";

Hope it helps

Replies are listed 'Best First'.
Re^2: Command Parsing
by jcstech (Initiate) on Apr 25, 2012 at 13:50 UTC
    This is definitely what I am trying to do and the script works great. However would it be possible to only extract the numbers returned and assign each one to a variable so I can format them in the order I need. Example
    print "AGC:$1 APC:$2 OAC:$3" and so on.
    I really do appreciate the help on this, I'm trying to learn perl scripting in my spare time and I'm sure my question shows as a newbie. Thanks

      Why not? To pick out the numbers, you could do this:

      my @arr_data; while (<>) { chomp; if (m/.+?(\d+?).?$/s) { push @arr_data, $1; } } my @assign_var = qw[AGC APC OAC CGA GAC CPA ACP CAO ACO BGH PHY ENG MA +T]; # assumed parameters my %hash_val; @hash_val{@assign_var} = @arr_data; print $_, ":", $hash_val{$_}, $/ foreach sort keys %hash_val;

      Please note that the assumed parameter could also be gotten from within the while loop, it really depend on what you have to work with.
      Hopes this helps