From c3ff29f9ad46d0cea6c94b44bcdb253d0f59f862 Mon Sep 17 00:00:00 2001 From: Angelo Naselli Date: Sun, 22 Jun 2014 23:44:29 +0200 Subject: Added parameter "separator" to know which is the tree item separator into string --- lib/AdminPanel/Shared.pm | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/AdminPanel/Shared.pm b/lib/AdminPanel/Shared.pm index dff57a7..a1df114 100644 --- a/lib/AdminPanel/Shared.pm +++ b/lib/AdminPanel/Shared.pm @@ -194,8 +194,10 @@ sub md5sum { =head3 INPUT -paths: ARRAY of string containing path like strings - (/ is the separator) +$param : HASH ref containing + paths => ARRAY of string containing path like strings + separator => item separator inside a single path + (default separator is /) =head3 OUTPUT @@ -211,11 +213,20 @@ This function return a tree representation of the given array. #============================================================= sub pathList2hash { + my ($param) = @_; + + die "array of path is missing" if ! exists $param->{paths}; + my $separator = '/'; + $separator = $param->{separator} if $param->{separator}; + if ($separator eq "/" || $separator eq "|") { + $separator = '\\' . $separator; + } + my %tree; - for (@_) + for (@{$param->{paths}}) { my $last = \\%tree; - $last = \$$last->{$_} for split /\//; + $last = \$$last->{$_} for split /$separator/; } return \%tree; -- cgit v1.2.1