Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How can I parse the Perl output?

Posted on 2011-03-01
2
Medium Priority
?
489 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 27

Accepted Solution

by:
wilcoxon earned 2000 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 27

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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 …
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…
Six Sigma Control Plans

879 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