CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Advanced:
How to change the scalar value to some other context.

 



santhosh_89
Novice

Jul 30, 2009, 8:47 PM

Post #1 of 2 (1374 views)
How to change the scalar value to some other context. Can't Post

 I want to change the scalar value to some other context(array/hash references). Actually my input will be as following.
Scalar will be a Input : '[1,'test',[{2=>3,3=>'test_56'},2,3,3]]'
If the scalar contains [],{}.I want change it to array-reference,hash-ref. The output should be as following if i print by using dumper module.
Dumper output :

$VAR1 = [ 1, 'test', [ { '3' => 'test_56', '2' => 3 }, [ 2 ], [ 3 ], 3 ] ];


1arryb
User

Aug 3, 2009, 7:55 AM

Post #2 of 2 (1360 views)
Re: [santhosh_89] How to change the scalar value to some other context. [In reply to] Can't Post

Hi santosh,

Yes, you could build a grammar and parser to analyze the string, but this can get tedious if your grammar is at all complicated. Let's step back and look at your whole problem a minute. It looks to me like what you are trying to do is read back into perl data structures that have been previously serialized for writing to a pipe or a file. If you have control over the sending program, why not use one of the Perl serialization packages to write out the data in the first place? Then you can use the same package to reconstitute it at the other end.

Cheers,

Larry

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives