Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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.


In reply to Re: Re: Re: Perl embedded in Kornshell by perigeeV
in thread Perl embedded in Kornshell by JALandry

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (2)
As of 2023-02-04 12:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer not to run the latest version of Perl because:







    Results (31 votes). Check out past polls.

    Notices?