Click here to get back home

Read 20 lines when pressing n for next

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Read 20 lines when pressing n for next s9uzaa 04-29-2008
Posted by s9uzaa on April 29, 2008, 9:21 pm
Please log in for more thread options
Hi,
I would like to write a perl script with the following criteria match.
1. open any text file taken the name from the command line.
2. read top 20 lines and stops, then
3. ask to press letter "n or p" (for next/previous) to print next or
previous 20 lines.
would appreciate any kind of help.
4. must have subroutine used.

thanks

Posted by Jürgen Exner on April 29, 2008, 9:48 pm
Please log in for more thread options
s9uzaa@gmail.com wrote:
>I would like to write a perl script with the following criteria match.
>1. open any text file

perldoc -f open

>taken the name from the command line.

perldoc perlvar and check for '@ARGV'

>2. read top 20 lines and stops, then

perldoc perlsyn and check for 'for'. However given the next requirement
the algorithm becomes a lot easier if you slurp in the whole file into
an array. If you read 20 line chunks then you need to seek forward and
backward all the time which is a real pain. In an array you just move
your current index.

>3. ask to press letter "n or p" (for next/previous)

perldoc -q single

>to print next or previous 20 lines.
> would appreciate any kind of help.

Maybe you should ask your tutor/teacher?

>4. must have subroutine used.

perldoc perlsub

jue

Posted by A. Sinan Unur on April 29, 2008, 9:48 pm
Please log in for more thread options
s9uzaa@gmail.com wrote in news:37b9eb38-e188-4dc2-b3a7-
5f09cc3b81ea@a70g2000hsh.googlegroups.com:

> I would like to write a perl script with the following criteria match.

Give it a shot. Then post any questions you might encounter (please read
the posting guidelines first).

> 1. open any text file taken the name from the command line.
> 2. read top 20 lines and stops, then
> 3. ask to press letter "n or p" (for next/previous) to print next or
> previous 20 lines.
> would appreciate any kind of help.
> 4. must have subroutine used.

Look up $. in perldoc perlvar

Sinan

--
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/

Posted by Chris Mattern on April 30, 2008, 11:49 am
Please log in for more thread options
> s9uzaa@gmail.com wrote in news:37b9eb38-e188-4dc2-b3a7-
> 5f09cc3b81ea@a70g2000hsh.googlegroups.com:
>
>> I would like to write a perl script with the following criteria match.
>
> Give it a shot. Then post any questions you might encounter (please read
> the posting guidelines first).
>
>> 1. open any text file taken the name from the command line.
>> 2. read top 20 lines and stops, then
>> 3. ask to press letter "n or p" (for next/previous) to print next or
>> previous 20 lines.
>> would appreciate any kind of help.
>> 4. must have subroutine used.
>
> Look up $. in perldoc perlvar
>
I got $5 that says this is homework. "must have subroutine used" is
a dead giveaway.

--
Christopher Mattern

NOTICE
Thank you for noticing this new notice
Your noticing it has been noted
And will be reported to the authorities

Posted by Jürgen Exner on April 30, 2008, 12:46 pm
Please log in for more thread options
>> s9uzaa@gmail.com wrote in news:37b9eb38-e188-4dc2-b3a7-
>>> 4. must have subroutine used.
>>
>> Look up $. in perldoc perlvar
>>
>I got $5 that says this is homework. "must have subroutine used" is
>a dead giveaway.

Absolutely agree. However, the tutor isn't that smart, either.

A sub
        sub do_nothing{};

that is called somewhere in the program would already fulfill that
requirement. Probably not what he had in mind but apparently he couldn't
come up with a more appropriate one.

jue

Similar ThreadsPosted
filehandle, read lines July 24, 2007, 5:09 am
Read first few lines from command output July 27, 2005, 1:47 pm
Beginner: read in lines array1 and after keyword array2 July 30, 2006, 7:37 am
How to break the lines in printing to html lines? July 5, 2006, 11:21 pm
perl -pe for blocks of lines instead of single lines September 26, 2006, 1:29 pm
How to filter out lines from a variable that has multi-lines? September 28, 2007, 9:09 pm
FAQ 6.3 How can I pull out lines between two patterns that are themselves on different lines? January 27, 2005, 12:03 am
FAQ 6.3 How can I pull out lines between two patterns that are themselves on different lines? May 14, 2005, 5:03 am
FAQ 6.3 How can I pull out lines between two patterns that are themselves on different lines? July 29, 2005, 10:03 pm
FAQ 6.3 How can I pull out lines between two patterns that are themselves on different lines? September 26, 2005, 10:03 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap