I'm having some issues getting this to work correctly and hoped y'all might let me know where i'm going wrong here (and maybe some code review as some of this looks ugly to me):
#!/usr/bin/env perl use strict; use warnings; use Config::Any; use Data::Dumper; my $config = Config::Any->load_files( { files => [ ($ARGV[0] // 'config.yml') ], use_ext => 1 } ); my $yml = $config->[0]{$ARGV[0] // 'config.yml'}; print Dumper($yml); my @groups = map {$_} keys %{$yml}; my ($gentitle, $gensearch) = searchgen("one", $yml); print "gentitles: " . Dumper($gentitle); print "gensearch: " . Dumper($gensearch); sub searchgen { my ($group, $hash) = @_; print "searchgen group: [$group]\n"; my ($titles, $fields); if ($group ~~ @groups and $group !~ /default/) { print "GROUP: [" . $group . "]\n"; for my $i (0 .. $#{$hash->{$group}}) { my $first = $hash->{$group}[$i][0]; print "FIRST: [$first]\n"; if (my ($name) = grep {$_ ~~ @groups} $first =~ /^\*(\S*)/) { print "NAME: [$name]\n"; my ($titlespart, $fieldspart) = searchgen($name, $hash); die "Program failed to parse linked part of yaml successfully in $name" if ($#{$titlespart} != $#{$fieldspart}); for my $part (0 .. $#{$titlespart}) { push @$titles, $titlespart->[$part]; push @$fields, $fieldspart->[$part]; } } else { for my $part (0 .. $#{$hash->{$group}}) { push @$titles, $hash->{$group}[0]; push @$fields, $hash->{$group}[1]; } } } } else { print "[" . $hash->{default}[0] . "]\n"; push @$titles, $hash->{default}[0]; push @$fields, $hash->{default}[1]; } return $titles, $fields; } ###### YAML default: - - blah - "tbl.col" - - blah1 - "tbl.col1" one: - - "*default" - - blah2 - "tbl.col2" ###### EXPECTED OUT gentitles: $VAR1 = [ 'blah', 'blah1', 'blah2' ]; gensearch: $VAR1 = [ 'tbl.col', 'tbl.col1', 'tbl.col2' ]; -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/