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

You should visit http://perlmaven.com/ (available in many languages) or http://learn.perl.org/ 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:

#!/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:

#!/usr/bin/perl
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.

#!/usr/bin/perl
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.

Leave a Comment