Solved

How can I parse the Perl output?

Posted on 2011-03-01
2
471 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Perl - Mawk 2 110
Reading fields from the text file. 4 106
How to strip .csv from file name 9 85
Migrate OTRS to newest version. 1 608
On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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…

759 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