in reply to Isn't there a print line function?
Your basic question is "How can I: do X to Y if Y has characteristic Z." You phrased it as "How can I print the 9th thing in X if I know that the 9th thing should have characteristic Y, but it might not be the 9th thing?"
As I reccommended before, think your problems through. Instead of rushing into an editor and typing away, write your solutions out on paper first. In fact, you might try writing out your problem there, too. Oftentimes, it's not that the solution eludes us, but the problem does.
I know it sounds like a waste of time, but think of it this way - if you manage to get it working without paper, great! But, you have been stopping into PM a lot. That's all well and good, but you're spending a lot of your time on understanding your problem vs. solving your problem. That time doesn't have to be spent like that.
If you write our your solution in pseudo-code, then you'll start to immediately notice parts you don't understand very well. Heck, write it out in English, as if you were going to explain your proposed solution to someone who doesn't program at all. An example could be as follow:
Problem: Given a paragraph, print out each line that contains the word "the".
Solution (in English):
(Before anyone smarts off, yes, I know the next LINE; isn't strictly necessary.)my @list = <LINES>; LINE: foreach my $line (@list) { if ($line =~ /(^|\s)the(\s|$)/i) { print "$line"; } else { next LINE; } }
See how each numbered part in English corresponds very nicely with the code? Try doing that once or twice for very simple examples and you'll see an immediate improvement in your understand of programming as a discipline.
------
We are the carpenters and bricklayers of the Information Age.
Vote paco for President!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Isn't there a print line function?
by brassmon_k (Sexton) on Sep 04, 2001 at 20:19 UTC |