Read 20 lines when pressing n for next

S

s9uzaa

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
 
J

Jürgen Exner

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
 
A

A. Sinan Unur

(e-mail address removed) wrote in (e-mail address removed):
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

--
A. Sinan Unur <[email protected]>
(remove .invalid and reverse each component for email address)

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

Jürgen Exner

Chris Mattern said:
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
 
T

Ted Zlatanov

On Tue, 29 Apr 2008 18:21:12 -0700 (PDT) (e-mail address removed) wrote:

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

perl -e'sub { exec less => -20 => @_}->(@ARGV)' FILE1 FILE2 ...

Unfortunately this uses SPACE or `f' instead of `n' to advance to the
next 20 lines, but I think it meets all the other criteria.

Good luck!
Ted
 
G

Gordon Etly

A. Sinan Unur said:
Agreed. Which is why he does not get any fish before showing his
attempts at fishing for himself ;-)

Why do you all just assume it's a homework assignment? Could it not just
as well be a simplified work project? I would not be at all surprised if
this was something handed down by one's boss or project manager, and
written in a simplified form (which is what one *should* do, no?) I
really see little point to make such an assumption, and I'm sure no one
likes being talked down to.
 
U

Uri Guttman

GE> Why do you all just assume it's a homework assignment? Could it
GE> not just as well be a simplified work project? I would not be at
GE> all surprised if this was something handed down by one's boss or
GE> project manager, and written in a simplified form (which is what
GE> one *should* do, no?) I really see little point to make such an
GE> assumption, and I'm sure no one likes being talked down to.

