perl script quesion pls

hi all,

i don't know anything about perl but since peer who wrote perl has left, I have to learn this as well accomplish this.. may be it is simple change, which you experts can help me in a min.

here is the issue..

there is perl script (on SOLARIS 5.8) which is called fixPrototype.pl which actually takes an argument as name of file (which is always "prototype) and fixes some stuff in this file..

so we will call

fixprototype.pl prototype

and it will change prototype file by fixing few things..

prototype file looks as below (only few lines)..

#ident  "%W%"
i       pkginfo
i       copyright
i       request

x none $OPTDIR 0755 $OWNER $GROUP

!search $INSDIR
f none $OPTDIR/docs.jar 0644 $OWNER $GROUP
x none $OPTDIR/appvar 0755 $OWNER $GROUP
x none $OPTDIR/appvar/upload 0755 $OWNER $GROUP
x none $OPTDIR/appvar/upload/CIO 0755 $OWNER $GROUP
x none $OPTDIR/appvar/upload/FEED 0755 $OWNER $GROUP
x none $OPTDIR/appvar/upload/FEED/FRANKRUSSELL 0755 $OWNER $GROUP
x none $OPTDIR/appvar/upload/FEED/GENERIC 0755 $OWNER $GROUP
x none $OPTDIR/appvar/upload/FEED/JPMORGAN 0755 $OWNER $GROUP
x none $OPTDIR/appvar/upload/FEED/LJR 0755 $OWNER $GROUP
x none $OPTDIR/appvar/upload/FEED/MELLON 0755 $OWNER $GROUP
x none $OPTDIR/appvar/upload/FEED/MERCER 0755 $OWNER $GROUP
x none $OPTDIR/appvar/upload/FEED/NORTHERNTRUST 0755 $OWNER $GROUP
x none $OPTDIR/appvar/upload/P2P 0755 $OWNER $GROUP
x none $OPTDIR/appvar/upload/PF 0755 $OWNER $GROUP
x none $OPTDIR/data 0755 $OWNER $GROUP
x none $OPTDIR/data/AUS 0755 $OWNER $GROUP
x none $OPTDIR/data/CMTA 0755 $OWNER $GROUP
x none $OPTDIR/data/GMRS 0755 $OWNER $GROUP
x none $OPTDIR/data/LEBL 0755 $OWNER $GROUP
x none $OPTDIR/data/RETAIL 0755 $OWNER $GROUP
x none $OPTDIR/data/logs 0755 $OWNER $GROUP
x none $OPTDIR/data/logs/app 0755 $OWNER $GROUP
x none $OPTDIR/data/logs/appsrv 0755 $OWNER $GROUP
x none $OPTDIR/data/logs/autosys 0755 $OWNER $GROUP
x none $OPTDIR/docs 0755 $OWNER $GROUP

and fixPrototype.pl looks as below (complete code)


#!/opt/perl/5.8.0/bin/perl
#ident      "%W%"
#==================================================
# GLOBAL VARIABLES
#==================================================

$filename      = $ARGV[0];
$myOwner      = $ARGV[1];
$myGroup      = $ARGV[2];
if ($myOwner eq '-' || $myOwner eq "" ) { $myOwner = '$OWNER'; }
if ($myGroup eq '-' || $myGroup eq "" ) { $myGroup = '$GROUP'; }

$wfilename      = $filename.$$;

#print "OWNER = $myOwner\n";

#==================================================
# USUAGE
#==================================================
sub helpme {

      print "\nUSAGE : \n";
      print "$0 <file name> <owner> <group>";
      print "\nex: $0 prototype isoft wls61";
      print "\n if <owner> and/or <group> is a dash (-) then it will default to \$OWNER \and/or $GROUP resp. from request script";
      print "\n\n";
      exit;
}

#==================================================
# PROGRAM
#==================================================

sub changeLine {
      my ($line, $perm, $owner, $group) = @_;
      $line =~ s/\$OWNER/$owner/;
      $line =~ s/\$GROUP/$group/;
      if ( $line =~ m#\s(\d\d\d\d)\s# ) {
            $line =~ s/$1/$perm/;
      }

      return $line;
}

if ( $ARGV[0] =~ /help/i || (length(@ARGV)+1) != 2 ) {
      &helpme;
} elsif (! -f $filename) {
      print "ERROR: $filename NOT found!\n";
      exit;
}

open(READPERL, "<$filename") || die "CANNOT OPEN $filename for reading";
open(WRITEPERL, ">$wfilename") || die "CANNOT OPEN $wfilename for writing";

while (my $line = <READPERL>) {

            if ($line =~ m|\$OPTDIR/data |) {
                  # if we leave this line in prototype,
                  # sym link will be removed and a physical directory will
                  # be created instead - bad.
                  # by removing it the other dirs spcified in protoype under data will still get created
                  # but they will get created on ftp nfs server as we want
                  
                  # touch this line and die!!!! - ask Scot B first

            } elsif ($line =~ m|\$OPTDIR/weblogic/etc|) {
                  # for shell scripts, etc.
                  print WRITEPERL changeLine($line, '0775', '$OWNER', '$GROUP');
            } elsif ($line =~ m|\$OPTDIR/appvar/upload |) {
                  # general location for writing files by weblogic
                  print WRITEPERL changeLine($line, '0775', 'wls61', '$GROUP');
            } elsif ($line =~ m|\$OPTDIR/appvar/upload/|) {
                  # general location for writing files by weblogic
                  print WRITEPERL changeLine($line, '0775', 'wls61', 'isoft');
              } elsif ($line =~ m|\$OPTDIR/logs/autosys|) {
                  # general location for writing autosys logs
                  print WRITEPERL changeLine($line, '0775', 'isoft', '$GROUP');
              } elsif ($line =~ m|\$OPTDIR/logs|) {
                  # general location for writing logs
                  print WRITEPERL changeLine($line, '0775', 'wls61', '$GROUP');
            } elsif ($line =~ m|\$OPTDIR/data/|) {
                  # general location for data files
                  # make it writable by isoft and wls61
                  # isoft - as this is the id autosys runs as
                  # wls61 as this is the id weblogic runs as
                  print WRITEPERL changeLine($line, '0775', 'wls61', 'isoft');
            } elsif ($line =~ m|config.xml|) {
                  print WRITEPERL changeLine($line, '0775', 'isoft', '$GROUP');
            } elsif ($line =~ m|setEnv.sh|) {
                  print WRITEPERL changeLine($line, '0775', 'isoft', '$GROUP');
            } elsif ($line =~ m|50006_AutosysProfile.sh|) {
                  print WRITEPERL changeLine($line, '0775', 'isoft', '$GROUP');
            } elsif ($line =~ m|rits_ldap.properties|) {
                  print WRITEPERL changeLine($line, '0775', 'isoft', '$GROUP');
            } else {
                  printf WRITEPERL $line;
            }
}

rename($wfilename, $filename);
close(READPERL);
close(WRITEPERL);



Bascially Requirement is as below:

I have to enhance pl script so that before fixing anything, it should read the prototype file and when it finds the line
i       request


after that it should insert a new line saying

i<tab>postinstall

so bascially new prototype file (only few lines) should look as below


#ident  "%W%"
i       pkginfo
i       copyright
i       request
i       postinstall

x none $OPTDIR 0755 $OWNER $GROUP

!search $INSDIR
f none $OPTDIR/docs.jar 0644 $OWNER $GROUP
x none $OPTDIR/appvar 0755 $OWNER $GROUP
x none $OPTDIR/appvar/upload 0755 $OWNER $GROUP

and the fixes which perl script is already doing..


hope you can help me with this...

regards
shivaniAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

kanduraCommented:
add another elsif:

    elsif( $line =~ m|^i\trequest| ) {
        # add postinstall line
        print WRITEPERL $line . "i\tpostinstall\n";
    }
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gripeCommented:
> I have to enhance pl script so that before fixing anything

Why do you have this requirement? If you see the line 'i     request' do you want to stop processing and ONLY change that line or do you want to continue on with the normal changes on the script. If you want to continue on, this is a simple matter of adding another elsif clause to your if/else statement, like so:

          } elsif ($line =~ m|i\trequest|) {                  # match i followed by a tab followed by request
               print WRITEPERL "$line\ni\tpostinstall\n"; # print the i<tab>request line followed by a i<tab>postinstall line
          }

Hope this helps.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.