Professional Web Applications Themes

Newbie - skipping lines of a file. - PERL Miscellaneous

[email]tadmcaugustmail.com[/email] (Tad McClellan) writes: > Chris Vidal <cvidalatt.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 ...

  1. #1

    Default Re: Newbie - skipping lines of a file.

    [email]tadmcaugustmail.com[/email] (Tad McClellan) writes:
    > Chris Vidal <cvidalatt.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.
    The irony is that I somehow failed to recognise this as a FAQ! I just
    answered the question patiently without any hostility explaining
    exactly where I suspected the OP's misconception in the meaning of
    'until' lay.
    > (and there is no comp.lang.perl newsgroup, it was removed years ago.)
    For the befefit of on-lookers who can't see non-existant newsgroups,
    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:
    > Yes you are right,
    I said a lot of things. As far as I know all of them were true.
    Without context I have no idea which to refer to.
    > thats why I posted my question here.
    None of the things I said could have accounted for your decision to
    post to a non-existant newsgroup.
    > ...cant figure it out or find a good example.
    I have no idea what you are talking about.
    > I want to skip some lines ...
    This was clear from your original post. And appart from your
    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

  2. #2

    Default Re: Newbie - skipping lines of a file.

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    Brian McCauley <nobullmail.com> wrote in
    news:u9ispvyfxx.fsfwcl-l.bham.ac.uk:
    > Quick staw-poll, does anyone, appart from the OP see that as hostile?
    Nope. And might I add that your posts, Brian, are typically among the most
    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

Similar Threads

  1. Add lines to pages in a file
    By Carlos_Cavazos@adobeforums.com in forum Adobe Acrobat Macintosh
    Replies: 2
    Last Post: December 13th, 07:27 PM
  2. Skipping, Server File is up to date
    By quig06107 in forum Coldfusion - Advanced Techniques
    Replies: 0
    Last Post: March 3rd, 02:49 PM
  3. read lines of file without parsing the lines
    By W. Paulisse in forum PHP Development
    Replies: 3
    Last Post: February 11th, 01:25 AM
  4. skipping lines of input from another program...
    By William M West in forum PERL Beginners
    Replies: 3
    Last Post: February 9th, 05:45 PM
  5. pick N random lines from a file
    By David Garamond in forum PERL Beginners
    Replies: 2
    Last Post: December 10th, 07:27 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139