Converting Perl code to shell

I have a perl code that runs like

Code I

sub p
{
   if ($d >= $D) {return}

   printf "%3s"x$d++," ";
   printf "%s%s\n",$_[0],$h{$_[0]}?" ** ":"";

   if (!$h{$_[0]})
   {
      $h{$_[0]}=1;
      map {p($_)} @{$s{$_[0]}}
   }
   $d--
}

($Set,$Job,$Num,$D) = (@ARGV);
map {shift} 0..3;

while (<>)
{
   map {push @{$s{"$pS,$pJ,$pN"}},"$sS,$sJ,$sN"} {($sS,$sJ,$sN,$pJ,$pS,$pN) = (/DEFINE JOBPRED ID=.(\S+),(\S+),(\d+). PJOB=(\S+) PSET=(\S+) PJNO=(\S+).*/)}
}

Code II

sub p
{
   if ($d >= $D) {return}

   printf "%3s"x$d++," ";
   printf "%s%s\n",$_[0],$h{$_[0]}?" ** ":"";

   if (!$h{$_[0]})
   {
      $h{$_[0]}=1;
      map {p($_)} @{$s{$_[0]}}
   }
   $d--
}

($Set,$Job,$Num,$D) = (@ARGV);
map {shift} 0..3;

while (<>)
{
   map {push @{$s{"$sS,$sJ,$sN"}},"$pS,$pJ,$pN"} {($sS,$sJ,$sN,$pJ,$pS,$pN) = (/DEFINE JOBPRED ID=.(\S+),(\S+),(\d+). PJOB=(\S+) PSET=(\S+) PJNO=(\S+).*/)}
}

p("$Set,$Job,$Num");

I need to convert this to UNIX Shell (perhaps using awk/sed ?). Could you please advise.

I hope there is sufficient information here.

Could please advise if had a chance to look at this?

I know perl but not shell, and that is some rather strange perl code. Few people will follow that code unless they understand perl really well.

With this massive use of the map function you might be able to convert it to a awk/sed script, but why would you want to? It would probably take 5-10 times the code and I don't think it would be faster.

I would guess the OP does not have perl - the reason for conversion.

It wold be easier if you described what the script does, rather than post perl code.

Hi,

jim mcnamara is correct. The machine where this code (or atleast the functionality of the code is intended to run) does not have Perl.

this code takes in 5 parameters (to generate a inter-dependency report between certain Unix related batch scheduling objects): the usage is:

code1.pl jobset job job_number depth file_to_search_for_dependeny

UXLPRMS02 jain1r:/home/jain1r > pred.pl OLA_OLA CHANGE_JOB_CLASS_ADMIN2 0190 3 /ifiles/retek_am/cauexpr.txt
OLA_OLA,CHANGE_JOB_CLASS_ADMIN2,0190
OLA_OLA,MONITOR_QEDSTID,0171
OLA_OLA,RELEASE_QEDSTID,0170
UXLPRMS02 jain1r:/home/jain1r >
which means CHANGE_JOB_CLASS_ADMIN2 will not run until MONITOR_QEDSTID has run (which inturn will not run until RELEASE_QEDSTID has not run)

Could kindly advise if got a chance to look at this please?

Could kindly advise if got a chance to look at this please?