gack, you again? having done a bit of perl, written requirements and
assigned tasks, i would have never said 'must use a subroutine'. that
plus the wording of the other requirements reeks of homework. but you
again seem to take offense at what is patently obvious to all the others
here. why don't you stop doing that and actually either answer his
homework assignment by giving him a fish or stfu. did you even notice
that the assignment is really a simple form of more/less written in
perl? how could that be a real world project assignment? your comment
insults the theoretical project manager by saying he would rewrite
more/less in perl for no reason. how dare you insult him? what gives you
the right to decide he is a poor project manager? maybe he doesn't know
about more/less? maybe he needs a version in perl for some unknown
reason you can't comprehend? i prefer to take the easier assumption
(occam's razor and all) that is is a homework assignment.

now go sit in the corner of the classroom facing the walls!

uri
 
G

Gordon Etly

Uri said:
gack, you again? having done a bit of perl, written requirements and
assigned tasks, i would have never said 'must use a subroutine'. that
plus the wording of the other requirements reeks of homework.

It could be homework, just as it could be any number of things. Could
just be how the OP put together his post, listing what he wanted to do.
The point is _you_ _don't_ _know_.
 
G

Gordon Etly

Sherman said:
....


Read step four: "Must have subroutine used."

It doesn't take a psychic or a genius to identify homework when it has
requirements like that.


Uh - no. The point of hiring a professional programmer is that the
manager should *not* have to write detailed, trivial instructions
like "be sure to use subroutines." One gets that kind of assignment
at school, but at work one is expected to know how to do the job
without all the hand-holding.

You could be surprised at how clueless some mangers/bosses can be. Never
underestimate that.
 
U

Uri Guttman

GE> It could be homework, just as it could be any number of things. Could
GE> just be how the OP put together his post, listing what he wanted to do.
GE> The point is _you_ _don't_ _know_.

and you know it is the opposite? how nice of you to tell us. we will
consult with you before we decide if other posts are homework. will you
be available 24x7 for this job? we all appreciate your doing this
thankless job and for no pay! do you want a long term contract to be the
homework monitor? for no extra pay will you actually answer perl
questions? or will you just make sure we do the right thing and you just
take the glory? please guide us O enlightened one as we need your help!

and there was no sarcasm in that, sincerely!

uri
 
U

Uri Guttman

GE> ...

GE> You could be surprised at how clueless some mangers/bosses can be. Never
GE> underestimate that.

or some posters. we have never underestimated that.

uri
 
G

Gordon Etly

Uri said:
and you know it is the opposite?

I don't know either way, but neither do you. That's the point. You
should not make assumptions that could just as easily be wrong (even if
it appears it "must" be a particular way) and pretend the alternatives
don't exist; just because _you_ deem such alternatives as unlikely
doesn't mean ultimately that they are.
 
G

Gordon Etly

Keith said:
Are you going to help, or are you going to continue to troll?

Translation: one cannot have an opinion or make a point that conflicts
with your own, lest the world cometh tumbling down to the ground. For
shame.

"I don't know either way, but neither do you. That's the point."
-from my other reply.

It's a point that you and Uri do not like, but last I checked, a
disagreement doesn't
Seriously--since ''Gordon'' isn't posting *wrong* Perl, there's no
reason to continue to reply to him. Perhaps if we all ignore him
he'll either stop posting his ridiculous rants, or he'll post actual
help.

I am a helping on several lists. If I could help in every single list I
have interest in, I would have to spend every waking moment going form
list to list, which isn't very realistic. Perhaps I'll spend more time
here when I tire of one of the ones I do offer help in. Either way, it's
not, and never has been, a requirement for posting comments in a group,
list, forum, or other.
 
N

nolo contendere

Translation: one cannot have an opinion or make a point that conflicts
with your own, lest the world cometh tumbling down to the ground. For
shame.

I wouldn't translate Keith's statement that way. Rather, I'd say that
he is implying that you're being needlessly argumentative, and that
your line of discussion is not productive.
 
G

Gordon Etly

nolo said:
I wouldn't translate Keith's statement that way. Rather, I'd say that
he is implying that you're being needlessly argumentative, and that
your line of discussion is not productive.

Well, it might not be the most productive, but it no less than Uri and
others making such assumptions that could easily be wrong. Frankly,
since when can one not comment on what someone else wrote? As I recall,
that by posting in a public forum, you are inviting comments, and that's
all I'm doing, yet some people choose to get on the defensive and sling
mud, rather than engage in a civil discussion.
 
G

Gordon Etly

Sherman said:
Spare me. Seriously - spare me.

Oh, sorry to have infringed on his royal majesty.
Another with two brain cells can see that the OP's question was
homework.

You don't know that, which was the point I made and you just happily
skipped over.
This has nothing to do with that. You've just got your
panties in a knot about the whole stupid "PERL vs Perl" thread, and

Heh. It seemed it was people like your self that had their underware
wound up in quite a bunch...
you're whining about every damn thing Uri says.

.... I made a point and people like Uri decided use cheap technicalities,
as well as to attack my character rather than submit a real refute to my
core point.
Grow up and give it a rest already. I'm sick of seeing your "Uri is
evil"

I dare you to point out where I actually said that. It seems to me
people like you and Uri simply cannot stand to have such faults pointed
out, for if one does it's time to whip out the ol' pitch forks and
torches...

And I'm the one who has to grow up... thanks you made my day with that
one :)
 
U

Uri Guttman

GE> ... I made a point and people like Uri decided use cheap technicalities,
GE> as well as to attack my character rather than submit a real refute to my
GE> core point.

my technicalities are the most expensive around! i have the receipts to
prove it!

but i don't attack your character as you have shown none. all you have
done is flame about how others post here. just shut up already unless
you actually talk some perl. that is all anyone is asked to do here. it
doesn't take character, it takes an understanding and enjoyment of
perl. do you have that?

GE> I dare you to point out where I actually said that. It seems to me
GE> people like you and Uri simply cannot stand to have such faults pointed
GE> out, for if one does it's time to whip out the ol' pitch forks and
GE> torches...

faults? i have no faults (other than the ones caused by the tectonic
plates in my skull).

GE> And I'm the one who has to grow up... thanks you made my day with that
GE> one :)

yes you do. i grew up last week. i have had enough of that. your turn!

uri
 
G

Gordon Etly

Uri said:
but i don't attack your character as you have shown none. all you have
done is flame about how others post here.

With all due respect, all I am guilty of is having opinions (which
happens to be contrary to your own view in both cases.) If anyone did
any "flaming", it was people like you that turned a simple point into a
kill-the-heretic.

You don't agree with someone, fine. But don't make it your personal
vendetta.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,158
Latest member
Vinay_Kumar Nevatia
Top