Set a shell array from an array in Perl script

后端 未结 3 1813
旧巷少年郎
旧巷少年郎 2021-01-29 07:23

I have the following Perl script:

 sub {
    my $sequence=\"SEQUENCE1\";
    my $sequence2=\"SEQUENCE2\";
    my @Array = ($sequence, $sequence2);
    return \\@         


        
3条回答
  •  感情败类
    2021-01-29 07:48

    You can do this, but you need to change vectTEST.pl -- currently you have an anonymous sub that you're not assigning to anything. Change the perl script to:

    $vect = sub {
        my $sequence="SEQUENCE1";
        my $sequence2="SEQUENCE2";
        my @Array=();
        push(@Array,$sequence,$sequence2);
        return \@Array;
    };
    1;
    

    Then, you can do this in bash:

    mapfile -t seq < <(perl -E 'do "vectTEST.pl"; say join "\n", @{$vect->()}')
    for idx in "${!seq[@]}"; do echo "$idx  ${seq[idx]}"; done
    
    0  SEQUENCE1
    1  SEQUENCE2
    

提交回复
热议问题