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: Regular Expressions:
Convert from String to Hash

 



nkishorech
New User

May 5, 2009, 1:48 PM

Post #1 of 5 (3315 views)
Convert from String to Hash Can't Post

How to convert from String to Hash and loop it and print it.

$ssmb_request = (
'request' => {
'acctno'=> 'XXXXXXX',
'prdtypcd'=> 'XXXXXXXX',
'sectyp' => 'XXXX'
},
'status' => {
'action_code' => '0',
'response_code' => '1000',
'errorInfo' => 'everything working fine'
},
'response' => {
'avlcash' => '278806.38',
'secdettbl' =>
{
'accttyp' => 'cash',
'accttyp_code' => '1',
'secfmtflg' => '',
'secfmtflg_code' => '1'
} ,
},

);



Thankx in advance...


vikas.deep
User

May 6, 2009, 4:08 AM

Post #2 of 5 (3296 views)
Re: [nkishorech] Convert from String to Hash [In reply to] Can't Post

Dear friend
are you absolutely sure about what you have written "$ssmb_request" as you know is different from "%ssmb_request". A scalar $ssmb_request means a reference to something while % means a hash.
Also at the end check if it is " } ,},)" or "},})"
-For all my suggestions " I am sure someone else can do it in a better or elegant manner!"


1arryb
User

May 6, 2009, 12:01 PM

Post #3 of 5 (3285 views)
Re: [nkishorech] Convert from String to Hash [In reply to] Can't Post

Hi nkishorech,

You ask, "how to convert from String to Hash", but you already present the hash (reference) in your post: Where is this String you speak of?

Cheers,

Larry


vikas.deep
User

May 7, 2009, 1:35 AM

Post #4 of 5 (3267 views)
Re: [1arryb] Convert from String to Hash [In reply to] Can't Post

Hello Larry!
What a name!!
You have not said your surname
I guess You cannot be that LARRY!!

I think our friend[nkishorech] is working on a "Hash of Hashes".
There are three hashes to be called on the basis of three scalar references i.e "request","status","response". As for the hash called by "response" key, it is in itself a "Hash of Hash" where in the "secdettbl"is to be used to access the last hash.
If my understanding is correct then he must initialise ssmb_request as a hash i.e "my %ssmb_request", but if he is creating a anonymous hash and trying to store it's reference in "ssmb_request"
then of course "ssmb_request" has to be a scalar.
If my understanding is correct then

print $ssmb_request{'request'}->{'acctno'};
print $ssmb_request{'response'}->{'secdettbl'}->{'accttyp'};

can be used to access the individual strings in each case.
-For all my suggestions " I am sure someone else can do it in a better or elegant manner!"


vikas.deep
User

May 7, 2009, 1:36 AM

Post #5 of 5 (3266 views)
Re: [nkishorech] Convert from String to Hash [In reply to] Can't Post

I can't understand why this has to appear in the "REGEULAR EXPRESSION " section.
-For all my suggestions " I am sure someone else can do it in a better or elegant manner!"

 
 


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

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