Create JSON format from two strings in PERL -


i've 2 string follows in perl script.

$labels = "firstname|lastname|email";  $values = 'krishna|mohan|some@gmail.com'; 

now construct json fromat 2 srings. need split (explode) both strings base on | (pipe) symbol , construct json format follows

{"firstname":"krishna","lastname":"mohan","email":"krishna@gmail.com"} 

how can achieve this? ideas appreciated.

use split "explode" strings, build hash results. then, use json translate json:

#!/usr/bin/perl use warnings; use strict;  use json;  $labels = 'firstname|lastname|email'; $values = 'krishna|mohan|some@gmail.com'; # doesn't work double quotes!  %hash; @hash{ split /\|/, $labels } = split /\|/, $values;  print to_json(\%hash); 

Comments

Popular posts from this blog

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -