perl - Generating a unordered list hash from a array -


i trying use hashes generate unordered list can further use in jstree. array has generated array has been passed thru .

my @array = ( "new order","recurring order","previously cancelled order"); 

i want output

$data = {          "new order" => {                          "recurring order" =>{                                               cancelled order = 1                                              }                         }     }; 

i can

my $data{$array[0]}{$array[1]}{$array[2]} = 1 

but array can of n variables, becomes bit more complicated that. thinking of recursion, have been sitting here last hour trying figure out

this generate data structure have defined it. not sure why you'd want though.

my @input = ( "new order","recurring order","previously cancelled order");  $data = 1; $data = {$_ => $data} reverse @input;  use data::dump; dd $data; 

if you're wanting randomize array, use list::util;

use list::util qw(shuffle);  @neworder = shuffle @input; 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -