Sponsored Content
Top Forums Shell Programming and Scripting Converting Perl code to shell Post 302292910 by zainravi on Monday 2nd of March 2009 01:54:09 AM
Old 03-02-2009
Converting Perl code to shell

I have a perl code that runs like

Code I
Code:
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
Code:
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.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Converting bash shell to perl

Does anyone know how to convert this bash shell script to perl? for i in `ls -l *pgp` do `usr/bin/gpg --passphrase-fd 0 $i < .sunspot` done Thanks! Any help would be appreciated. I'm new to Linux and perl. (4 Replies)
Discussion started by: freak
4 Replies

2. Shell Programming and Scripting

Refrence Shell variable in Perl code.

:confused: I have 2 files a & b Contents of a are:- -------------------------- This is a Good Boy This is a Good Boy This is a Very Good Boy This is a Good Boy This is a Good Boy --------------------------- The contents of b are ------------------- This is Testing Beta... (5 Replies)
Discussion started by: send2sridhar
5 Replies

3. Shell Programming and Scripting

How to run perl code within a shell script...?

Hi, I have a sheel script that invokes a perl script...Now, instead havin the perl script as a separate file I'd like put the contents in the sheel script itself...But I am not sure how ro run that perl script contents.please help me Thanks (1 Reply)
Discussion started by: vijay_0209
1 Replies

4. Shell Programming and Scripting

Converting perl to exe

Hello All, I want to convert .pl to .exe with all include libraries like: WIN32/OLE..... Please suggest me how i will proceed for this.... (7 Replies)
Discussion started by: suvenduperl
7 Replies

5. Shell Programming and Scripting

convert perl code to shell script

This is about how to Monitoring folder for new files using shell script im doing a project using smsserver tools 3. i have used a perl script to handle incoming messages. the content of each message must be directed to a java program. this program generates the answer to reply to the user... (2 Replies)
Discussion started by: x34
2 Replies

6. Shell Programming and Scripting

Perl:: mass replacement of converting C code formats to tgmath.h

hello, i have a lot of C old code I'm updating to C11 with tgmath.h for generic math. the old code has very specific types, real and complex, like cabsl, csinhl, etc usually for simple bulk replacements i would do something simple like this perl -pi -e 's/cosl/cos/g' *.c the reference... (0 Replies)
Discussion started by: f77hack
0 Replies

7. Shell Programming and Scripting

Need shell script version of below perl code

We are using AIX version 7100-03-05-1524 Please provide shell script version (bash or ksh) of below perl code,since we need to have line breaks in huge XML files #!/usr/bin/perl # # Purpose: Read an XML file and indent it for ease of reading # Author: RedGrittyBrick 2011. # Licence:... (11 Replies)
Discussion started by: vishwanath001
11 Replies

8. Shell Programming and Scripting

Converting shell to Perl I run into shell built in function trap and need alternative in Perl

I am working on converting shell to Perl script. In shell we have built in function trap Do you know alternative in Perl or actually we don't need it? Thanks for contribution (3 Replies)
Discussion started by: digioleg54
3 Replies

9. UNIX for Beginners Questions & Answers

Converting awk to perl

Hello. I'm trying to convert an awk script I wrote to perl (which I just started self-teaching). I tried the a2p command but I couldn't make sense of most of it. Here was the awk code: BEGIN{ FS = "," print "NAME\tLOW\tHIGH\tAVERAGE" a=0 } { if(a==0){ a+=1 (1 Reply)
Discussion started by: Eric7giants
1 Replies

10. UNIX for Beginners Questions & Answers

Converting awk to perl

Hello. I'm currently teaching myself Perl and was trying to turn an awk code that I had written into Perl. I have gotten stuck on a particular part and a2p has not helped me at all. The task was to take a .csv file containing a name, assignment type, score and points possible and compute it into a... (1 Reply)
Discussion started by: Eric7giants
1 Replies
LDAP_FRIENDLY(3)					     Library Functions Manual						  LDAP_FRIENDLY(3)

NAME
ldap_friendly_name, ldap_free_friendlymap - LDAP unfriendly to friendly name mapping routine SYNOPSIS
#include <ldap.h> typedef struct ldap_friendly { char *lf_unfriendly; char *lf_friendly; } LDAPFriendlyMap; char *ldap_friendly_name(filename, name, map) char *filename; char *name; LDAPFriendlyMap **map; void ldap_free_friendlymap(map) LDAPFriendlyMap **map; DESCRIPTION
This routine is used to map one set of strings to another. Typically, this is done for country names, to map from the two-letter country codes to longer more readable names. The mechanism is general enough to be used with other things, though. filename is the name of a file containing the unfriendly to friendly mapping, name is the unfriendly name to map to a friendly name, and map is a result-parameter that should be set to NULL on the first call. It is then used to hold the mapping in core so that the file need not be read on subsequent calls. For example: LDAPFriendlyMap *map = NULL; printf( "unfriendly %s => friendly %s ", name, ldap_friendly_name( "/usr/share/openldap/ldapfriendly", name, &map ) ); The mapping file should contain lines like this: unfriendlyname friendlyname. Lines that begin with a '#' character are comments and are ignored. The ldap_free_friendlymap() call is used to free structures allocated by ldap_friendly_name() when no more calls to ldap_friendly_name() are to be made. ERRORS
NULL is returned by ldap_friendly_name() if there is an error opening filename, or if the file has a bad format, or if the map parameter is NULL. FILES
/usr/share/openldap/ldapfriendly.conf SEE ALSO
ldap(3) ACKNOWLEDGEMENTS
OpenLDAP is developed and maintained by The OpenLDAP Project (http://www.openldap.org/). OpenLDAP is derived from University of Michigan LDAP 3.3 Release. OpenLDAP 2.0.27-Release 22 September 1998 LDAP_FRIENDLY(3)
All times are GMT -4. The time now is 05:23 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy