Hi Monks, I need to use NDBM_File db across child processes. I use below code to create DB in parent
#!/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, creat +ing 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 retr +ieve 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"; }
I need to know whether I'm doing things rite ? need your wisdom in using NDBM db across multiple child processes.
In reply to use NDBM_File DB by child processes by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |