in reply to Difficulty handling std{in,out,err} of child processes

my %used; for ( @{ $graph_data->{Edges} } ) { $edges{$_->{in}->[0]} //= {}; $edges{$_->{in}->[0]}->{$_->{in}->[1]} //= []; push( @{ $edges{$_->{in}->[0]}->{$_->{in}->[1]} }, $_->{out} ); $used{$_->{out}} //= 0; $used{$_->{out}}++; if ( grep { $used{$_} > 1 } keys( %used ) ) { die( 'Only one input per node!' ); } }

Perl has a thing called autovivification, which means that that could be simplified to:

my %used; for ( @{ $graph_data->{Edges} } ) { push @{ $edges{ $_->{in}[0] }{ $_->{in}[1] } }, $_->{out}; if ( ++$used{ $_->{out} } > 1 ) { die 'Only one input per node!'; } }


eval { ... }; if ( $! ) { say "Error starting ID $_->{id}: $!"; }

The $! variable does nothing useful there.    You need to use the $@ variable instead.

Replies are listed 'Best First'.
Re^2: Difficulty handling std{in,out,err} of child processes
by eternaleye (Novice) on Dec 01, 2010 at 07:16 UTC
    re autovivification, I tried first without the //= lines, but push kept spitting out an error about the first argument needing to be an array or array reference and not a hash element.

    Also, the $! _is_ giving the 'invalid seek' message, and I just tried with $@ and it merely said:
    Error starting ID 5:
    ie, without any error message at all. (If I change the if as well, the line is missing completely.)

      If  start_job() is setting $! when it fails then you need to die at that point with $! in the error message and that will show up in $@ at the end of eval.

        Ah, okay. Thanks!
      Hm, with your suggestion on the %used section it's working. Not sure why I was getting the error I was.