How can I convert my shell script to Perl? [closed]

You should visit (available in many languages) or to learn some Perl first.

Your shell script doesn’t need to copy the commandline values. You also used #!usr/bin/bash which won’t work because the path is either /usr/bin/bash or (more common) /bin/bash:

createviewset ccm -b $1 -t $2
source setenv $2
rest of the code

Perl assigns all command line arguments to the array @ARGV. This sample prints your two arguments:

print $ARGV[0];
print $ARGV[1];

Notice that the numbering starts with 0 instead of 1 as in $1 in your bash script.

Next part is running external (shell) commands in Perl: Use the system command.

use strict;
use warnings;

system 'createviewset','ccm','-b',$ARGV[0],'-t',$ARGV[1];
system 'source','setenv',$ARGV[1];

Notice that the source command won’t work because a Perl script is not a shell script and can’t “include” Bash script. I appreciate that you’re trying to use Perl for your problem, but it looks like Bash is the much better tool for this.

Browse More Popular Posts

Leave a Comment