# Converting Perl code to shell

**URL:** <https://community.unix.com/t/converting-perl-code-to-shell/233650>\
**Category:** Shell Programming and Scripting\
**Created:** [March 2, 2009, 1:54am UTC](https://community.unix.com/t/converting-perl-code-to-shell/233650 "2009-03-02T01:54:09Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![zainravi](https://community.unix.com/letter_avatar/zainravi/32/5_5575768a8748004e209b776fc1b2916d.png) [@zainravi](https://community.unix.com/u/zainravi)\
**Post date:** [March 2, 2009, 1:54am UTC](https://community.unix.com/t/converting-perl-code-to-shell/233650/1 "2009-03-02T01:54:09Z")

</div>

I have a perl code that runs like

Code I

```nohighlight
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

```nohighlight
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.

---

<div class="post-metadata">

**Author:** ![zainravi](https://community.unix.com/letter_avatar/zainravi/32/5_5575768a8748004e209b776fc1b2916d.png) [@zainravi](https://community.unix.com/u/zainravi)\
**Post date:** [March 4, 2009, 12:00am UTC](https://community.unix.com/t/converting-perl-code-to-shell/233650/2 "2009-03-04T00:00:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![KevinADC](https://community.unix.com/letter_avatar/kevinadc/32/5_5575768a8748004e209b776fc1b2916d.png) [@KevinADC](https://community.unix.com/u/KevinADC)\
**Post date:** [March 4, 2009, 12:15am UTC](https://community.unix.com/t/converting-perl-code-to-shell/233650/3 "2009-03-04T00:15:55Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![pludi](https://community.unix.com/user_avatar/community.unix.com/pludi/32/1278_2.png) [@pludi](https://community.unix.com/u/pludi)\
**Post date:** [March 4, 2009, 11:40am UTC](https://community.unix.com/t/converting-perl-code-to-shell/233650/4 "2009-03-04T11:40:51Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jim\_mcnamara](https://community.unix.com/letter_avatar/jim_mcnamara/32/5_5575768a8748004e209b776fc1b2916d.png) [@jim\_mcnamara](https://community.unix.com/u/jim_mcnamara)\
**Post date:** [March 4, 2009, 11:52am UTC](https://community.unix.com/t/converting-perl-code-to-shell/233650/5 "2009-03-04T11:52:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![cfajohnson](https://community.unix.com/user_avatar/community.unix.com/cfajohnson/32/16669_2.png) [@cfajohnson](https://community.unix.com/u/cfajohnson)\
**Post date:** [March 4, 2009, 1:33pm UTC](https://community.unix.com/t/converting-perl-code-to-shell/233650/6 "2009-03-04T13:33:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![zainravi](https://community.unix.com/letter_avatar/zainravi/32/5_5575768a8748004e209b776fc1b2916d.png) [@zainravi](https://community.unix.com/u/zainravi)\
**Post date:** [March 4, 2009, 11:04pm UTC](https://community.unix.com/t/converting-perl-code-to-shell/233650/7 "2009-03-04T23:04:11Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![zainravi](https://community.unix.com/letter_avatar/zainravi/32/5_5575768a8748004e209b776fc1b2916d.png) [@zainravi](https://community.unix.com/u/zainravi)\
**Post date:** [March 6, 2009, 2:47am UTC](https://community.unix.com/t/converting-perl-code-to-shell/233650/8 "2009-03-06T02:47:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![zainravi](https://community.unix.com/letter_avatar/zainravi/32/5_5575768a8748004e209b776fc1b2916d.png) [@zainravi](https://community.unix.com/u/zainravi)\
**Post date:** [March 12, 2009, 12:54pm UTC](https://community.unix.com/t/converting-perl-code-to-shell/233650/9 "2009-03-12T12:54:18Z")

</div>

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