#!/usr/bin/env perl use warnings; use Fcntl; use NDBM_File; use List::Util qw(first); my $df = 'db'; my %db; my @c_p; (tie %db, NDBM_File, $df, O_CREAT|O_RDWR, 0666) || die "$0: ERR, creating DB $df : $!\n"; $db{'fields'} = ['rc', 'ev', 'h', 'u', 'oh', 'c', 'i', 'n_c']; untie %db || die "$0: Couldn't close db, $!\n"; my $pid = fork(); if ( $pid ) { # parent push @c_p, $pid; } elsif ( $pid == 0) { #child ssh_remote_exec(); exit (0); } sub ssh_remote_exec { my %_h; my @a; my %db; my $df = 'db'; (tie %db, NDBM_File, $df, O_RDWR, 0666) || die "$0: ERR, open DB $df : $!\n"; # get output from remote exec and parse it into %_h # here open the db created in parent, use the field key to retrieve the array index and put there the value of key from %_h # but $db{'field'} has no data in child foreach my $k (keys %_h ) { my $i = first { $db{'fields'}->[$_] eq $k } 0..$#{$db{'fields'}}; $a[$i] = $_h{$k}; print "key : $k, index : $i, value: $_h{$k} \n"; } print join (';', @a), "\n"; $db{'1'} = join (';', @a); untie %db || die "$0: Couldn't close db, $!\n"; }