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: Need a Custom or Prewritten Perl Program?: I need a program that...:
Create a hash from a string

 



hujirong
Novice

Jun 25, 2015, 8:47 AM

Post #1 of 2 (9584 views)
Create a hash from a string Can't Post

# Hash my %weekly_temperature = ('monday', 65, 'tuesday', 68, 'wednesday', 71, 'thursday', 53, 'friday', 60);

Using the above sample, I now have a string can be formatted like this:
"'monday', 65, 'tuesday', 68, 'wednesday', 71, 'thursday', 53, 'friday', 60". How can I create a hashfrom this string? or I can format the string in whatever way it takes. It's transferred from another system.

Thanks
Jirong


(This post was edited by hujirong on Jun 25, 2015, 8:48 AM)


Laurent_R
Veteran / Moderator

Jun 27, 2015, 4:51 AM

Post #2 of 2 (9566 views)
Re: [hujirong] Create a hash from a string [In reply to] Can't Post

Perhaps something like this:


Code
my $string = "'monday', 65, 'tuesday', 68, 'wednesday', 71, 'thursday', 53, 'friday', 60"; 
my %weekly_temp = split /[,\s]+/, $string;


 
 


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

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