0

I dumped out a Perl variable called $prefs and got this:

$VAR1 = bless( {
                 'USERID' => 1286,
                 'PREFS' => {
                              '1' => {
                                       'VALUE' => 1,
                                       'OTHERS_POST' => 1,
                                       'CLIENTS_POST' => 1,
                                       'ASSIGNED_TASKS' => 1
                                     }
                            },
                 'dbh' => bless( {
                                   '_sth' => bless( {}, 'DBI::st' ),
                                   '_dbh' => bless( {}, 'DBI::db' )
                                 }, 'Taskman::DB' )
               }, 'USystems::UserPrefs' );

I'm pretty new to Perl, and I was wondering if someone can break down on whether or not it is possible to access specific data within this variable.

Like if I wanted to do an if statement such as

if (OTHERS_POST == 1) {
      // code }

How would I get to the actual OTHERS_POST inside the $prefs variable

2
  • 4
    The USystems::UserPrefs class is not one that I can find on CPAN, but I'd recommend trying the command perldoc USystems::UserPrefs to find any documentation on the class. Alternatively you can follow Gingi's advice, do an end-run around the class and hope that it's implementation never ever changes... Commented Jul 1, 2014 at 17:28
  • You would get a proper answer if you showed the USystems/UserPrefs.pm module file Commented Jul 1, 2014 at 19:05

1 Answer 1

1
$prefs->{PREFS}->{1}->{OTHERS_POST};
Sign up to request clarification or add additional context in comments.

3 Comments

note that this is bypassing the class's encapsulation; $prefs is a USystems::UserPrefs object; it would be preferable (pun intended) to use whatever method(s) that class provides
This answer is probably wrong, even though it will work, because USystems::UserPrefs may have an accessor method which exposes this data. (But there's no way for us to know, since it seems to be a proprietary module in your system.)
Yes, if a reference is a blessed object, a proper method should expose it in a more portable way. But this is not a CPAN question :) and for beginning Perl it shows how to access nested structures (at least nested hashes).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.