Help: Perl Script Doesn't Write Out

Help: Perl Script Doesn't Write Out

Post by Aristotl » Thu, 20 Jun 2002 03:15:28



I have created a Bourne Shell script that is supposed to execute Perl
commands to change multiple dates within a file.  We found that we could
not use sed because it changes the number of bytes in the file, which
causes an out of synch situation with our program...Problem:

The script seems to never write out...What can I do to solve this
problem?  Here is the code in general:

#!/bin/sh

myname="/opt/jets/users/`whoami`/PNRForward"
if test -f $myname
then
        echo "$0: Cannot make directory $myname (already exists)" 1&>2
        exit 0
fi

echo "Enter the filename you want to age forward \c"
read FILENAME
mkdir "$myname"
echo "PNRForward is now in progress....go get a cup of coffee... \c"
perl -pe 's/18JUN/13aug/g'; \
-pe 's/19JUN/14aug/g'; \
-pe 's/20JUN/15aug/g'; \
-pe 's/21JUN/16aug/g'; \
-pe 's/22JUN/17aug/g'; \
-pe 's/23JUN/18aug/g'; \
-pe 's/24JUN/19aug/g'; \
$FILENAME > "$myname"/"$FILENAME`date +_%m%d%H%M%S`"
echo "done"

Thanks for any pointers.

A.

 
 
 

Help: Perl Script Doesn't Write Out

Post by those who know me have no need of my nam » Thu, 20 Jun 2002 04:52:29


in comp.unix.shell i read:

Quote:>I have created a Bourne Shell script that is supposed to execute Perl
>commands to change multiple dates within a file.  

often it's better to do it all in perl.  why?  each time you start perl it
takes a while (to compile the script), but if you loop inside perl the
single invocation and looping is very fast.

Quote:>The script seems to never write out...What can I do to solve this
>problem?  Here is the code in general:

not a cut-and-paste?  then you might have introduced typos which i'm about
to help you fix but which aren't actually present in your script -- don't
do that.  if you did cut-and-paste and just removed the unnecessary parts
then we'll hope that they were actually unnecessary.  it's good to trim,
but you need to be careful is all.

Quote:>perl -pe 's/18JUN/13aug/g'; \
>-pe 's/19JUN/14aug/g'; \
>-pe 's/20JUN/15aug/g'; \
>-pe 's/21JUN/16aug/g'; \
>-pe 's/22JUN/17aug/g'; \
>-pe 's/23JUN/18aug/g'; \
>-pe 's/24JUN/19aug/g'; \
>$FILENAME > "$myname"/"$FILENAME`date +_%m%d%H%M%S`"

perl -pe '
s/18JUN/13aug/g;
s/19JUN/14aug/g;
s/20JUN/15aug/g;
s/21JUN/16aug/g;
s/22JUN/17aug/g;
s/23JUN/18aug/g;
s/24JUN/19aug/g;
' $FILENAME > "$myname"/"$FILENAME`date +_%m%d%H%M%S`"

--
bringing you boring signatures for 17 years

 
 
 

Help: Perl Script Doesn't Write Out

Post by Aristotl » Thu, 20 Jun 2002 05:46:45




Quote:> in comp.unix.shell i read:

> >I have created a Bourne Shell script that is supposed to execute Perl
> >commands to change multiple dates within a file.

> often it's better to do it all in perl.  why?  each time you start perl it
> takes a while (to compile the script), but if you loop inside perl the
> single invocation and looping is very fast.

> >The script seems to never write out...What can I do to solve this
> >problem?  Here is the code in general:

> not a cut-and-paste?  then you might have introduced typos which i'm about
> to help you fix but which aren't actually present in your script -- don't
> do that.  if you did cut-and-paste and just removed the unnecessary parts
> then we'll hope that they were actually unnecessary.  it's good to trim,
> but you need to be careful is all.

> >perl -pe 's/18JUN/13aug/g'; \
> >-pe 's/19JUN/14aug/g'; \
> >-pe 's/20JUN/15aug/g'; \
> >-pe 's/21JUN/16aug/g'; \
> >-pe 's/22JUN/17aug/g'; \
> >-pe 's/23JUN/18aug/g'; \
> >-pe 's/24JUN/19aug/g'; \
> >$FILENAME > "$myname"/"$FILENAME`date +_%m%d%H%M%S`"

> perl -pe '
> s/18JUN/13aug/g;
> s/19JUN/14aug/g;
> s/20JUN/15aug/g;
> s/21JUN/16aug/g;
> s/22JUN/17aug/g;
> s/23JUN/18aug/g;
> s/24JUN/19aug/g;
> ' $FILENAME > "$myname"/"$FILENAME`date +_%m%d%H%M%S`"

> --
> bringing you boring signatures for 17 years

Thanks for the reply.  Now I'm getting a file that's created but it is
empty...any ideas?
 
 
 

Help: Perl Script Doesn't Write Out

Post by John W. Krah » Thu, 20 Jun 2002 10:06:50



> I have created a Bourne Shell script that is supposed to execute Perl
> commands to change multiple dates within a file.  We found that we could
> not use sed because it changes the number of bytes in the file, which
> causes an out of synch situation with our program...Problem:

> The script seems to never write out...What can I do to solve this
> problem?  Here is the code in general:

> #!/bin/sh

> myname="/opt/jets/users/`whoami`/PNRForward"
> if test -f $myname
> then
>         echo "$0: Cannot make directory $myname (already exists)" 1&>2
>         exit 0
> fi

> echo "Enter the filename you want to age forward \c"
> read FILENAME
> mkdir "$myname"
> echo "PNRForward is now in progress....go get a cup of coffee... \c"
> perl -pe 's/18JUN/13aug/g'; \
> -pe 's/19JUN/14aug/g'; \
> -pe 's/20JUN/15aug/g'; \
> -pe 's/21JUN/16aug/g'; \
> -pe 's/22JUN/17aug/g'; \
> -pe 's/23JUN/18aug/g'; \
> -pe 's/24JUN/19aug/g'; \
> $FILENAME > "$myname"/"$FILENAME`date +_%m%d%H%M%S`"
> echo "done"

#!/usr/bin/perl -w
use strict;
use POSIX 'strftime';

my $myname = "/opt/jets/users/$ENV{USER}/PNRForward";
mkdir $myname or die "Cannot mkdir $myname: $!";

print "Enter the filename you want to age forward ";
chomp( my $file_in = <STDIN> );
my $file_out = "$myname/$file_in" . strftime '_%m%d%H%M%S', localtime;

print "PNRForward is now in progress....go get a cup of coffee... ";

open IN,  '<', $file_in  or die "Cannot open $file_in: $!";
open OUT, '>', $file_out or die "Cannot open $file_out: $!";

while ( <IN> ) {
    s/18JUN/13aug/g;
    s/19JUN/14aug/g;
    s/20JUN/15aug/g;
    s/21JUN/16aug/g;
    s/22JUN/17aug/g;
    s/23JUN/18aug/g;
    s/24JUN/19aug/g;
    print OUT;
    }

print "done\n";

__END__

John
--
use Perl;
program
fulfillment