Solved

How can I parse the Perl output?

Posted on 2011-03-01
2
435 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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Perl Script to append xml file 32 184
hard perl script 16 144
Insert Text into odbc.ini file 15 62
Perl script to delete older files 6 42
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…
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now