Ask a Question related to PERL Miscellaneous, Design and Development.
-
Brian McCauley #1
Re: Newbie - skipping lines of a file.
[email]tadmc@augustmail.com[/email] (Tad McClellan) writes:
The irony is that I somehow failed to recognise this as a FAQ! I just> Chris Vidal <cvidal@att.com> wrote:> ^^^^^ ^^^^^^^^^^> > If I had the file named tfile.
> >
> > AAA
> > BBB
> > CCC
> > DDD
> > aaa
> > bbb
> > ccc
> > ddd
> > eee
> > fffff
> >
> > sed '/AAA/,/DDD/d' tfile would delete AAA, BBB, CCC, DDD
> >
> > How would I do this using perl until loop structure.
>
> I don't know how to do it that way.
>
> I know how to do it some other way though...
>
>>> > I posted this question on comp.lang.perl and got a hostile response.
>
> That type of response should be expected when you post a
> Frequently Asked Question.
answered the question patiently without any hostility explaining
exactly where I suspected the OP's misconception in the meaning of
'until' lay.
For the befefit of on-lookers who can't see non-existant newsgroups,> (and there is no comp.lang.perl newsgroup, it was removed years ago.)
here is my so-called "hostile" response:
You have misunderstood what until means in Perl.
until (EXPR) {BLOCK}
is a _looping_ construct.
_Each_ time the above is executed it will repeatedly do BLOCK until
EXPR is true. If BLOCK cannot make EXPR become false and does not
break out of the loop by some other means then this is an infinite
loop.
You you evidently believe until is a simple negated condition with
memory. i.e. it does something once each time it is executed until
some condition is true and thereafter never does it again.
In Perl that would be written:
unless ( EXPR .. 1 == 0 ) { BLOCK }
Also you want the 'next' to go to the next line, i.e. the next
iteration of the while loop. But by default it goes to the next
iteration of the inner-most looping construct (the until). You could
get around this by labling your loops (see perldoc -f next).
But, of course, you didn't want the inner loop at all.
This newsgroup does not exist (see FAQ). Please do not start threads
here.
Quick staw-poll, does anyone, appart from the OP see that as hostile?
That didn't seem to be enough for the OP so he spat TOFU in my face.
Obviously this would put me in a hostile frame of mind but I think I
controlled my hostility quite well and went on calmly to explain:
I said a lot of things. As far as I know all of them were true.> Yes you are right,
Without context I have no idea which to refer to.
None of the things I said could have accounted for your decision to> thats why I posted my question here.
post to a non-existant newsgroup.
I have no idea what you are talking about.> ...cant figure it out or find a good example.
This was clear from your original post. And appart from your> I want to skip some lines ...
confusion about 'until' and 'unless' you were basically doing it right
(i.e. using 'next') in your OP. Now I've cleared that up your code
would almost work (except it would include in the output the line that
triggered the state change).
The obvious way to avoid that just to spell it out:
use strict;
use warnings;
my $seen_trigger;
while (<>) {
unless ( $seen_trigger ) {
$seen_trigger = /PATTERN/;
next;
} print;
}
If you still have a problem then I suggest you produce another minimal
but complete script that illustrates your problem (see posting
guidelines in comp.lang.perl.misc) and post it to that newsgroup
because this one does not exist (see FAQ).
If someone tries to help do not insult them by spitting TOFU in their
faces (see guidelines). Doing so will rapidly exhaust your quota of
good-will.
So not only is the OP asking a FAQ. He's also asking a question that
has already been answered for him personally. He also, despite being
advised to check the guidelines _and_ explicitly being advised to
include a minimal but complete example script, failed to include such
a script.
Plonkers take note!
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
Brian McCauley Guest
-
Add lines to pages in a file
Ok, I've heard that I can do this with templates. But I'm not sure how to do this. Here is what I want to have. I have a PDF with several pages. Each... -
Skipping, Server File is up to date
I am new to Visual SourceSafe and have set it up according to the documentation I could find on Macromedia. I'm having major difficulties getting... -
read lines of file without parsing the lines
Hello! Currently i have a logfile which tracks a certain feature on my server. Every time the feature accurs my script appends a line in the... -
skipping lines of input from another program...
the following is my script that i am working on- it fails to do quite the right thing.. qouting from one of the comments below:: "#skip_lines()... -
pick N random lines from a file
I'm trying to extend the Perl cookbook recipe on how to pick a random line from a file: #!/usr/bin/perl rand($.) < 1 && ($line = $_) while <>;... -
Eric J. Roode #2
Re: Newbie - skipping lines of a file.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Brian McCauley <nobull@mail.com> wrote in
news:u9ispvyfxx.fsf@wcl-l.bham.ac.uk:
Nope. And might I add that your posts, Brian, are typically among the most> Quick staw-poll, does anyone, appart from the OP see that as hostile?
cordial and patient of all the regular posters.
- --
Eric
$_ = reverse sort qw p ekca lre Js reh ts
p, $/.r, map $_.$", qw e p h tona e; print
-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>
iQA/AwUBPxyDHmPeouIeTNHoEQIfxgCgyknExNMUpClFggBcO8To7k baHsAAoO9m
AhgXq0V5wE7ylQXbGwbthjAX
=HGVe
-----END PGP SIGNATURE-----
Eric J. Roode Guest



Reply With Quote

