0

I have a string of formatted data that I would like to push to an array, but my Perl skills are lacking.

The string is:

'ShoreTelCallStateInfo' => [
    {
       'callStateDetail' => 'Active',
       'callState' => 'OnHold',
       'callInfo' => {
             'callerIDName' => 'Joel Lewis',                                          
             'callID' => '66766',
             'lineID' => '3947',
             'connectedIDName' => 'VM-Forward',
             'calledID' => '2105',
             'callerID' => '1955',
             'isInbound' => 'false',
             'calledIDName' => 'VM-Forward',
             'callReason' => 'None',
             'callUniqueID' => '2488927099',
             'connectedID' => '2105',
             'isExternal' => 'false',
             'callGUID' => '{00030000-67CA-537E-3FD8-0010492377D9}'
        }
    },
    {
        'callStateDetail' => 'Active',
        'callState' => 'Connected',
        'callInfo' => {
             'callerIDName' => 'Lewis Joel',
             'callID' => '73202',
             'lineID' => '3947',
             'connectedIDName' => 'Lewis Joel',
             'calledID' => '1955',
             'callerID' => '+1385#######',
             'isInbound' => 'true',
             'calledIDName' => 'Joel Lewis',
             'callReason' => 'None',
             'callUniqueID' => '2193468845',
             'connectedID' => '+1385#######',
             'isExternal' => 'true',
             'callGUID' => '{00030000-6809-537E-3FD8-0010492377D9}'
        }
     }
  ]
};

I have tried to simply create the array and assign the string, but this is not working:

my @magicarray = $string;

Is there a quick way to initialize this array with the formatted data?

11
  • That's not a string. If you add a { to the beginning, it would be an anonymous hash. Maybe you meant a "scalar"? Commented Mar 31, 2015 at 15:43
  • It doesn't look like a string to me Commented Mar 31, 2015 at 15:43
  • It is stored as a string, I want it to be converted. Commented Mar 31, 2015 at 15:45
  • But it might be related to a SOAP object: stackoverflow.com/questions/29370434/… Commented Mar 31, 2015 at 15:45
  • 2
    @JoelLewis: You're asking the wrong question again! I tried to explain that it is almost never useful to print the Data::Dumper representation of an object. Most of the information is in the methods that the object provides. Please explain what you're trying to do using the SOAP API, and give example sources if possible so that we can test solutions ourselves Commented Mar 31, 2015 at 16:04

2 Answers 2

2

Just prepend the missing left curly bracket and call eval. Before doing so, make sure the string doesn't contain any commands (imagine what system 'rm -rf /' would cause).

my $string = q( 'ShoreTelCallStateInfo' => [
                                     {
                                       'callStateDetail' => 'Active',
# ETC...
                                     }
                                   ]
        };);
my @array = eval "{$string";
Sign up to request clarification or add additional context in comments.

Comments

1

It is difficult to help without understanding the data better. But I suggest this

my $state_info = $result->{ShoreTelCallStateInfo};

for my $state_item ( @$state_info ) {
  say $state_item->{callInfo}{callerID};
}

when worked with your sample data gives

1955
+1385#######

Is that close to what you want?

3 Comments

This is exactly what I'm looking for, however for some reason $state info is blank. Resulting in no loop. I can't figure out why state info is not getting the data. Also I think you posted this to the wrong question of mine.
I apologise for posting against the wrong question, but your new post was very similar to this one. Please pull back a long way and explain the nature of the data source as well as why you are using Data::Dumper to serialise, and then eval to deserialise. You motives may be valid but it is impossible to tell from what you have written. I realise that many things seem obvious to you, but are part of the system with which you are working. We cannot knowany of that, so please imagine that we are from Jupiter and know programming but nothing of your system
Thank you for being patient and trying to help. I have updated my origional question: stackoverflow.com/questions/29370434/… I hope it is a bit easier to understand what is going on.

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.