Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Re: Re: Perl embedded in Kornshell

by perigeeV (Hermit)
on Sep 04, 2001 at 07:20 UTC ( #109979=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Perl embedded in Kornshell
in thread Perl embedded in Kornshell

OK.

First, you seemed to have confused everyone in your original post. We can proceed now that we all have a bit more information. Second, you should check out the Site How To for formatting tips. Just put your code in <code>...</code> tags. Third, my awk is really rusty so let me know if I misread your code.

Your file is only 33M so perl should have no problem provided you have some semblance of memory available to you. So can we assume that you do not need to do any pre-cutting?

In awk the input file is automatically read, parsed and acted upon. In Perl you have to explicitly tell perl how you'd like your file served. So when you say:

cat /home/spjal/files/bprcf.parms /home/spjal/files/temp | perl ' BEGIN { linectr=0 } { linectr++

we would say:

#!/usr/local/bin/perl -w; use strict; my $infile = "/path/to/infile"; my $outfile = "/path/to/outfile"; open(INFILE, "$infile") || die "Died openning $infile. $!\n"; open(OUTFILE, ">$outfile") || die "Died openning $outfile. $!\n"; my $linectr = 0; my $fline; my $lline; while(<INFILE>) { chomp; # Remove the newline.

The while magic will now pull in the file line by line. I hope I understand correctly that the first line contains the four parms. Then:

if(++$linectr == 1) { my($scheck, $echeck, $fcheck, $lcheck) = split; # Splits on + whitespace by default.

Since I don't know the data you're processing I can't second guess your logic, so I'll Perl-ize the next bit:

if ( $fcheck == $scheck ) { $fline=2 } else { $fline=(($fcheck - $scheck) + 3) } if ( $lcheck == $echeck ) { $lline=999999999 } else { $lline=(($lcheck - $scheck) + 3) } } elsif ( $linectr == 2 ) { print OUTFILE "$_\n"; # $_ holds the line. } elsif ( linectr <= lline && linectr >= fline ) { print OUTFILE "$_\n"; } }

That's what I understand from your response. I've written this as a stand alone script that can be called from your shell script. You can also run it inline by changing the hash-bang line with | perl -e '.... Please feel free to post more information or questions.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://109979]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2022-12-07 11:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?