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'
Frage
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 );
Lösung
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'
Andere Tipps
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.