This:
my @array = (1,2,3);
system ("/tmp/a.sh @array" );
is equivalent to the shell command:
/tmp/a.sh 1 2 3
you can see this by simply printing out what you pass to system:
print "/tmp/a.sh @array";
a.sh
should handle them like any other set of shell arguments.
To be safe, you should bypass the shell and pass the array in as arguments directly:
system "/tmp/a.sh", @array;
Doing this passes each element of @array
in as a separate argument rather than as a space separated string. This is important if the values in @array
contain spaces, for example:
my @array = ("Hello, world", "This is one argument");
system "./count_args.sh @array";
system "./count_args.sh", @array;
where count_args.sh
is:
#!/bin/sh
echo "$# arguments"
you'll see that in the first one it gets 6 arguments and the second it gets 2.
A short tutorial on handling arguments in a shell program can be found here.
Anyhow, why write one program in Perl and one in shell? It increases complexity to use two languages and shell has no debugger. Write them both in Perl. Better yet, write it as a function in the Perl program.