문제

I have a perl module with data definitions (hashes, arrays, etc.), is there any way I can access that data from inside a bash script? This isn't working for me...

#!/bin/bash

perl -e 'use Data'
tests=`perl -e "@tests"; `
echo "Perl tests = ${tests}"         # prints "Perl tests = "

The module looks something like this:

our @EXPORT_OK = qw( @tests );
our @tests = qw( 1 2 3 4 5 );
도움이 되었습니까?

해결책

If you have package variable @tests inside Data module,

perl -MData -e 'print "$_\n" for @Data::tests'

For perl 5.10 and above,

perl -MData -E 'say for @Data::tests'

다른 팁

You can use a module from the command line with -M

perl -MData -e'print map {"$_\n"} @tests;'

In the code you give, you run one interpreter that loads Data. It exits. You then run a second interpreter, which prints @tests. As that's the only action the second interpreter has performed, it's uninitialized, and prints nothing.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top