Solved

How can I parse the Perl output?

Posted on 2011-03-01
2
455 Views
Last Modified: 2012-05-11
I have a followup question on this issue:

In my PERL code the following line :

print Dumper $ssc->{'myStates'};

Open in new window


returns:
      
$VAR1 = [
          bless( {
                   'priority' => 'Unset',
                   'owner' => 'Unassigned',
                   'required' => 'ABCD',
                   'status' => 'Completed',
                 }, 'gState' )
        ];

Open in new window



How can I extract the 'status' from this output in Perl?

Thanks,
      
0
Comment
Question by:Tolgar
  • 2
2 Comments
 
LVL 26

Accepted Solution

by:
wilcoxon earned 500 total points
ID: 35012851
print $ssc->{myStates}[0]{status};

If you have more than one instance of gState, you'll need to loop over the items (or something similar) to get all of the status.
0
 
LVL 26

Expert Comment

by:wilcoxon
ID: 35012875
To further explain what you are looking at...

$VAR1 in the output corresponds to $ssc->{myStates} since that's what you called Dumper with.
The [] around it indicates that it is an array reference (needing [0] to get the first item).
The bless({},'gState') says that it is a blessed hash which should be irrelevant for extracting data so {state} will get us the value of state.

So we end up with $ssc->{myStates}[0]{status}.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question