Loading ...
Sorry, an error occurred while loading the content.

Delete lines from txt1 until txt2

Expand Messages
  • acummingsus
    Hi, $del = 0, s/^.* n//, if /-- no history end --/; Is it safe to say it like ^^that^^ ? (it works). -- I ve code and __DATA__ enclosed that does the desired
    Message 1 of 9 , Aug 3, 2005
    • 0 Attachment
      Hi,

      $del = 0, s/^.*\n//, if /-- no history end --/;

      Is it safe to say it like ^^that^^ ? (it works).
      --

      I've code and __DATA__ enclosed that does the desired task.

      But I surprised myself that I got it this far without help (except for
      "Perl Cookbook" 2nd edition).

      So I'm also asking if the code that I contrived for this task is
      within reason as far as convention or norm goes (perhaps that's a
      loaded question given Perl's freedom to say it how you want ?). IOW
      how would others approach this task? (I'm aware of the likes of
      File::Tie , Tie::Hash but I may not be advanced skills enough for it
      or Object Oriented) but recommend if you want to.
      --

      I'm deleting the line that contains: -- no history start --

      And then I delete all of the next consecutive lines until: -- no
      history end --

      Finally, I delete the line that contains: -- no history end --

      Those are the only modifications made to DATA which the modified
      version is outputted to a text file.

      #!/usr/bin/perl -w
      use strict;

      # my $old = shift;
      my $del;
      my $new = 'testing.txt';
      # open(OLD, "<", $old) or die "cant open $old: $!";
      open(NEW, ">", $new) or die "cant open $new: $!";
      # while (<OLD>) {
      while (<DATA>) {

      $del = 1 if /-- no history start --/;
      # if (/-- no history start --/) { $del = 1 }

      $del = 0, s/^.*\n//, if /-- no history end --/;
      # if (/-- no history end --/) { $del = 0; s/^.*\n//; }

      next if $del;
      print NEW $_;
      }
      # close(OLD) or die "cant open $old: $!";
      close(DATA) or die "cant close : $!";
      close(NEW) or die "cant close $new: $!";
      # rename($old, "$old.orig") or die "cant rename $old to $old.orig: $!";
      # rename($new, "$old") or die "cant rename $new to $old: $!";

      __DATA__
      ls /root
      pwd
      cp gdm.conf ~/cfg_ac/gdm.conf
      cd ..
      pwd
      ls
      text -- no history start -- more stuff
      cp xorg.conf ~/cfg_ac/xorg.conf
      cp xorg.conf-fbdev ~/cfg_ac/xorg.conf-fbdev
      cp xorg.conf-vesa ~/cfg_ac/xorg.conf-vesa
      here -- no history end -- appended
      cd ..
      pwd
      cp inittab ~/cfg_ac/inittab
      cd rc.d
      pwd
      cp rc.modules ~/cfg_ac/rc.modules
      # end.

      Alan.
    • Damien Carbery
      ... You can use the range operator ( .. or ... ) to achieve the same thing, without having to use a flag variable ($del). Simply change your while loop to:
      Message 2 of 9 , Aug 4, 2005
      • 0 Attachment
        --- In perl-beginner@yahoogroups.com, "acummingsus" <acelists@g...> wrote:
        > Hi,
        >
        > $del = 0, s/^.*\n//, if /-- no history end --/;
        >
        > Is it safe to say it like ^^that^^ ? (it works).
        > --
        >
        > I've code and __DATA__ enclosed that does the desired task.
        >
        > But I surprised myself that I got it this far without help (except for
        > "Perl Cookbook" 2nd edition).
        >
        > So I'm also asking if the code that I contrived for this task is
        > within reason as far as convention or norm goes (perhaps that's a
        > loaded question given Perl's freedom to say it how you want ?). IOW
        > how would others approach this task? (I'm aware of the likes of
        > File::Tie , Tie::Hash but I may not be advanced skills enough for it
        > or Object Oriented) but recommend if you want to.
        > --
        >
        > I'm deleting the line that contains: -- no history start --
        >
        > And then I delete all of the next consecutive lines until: -- no
        > history end --
        >
        > Finally, I delete the line that contains: -- no history end --
        >
        > Those are the only modifications made to DATA which the modified
        > version is outputted to a text file.
        >
        > #!/usr/bin/perl -w
        > use strict;
        >
        > # my $old = shift;
        > my $del;
        > my $new = 'testing.txt';
        > # open(OLD, "<", $old) or die "cant open $old: $!";
        > open(NEW, ">", $new) or die "cant open $new: $!";
        > # while (<OLD>) {
        > while (<DATA>) {
        >
        > $del = 1 if /-- no history start --/;
        > # if (/-- no history start --/) { $del = 1 }
        >
        > $del = 0, s/^.*\n//, if /-- no history end --/;
        > # if (/-- no history end --/) { $del = 0; s/^.*\n//; }
        >
        > next if $del;
        > print NEW $_;
        > }
        > # close(OLD) or die "cant open $old: $!";
        > close(DATA) or die "cant close : $!";
        > close(NEW) or die "cant close $new: $!";
        > # rename($old, "$old.orig") or die "cant rename $old to $old.orig: $!";
        > # rename($new, "$old") or die "cant rename $new to $old: $!";
        >
        > __DATA__
        > ls /root
        > pwd
        > cp gdm.conf ~/cfg_ac/gdm.conf
        > cd ..
        > pwd
        > ls
        > text -- no history start -- more stuff
        > cp xorg.conf ~/cfg_ac/xorg.conf
        > cp xorg.conf-fbdev ~/cfg_ac/xorg.conf-fbdev
        > cp xorg.conf-vesa ~/cfg_ac/xorg.conf-vesa
        > here -- no history end -- appended
        > cd ..
        > pwd
        > cp inittab ~/cfg_ac/inittab
        > cd rc.d
        > pwd
        > cp rc.modules ~/cfg_ac/rc.modules
        > # end.
        >
        > Alan.

        You can use the range operator (".." or "...") to achieve the same
        thing, without having to use a flag variable ($del).
        Simply change your 'while' loop to:

        while (<DATA>) {
        # Skip lines between 'no history start' and 'end'
        next if ( /-- no history start --/ .. /-- no history end --/ );
        print NEW; # '$_' is implied.
        }

        Aside: don't forget to add error checking to ensure that the files
        were successfully opened.

        Mmm, gdm and xorg - a nice can of worms from an accessibility
        perspective (I work with the developers of GOK, gnopernicus and other
        a11y apps).
      • acummingsus
        ... wrote: [snip ] ... $old.orig: $! ; ... Works fine! I had then soon raised the bar which (may) bring another question. A bit more complexity: (in
        Message 3 of 9 , Aug 5, 2005
        • 0 Attachment
          --- In perl-beginner@yahoogroups.com, "Damien Carbery"
          <daymobrew@y...> wrote:
          > --- In perl-beginner@yahoogroups.com, "acummingsus" <acelists@g...>
          wrote:
          [snip ]
          > > #!/usr/bin/perl -w
          > > use strict;
          > >
          > > # my $old = shift;
          > > my $del;
          > > my $new = 'testing.txt';
          > > # open(OLD, "<", $old) or die "cant open $old: $!";
          > > open(NEW, ">", $new) or die "cant open $new: $!";
          > > # while (<OLD>) {
          > > while (<DATA>) {
          > >
          > > $del = 1 if /-- no history start --/;
          > > # if (/-- no history start --/) { $del = 1 }
          > >
          > > $del = 0, s/^.*\n//, if /-- no history end --/;
          > > # if (/-- no history end --/) { $del = 0; s/^.*\n//; }
          > >
          > > next if $del;
          > > print NEW $_;
          > > }
          > > # close(OLD) or die "cant open $old: $!";
          > > close(DATA) or die "cant close : $!";
          > > close(NEW) or die "cant close $new: $!";
          > > # rename($old, "$old.orig") or die "cant rename $old to
          $old.orig: $!";
          > > # rename($new, "$old") or die "cant rename $new to $old: $!";
          > >
          > > __DATA__
          > > ls /root
          > > pwd
          > > cp gdm.conf ~/cfg_ac/gdm.conf
          > > cd ..
          > > pwd
          > > ls
          > > text -- no history start -- more stuff
          > > cp xorg.conf ~/cfg_ac/xorg.conf
          > > cp xorg.conf-fbdev ~/cfg_ac/xorg.conf-fbdev
          > > cp xorg.conf-vesa ~/cfg_ac/xorg.conf-vesa
          > > here -- no history end -- appended
          > > cd ..
          > > pwd
          > > cp inittab ~/cfg_ac/inittab
          > > cd rc.d
          > > pwd
          > > cp rc.modules ~/cfg_ac/rc.modules
          > > # end.
          > >
          > > Alan.
          >
          > You can use the range operator (".." or "...") to achieve the same
          > thing, without having to use a flag variable ($del).
          > Simply change your 'while' loop to:
          >
          > while (<DATA>) {
          > # Skip lines between 'no history start' and 'end'
          > next if ( /-- no history start --/ .. /-- no history end --/ );
          > print NEW; # '$_' is implied.
          > }
          >
          > Aside: don't forget to add error checking to ensure that the files
          > were successfully opened.

          Works fine! I had then soon raised the bar which (may) bring another
          question.

          A bit more complexity: (in __DATA__) From begin of html markup
          through and including the last line which has html markup in it, I
          need to keep.

          The next, below enclosed code does what I need to do. But I didn't
          know how else to do it except to bring back in the use of a flag variable.

          By my commented "next unless" line it can be seen that I tried "this |
          that" in match along with "$firstline .." and it didn't work (I don't
          know why that did not work).

          Comments? Suggestions?

          #!/usr/bin/perl -w
          use strict;

          # my $old = shift;
          my $del = 1;
          my $htm_end_line;
          my $new = 'testing.txt';
          # open(OLD, "<", $old) or die "cant open $old: $!";
          open(NEW, ">", $new) or die "cant open $new: $!";
          # while (<OLD>) {
          # my $firstLine = <DATA>;
          while (<DATA>) {
          $del = 0 if /<\!DOCTYPE html |<html>/; # rids of junk pre the html

          # $del = 1 if /-- no history start --/;
          # if (/-- no history start --/) { $del = 1 }

          # $del = 1, $htm_tag = $_, if /<\/html>/;
          # next unless /$firstLine .. <\!DOCTYPE html |<html>/;
          $htm_end_line = $_ if /<\/html>/; # line along_with/includes </html>
          next if /<\/html>/ .. eof; # rids of junk after the </html> tag
          next if $del;
          print NEW;
          }
          print NEW $htm_end_line;
          # close(OLD) or die "cant open $old: $!";
          close(DATA) or die "cant close : $!";
          close(NEW) or die "cant close $new: $!";

          __DATA__
          junk ls /root
          junk pwd
          text -- no history start -- more stuff
          junk cp gdm.conf ~/cfg_ac/gdm.conf
          junk cd ..
          here -- no history end -- appended
          junk pwd
          junk ls no_junk begins next line
          <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
          <html><head><title>title_here</title><meta name="stuff" />
          </head><body>
          cp xorg.conf ~/cfg_ac/xorg.conf
          cp xorg.conf-fbdev ~/cfg_ac/xorg.conf-fbdev
          cp xorg.conf-vesa ~/cfg_ac/xorg.conf-vesa
          </body></html>
          junk, here to eof cd ..
          pwd
          text -- no history start -- more stuff
          junk line 1
          junk line 2
          here -- no history end -- appended
          pwd
          cp rc.modules ~/cfg_ac/rc.modules
          # end

          > Mmm, gdm and xorg - a nice can of worms from an accessibility
          > perspective (I work with the developers of GOK, gnopernicus and other
          > a11y apps).

          Not familiar with those ally I'll have to check 'em out.

          Saved a copy of my Slackware 10.1 config files. May switch to kdm,
          may not. I don't need accessibility. Got gdm to auto log me on (at
          home) gdm offers a higher number of window managers to load than kdm
          (out of the box Slack 10.1) But it just now dawned on me that might
          could add more choices to kdm menu (edit the menu, maybe can do).

          Alan.
        • acummingsus
          ... [ snip ] ... [snip] ... while ( ) { print NEW if / /i; next if $. == 1 .. / /i; # rids of junk pre the
          Message 4 of 9 , Aug 7, 2005
          • 0 Attachment
            --- In perl-beginner@yahoogroups.com, "acummingsus" <acelists@g...> wrote:
            > --- In perl-beginner@yahoogroups.com, "Damien Carbery"
            > <daymobrew@y...> wrote:
            > > --- In perl-beginner@yahoogroups.com, "acummingsus" <acelists@g...>
            > wrote:
            > [snip ]
            > > > #!/usr/bin/perl -w
            [ snip ]
            > > You can use the range operator (".." or "...") to achieve the same
            > > thing, without having to use a flag variable ($del).
            [snip]
            > #!/usr/bin/perl -w
            > use strict;
            >
            > # my $old = shift;
            > my $del = 1;
            > my $htm_end_line;
            > my $new = 'testing.txt';
            > # open(OLD, "<", $old) or die "cant open $old: $!";
            > open(NEW, ">", $new) or die "cant open $new: $!";
            > # while (<OLD>) {
            > # my $firstLine = <DATA>;
            > while (<DATA>) {
            > $del = 0 if /<\!DOCTYPE html |<html>/; # rids of junk pre the html
            >
            > # $del = 1 if /-- no history start --/;
            > # if (/-- no history start --/) { $del = 1 }
            >
            > # $del = 1, $htm_tag = $_, if /<\/html>/;
            > # next unless /$firstLine .. <\!DOCTYPE html |<html>/;
            > $htm_end_line = $_ if /<\/html>/; # line along_with/includes </html>
            > next if /<\/html>/ .. eof; # rids of junk after the </html> tag
            > next if $del;
            > print NEW;
            > }
            > print NEW $htm_end_line;
            > # close(OLD) or die "cant open $old: $!";
            > close(DATA) or die "cant close : $!";
            > close(NEW) or die "cant close $new: $!";
            >
            > __DATA__
            > junk cd ..
            > here -- no history end -- appended
            > junk pwd
            > junk ls no_junk begins next line
            > <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
            > <html><head><title>title_here</title><meta name="stuff" />
            > </head><body>
            > cp xorg.conf ~/cfg_ac/xorg.conf
            > cp xorg.conf-fbdev ~/cfg_ac/xorg.conf-fbdev
            > cp xorg.conf-vesa ~/cfg_ac/xorg.conf-vesa
            > </body></html>
            > junk, here to eof cd ..
            > pwd
            > text -- no history start -- more stuff

            while (<DATA>) {
            print NEW if /<\!DOCTYPE html |<html>/i;
            next if "$." == 1 .. /<\!DOCTYPE html |<html>/i; # rids of junk pre
            the html
            print NEW if /<\/html>/i;
            next if /<\/html>/i .. eof; # rids of junk after the </html> tag
            print NEW;
            }

            A bit more hacking and I came up with that as the next revision/version.

            It works either with or without the double quotes surrounding the $.
            variable.

            And I have no idea which of the two, with or without quotes, may be
            more appropriate.
            --

            FWIW
            http://www.perl.com/pub/a/2004/06/18/variables.html

            near 1/3 of the way down the page:

            while (<FILE>) {
            if (/!! START !!/ .. /!! END !!/) {
            # process line
            }
            }

            That article calls it the flip flop operator rather than the range
            operator. And uses a regex on both sides of the range operator (two
            regex) rather than using only one regex with the range operator inside
            of that one regex. Maybe (maybe not) I mistakenly thought it worked
            at one point like this latter mentioned.

            Alan.
          • Damien Carbery
            ... Alan, Why didn t you just expand on the code I provided? You ve even seen similar code in the perl.com article. I simplified your while loop to: while
            Message 5 of 9 , Aug 7, 2005
            • 0 Attachment
              --- In perl-beginner@yahoogroups.com, "acummingsus" <acelists@g...> wrote:
              > --- In perl-beginner@yahoogroups.com, "acummingsus" <acelists@g...>
              wrote:
              > > --- In perl-beginner@yahoogroups.com, "Damien Carbery"
              > > <daymobrew@y...> wrote:
              > > > --- In perl-beginner@yahoogroups.com, "acummingsus" <acelists@g...>
              > > wrote:
              > > [snip ]
              > > > > #!/usr/bin/perl -w
              > [ snip ]
              > > > You can use the range operator (".." or "...") to achieve the same
              > > > thing, without having to use a flag variable ($del).
              > [snip]
              > > #!/usr/bin/perl -w
              > > use strict;
              > >
              > > # my $old = shift;
              > > my $del = 1;
              > > my $htm_end_line;
              > > my $new = 'testing.txt';
              > > # open(OLD, "<", $old) or die "cant open $old: $!";
              > > open(NEW, ">", $new) or die "cant open $new: $!";
              > > # while (<OLD>) {
              > > # my $firstLine = <DATA>;
              > > while (<DATA>) {
              > > $del = 0 if /<\!DOCTYPE html |<html>/; # rids of junk pre the html
              > >
              > > # $del = 1 if /-- no history start --/;
              > > # if (/-- no history start --/) { $del = 1 }
              > >
              > > # $del = 1, $htm_tag = $_, if /<\/html>/;
              > > # next unless /$firstLine .. <\!DOCTYPE html |<html>/;
              > > $htm_end_line = $_ if /<\/html>/; # line along_with/includes </html>
              > > next if /<\/html>/ .. eof; # rids of junk after the </html> tag
              > > next if $del;
              > > print NEW;
              > > }
              > > print NEW $htm_end_line;
              > > # close(OLD) or die "cant open $old: $!";
              > > close(DATA) or die "cant close : $!";
              > > close(NEW) or die "cant close $new: $!";
              > >
              > > __DATA__
              > > junk cd ..
              > > here -- no history end -- appended
              > > junk pwd
              > > junk ls no_junk begins next line
              > > <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
              > > <html><head><title>title_here</title><meta name="stuff" />
              > > </head><body>
              > > cp xorg.conf ~/cfg_ac/xorg.conf
              > > cp xorg.conf-fbdev ~/cfg_ac/xorg.conf-fbdev
              > > cp xorg.conf-vesa ~/cfg_ac/xorg.conf-vesa
              > > </body></html>
              > > junk, here to eof cd ..
              > > pwd
              > > text -- no history start -- more stuff
              >
              > while (<DATA>) {
              > print NEW if /<\!DOCTYPE html |<html>/i;
              > next if "$." == 1 .. /<\!DOCTYPE html |<html>/i; # rids of junk pre
              > the html
              > print NEW if /<\/html>/i;
              > next if /<\/html>/i .. eof; # rids of junk after the </html> tag
              > print NEW;
              > }
              >
              > A bit more hacking and I came up with that as the next revision/version.
              >
              > It works either with or without the double quotes surrounding the $.
              > variable.
              >
              > And I have no idea which of the two, with or without quotes, may be
              > more appropriate.
              > --
              >
              > FWIW
              > http://www.perl.com/pub/a/2004/06/18/variables.html
              >
              > near 1/3 of the way down the page:
              >
              > while (<FILE>) {
              > if (/!! START !!/ .. /!! END !!/) {
              > # process line
              > }
              > }
              >
              > That article calls it the flip flop operator rather than the range
              > operator. And uses a regex on both sides of the range operator (two
              > regex) rather than using only one regex with the range operator inside
              > of that one regex. Maybe (maybe not) I mistakenly thought it worked
              > at one point like this latter mentioned.
              >
              > Alan.

              Alan,

              Why didn't you just expand on the code I provided? You've even seen
              similar code in the perl.com article.

              I simplified your while loop to:

              while (<DATA>) {
              print NEW if /<\!DOCTYPE html/ .. /<\/html>/;
              }

              and this works.
            • acummingsus
              ... [ snip ] ... [ snip ] ... [ snip ] ... No, I did not see similar code at perl.com. And, as next, without having learned what the limits
              Message 6 of 9 , Aug 8, 2005
              • 0 Attachment
                --- In perl-beginner@yahoogroups.com, "Damien Carbery"
                <daymobrew@y...> wrote:
                > --- In perl-beginner@yahoogroups.com, "acummingsus" <acelists@g...>
                wrote:
                > > --- In perl-beginner@yahoogroups.com, "acummingsus" <acelists@g...>
                > wrote:
                > > > --- In perl-beginner@yahoogroups.com, "Damien Carbery"
                > > > <daymobrew@y...> wrote:
                > > > > --- In perl-beginner@yahoogroups.com, "acummingsus"
                <acelists@g...>
                [ snip ]
                > > while (<DATA>) {
                > > print NEW if /<\!DOCTYPE html |<html>/i;
                > > next if "$." == 1 .. /<\!DOCTYPE html |<html>/i; # rids of junk pre
                > > the html
                > > print NEW if /<\/html>/i;
                > > next if /<\/html>/i .. eof; # rids of junk after the </html> tag
                > > print NEW;
                > > }
                [ snip ]
                > > FWIW
                > > http://www.perl.com/pub/a/2004/06/18/variables.html
                [ snip ]
                > Alan,
                >
                > Why didn't you just expand on the code I provided? You've even seen
                > similar code in the perl.com article.
                >
                > I simplified your while loop to:
                >
                > while (<DATA>) {
                > print NEW if /<\!DOCTYPE html/ .. /<\/html>/;
                > }
                >
                > and this works.

                No, I did not see similar code at perl.com. And, as next, without
                having learned what the limits are, I'm supposed to just know (what
                they are)?

                To answer your first ques: due to my thinking pattern of which to keep
                testing of condition to a minimum. ie there's very significantly less
                junk text to (test for) and not print versus there's very
                significantly more including the entire html markup and page content
                to (test for) and print.

                Evidently I'm not only a beginner but also a (I do happen to be a
                handicapped learner) who doesn't know which and/or what falls within a
                parameter constituting what is *reasonable* and/or what is OK and/or
                when enough is enough as far as (my trying to get) efficiency of
                design is concerned regarding my making choice(s).

                And, I did not see similar code in the perl.com article. I read
                portions of the article. And I saw:

                {
                # process line
                }

                which does not indicate that it is an ok design thing to continuously
                test and to print to NEW if within range of begin to end of html
                markup (97% of the file's content fits within such a range, some files
                may be a bit large. And I also do/did not know what might happen with
                ram/memory consumption).

                And now it's likely that you know where I came from. But if
                understanding remains/continues as lacking, just query again.

                Alan.
              • Damien Carbery
                ... The # process line code does not imply anything about the surrounding code. In fact, as the article was on perl.com I think it is reasonably safe to
                Message 7 of 9 , Aug 8, 2005
                • 0 Attachment
                  --- In perl-beginner@yahoogroups.com, "acummingsus" <acelists@g...> wrote:
                  > [ snip ]
                  > > > FWIW
                  > > > http://www.perl.com/pub/a/2004/06/18/variables.html
                  > [ snip ]
                  > > Alan,
                  > >
                  > > Why didn't you just expand on the code I provided? You've even
                  > > seen similar code in the perl.com article.
                  > >
                  > > I simplified your while loop to:
                  > >
                  > > while (<DATA>) {
                  > > print NEW if /<\!DOCTYPE html/ .. /<\/html>/;
                  > > }
                  > >
                  > > and this works.
                  >
                  > No, I did not see similar code at perl.com. And, as next, without
                  > having learned what the limits are, I'm supposed to just know (what
                  > they are)?
                  >
                  > To answer your first ques: due to my thinking pattern of which to keep
                  > testing of condition to a minimum. ie there's very significantly less
                  > junk text to (test for) and not print versus there's very
                  > significantly more including the entire html markup and page content
                  > to (test for) and print.
                  >
                  > Evidently I'm not only a beginner but also a (I do happen to be a
                  > handicapped learner) who doesn't know which and/or what falls within a
                  > parameter constituting what is *reasonable* and/or what is OK and/or
                  > when enough is enough as far as (my trying to get) efficiency of
                  > design is concerned regarding my making choice(s).
                  >
                  > And, I did not see similar code in the perl.com article. I read
                  > portions of the article. And I saw:
                  >
                  > {
                  > # process line
                  > }
                  >
                  > which does not indicate that it is an ok design thing to continuously
                  > test and to print to NEW if within range of begin to end of html
                  > markup (97% of the file's content fits within such a range, some files
                  > may be a bit large. And I also do/did not know what might happen with
                  > ram/memory consumption).
                  >
                  > And now it's likely that you know where I came from. But if
                  > understanding remains/continues as lacking, just query again.
                  >
                  > Alan.

                  The "# process line" code does not imply anything about the
                  surrounding code. In fact, as the article was on perl.com I think it
                  is reasonably safe to assume that the presented code is good practice.

                  If you are reading data line by line each line will have to be
                  continuously tested, regardless of what method you use - a flag
                  variable or the flip-flop operator.

                  If I rewrite the while loop like:
                  while (<DATA>) {
                  if /<\!DOCTYPE html/ .. /<\/html>/ {
                  print NEW $_;
                  }
                  }
                  do you see it looking like the example code in the perl.com article?

                  As the code is only reading one line at a time the memory usage is
                  small (vs reading the entire file).
                  You could always try the code I presented and see if it works for you.
                  If it doesn't then come back to the group with the errors.

                  > And, as next, without having learned what the limits are, I'm
                  > supposed to just know (what they are)?
                  I didn't understand this sentence/question.
                  Are you asking about the limits of what constitutes html?
                  Or CPU/RAM limits?
                  Something entirely different?
                • acummingsus
                  ... [ snip ] ... [ snip ] ... I was already aware that process line didn t imply anything about surrounding code. ... flag versus flip flop was not part of
                  Message 8 of 9 , Aug 8, 2005
                  • 0 Attachment
                    --- In perl-beginner@yahoogroups.com, "Damien Carbery"
                    <daymobrew@y...> wrote:
                    > --- In perl-beginner@yahoogroups.com, "acummingsus" <acelists@g...>
                    wrote:
                    > > [ snip ]
                    > > > > FWIW
                    [ snip ]
                    > > And, I did not see similar code in the perl.com article. I read
                    > > portions of the article. And I saw:
                    > >
                    > > {
                    > > # process line
                    > > }
                    [ snip ]
                    > The "# process line" code does not imply anything about the
                    > surrounding code. In fact, as the article was on perl.com I think it
                    > is reasonably safe to assume that the presented code is good practice.

                    I was already aware that "process line" didn't imply anything about
                    surrounding code.
                    >
                    > If you are reading data line by line each line will have to be
                    > continuously tested, regardless of what method you use - a flag
                    > variable or the flip-flop operator.

                    flag versus flip flop was not part of my concern.

                    I formerly had incorrectly thought that *with two flip flops*, one for
                    top of doc and the other for bottom of doc, once the top of doc flip
                    flop had completed its task that this flip flop then *no longer
                    tested*. But now I see that's not true (about the testing) I now see
                    that it continues to test but that in the way I had been using it
                    *it_no_longer_found_a_2nd_area/range_that_match*

                    >
                    > If I rewrite the while loop like:
                    > while (<DATA>) {
                    > if /<\!DOCTYPE html/ .. /<\/html>/ {
                    > print NEW $_;
                    > }
                    > }
                    > do you see it looking like the example code in the perl.com article?

                    Not at all a part of my concern. That's about two different coding
                    styles, that's all. My concern had nothing to do with two different
                    ways to say the same thing in Perl. I had already understood that.

                    Once again, as I formerly said: my concern was over # 1. to test to
                    leave out (not print) versus instead # 2. to test to retain (what to
                    print)

                    perl.com did not have or it was in the part I didn't read:

                    print NEW $_;

                    instead perl.com have:

                    {
                    # process line
                    }

                    (which is not a specific example).

                    NOW I understand about the testing. And also evidently that a huge
                    range (nearly top to bottom of sometimes a big doc) is an OK thing to do.

                    VERY key: I missed it and/or I doubt whether it said that at perl.com
                    article about: do not concern yourself with the size/extent of the
                    number of lines being tested *that_match* within a range (as well as
                    why it is so)

                    >
                    > As the code is only reading one line at a time the memory usage is
                    > small (vs reading the entire file).
                    > You could always try the code I presented and see if it works for you.
                    > If it doesn't then come back to the group with the errors.

                    I'm sure it works fine or you wouldn't have shared it.

                    >
                    > > And, as next, without having learned what the limits are, I'm
                    > > supposed to just know (what they are)?
                    > I didn't understand this sentence/question.
                    > Are you asking about the limits of what constitutes html?
                    > Or CPU/RAM limits?
                    > Something entirely different?

                    You snipped or changed its order. It was at the top.

                    And, at the top stuff usually consists of an introduction, a lead into
                    (lead up to the main material) if you will. It was meant as a short
                    synopsis of what's to come. Sorry for not labeling it so as well as
                    not being specific about what sort of limit did I mean.

                    For starters, *limit* in that case, once again, had to do with: # 1.
                    to test to leave out (not print) versus instead # 2. to test to
                    retain (what to print).

                    My main concern # 1: Further, (this *IS* the key item, it's the limit
                    I was unaware whether existed or not) this *limit* applies to the
                    size/extent of a range as in how many tested lines match and thus fits
                    within this range.

                    My main concern # 2: Moreover, whatever keeps track of the range must
                    consume but little or negligible (very teency) resource. It is so
                    because when the range grows to nearly 96% of an entire doc before the
                    match at the end of the range happens.

                    So, THAT is both what got me and what I had not known about which is
                    if there is a *limit* to the size of how large (how many tested and
                    matched lines) can, is OK to fit within a range. (and if it's worthy
                    to keep the range small, ie use two smaller of them ranges instead of
                    one huge range) (but NOW I know better about thewhole thing ie a huge
                    range is OK)

                    Thus my two flip flops, each with only nearly 7 tested lines in them
                    that match (as opposed to several hundred or more lines that match
                    using one flip flop).

                    So, the *limit* in this case does not exist. There is no limiting
                    size one should keep within as far as how many tested lines do match
                    and fit within this range.(unless an expert corrects me)

                    Alan.
                  • acummingsus
                    About the range a.k.a. flip flop operator: Since I was using it in a scalar context it appears to me now that all that it does in that case is to flip flop
                    Message 9 of 9 , Aug 8, 2005
                    • 0 Attachment
                      About the range a.k.a. "flip flop" operator:

                      Since I was using it in a scalar context it appears to me now that all
                      that it does in that case is to flip flop from the first item to the
                      second item.

                      It appears also that true or false being returned is all that we are
                      working with here (and that according to whether true or false then
                      either the line in question gets processed or it does not get processed).

                      So it NOW appears that there is nothing to keep track of as far as it
                      recording how big the range gets before that range matches its item
                      that closes or otherwise makes happen the end of range.

                      It also NOW appears that the term "range" ended up aiding to, at least
                      at first, misguide/confuse this newbie.

                      It also NOW appears that when used in scalar context, a "range" is an
                      actual by product or otherwise the outcome that gets produced from the
                      flip flop action and the aforementioned true or false returned.

                      The perl.com article

                      http://www.perl.com/pub/a/2004/06/18/variables.html

                      did not mention that: some people, when first introduced to the range
                      operator, mistakenly latch onto the term "range" which may result in
                      such an individual groping about, trying to find out about what
                      constitutes its appropriate useage. But in a scalar context the only
                      correct useage of this operator is to use it since any so called range
                      constitutes the output that arises from the combination of flip flop
                      and true -- false.

                      ^^THAT^^ or similar is what I needed. NOT the perl.com article. NOT
                      being referenced to that article. NOT a pondering of why didn't I
                      simply do so and so. But, all of this is OK given a truly interested
                      in really why, finding out WHY. Hopefully I have shared clearly
                      enough so that it is now known as far as the answers to the why queries.

                      Perhaps it's in the docs somewhere. Perhaps not.

                      When I learn, I need to (correctly) understand the underlying
                      mechanisms involved.

                      Alan.
                    Your message has been successfully submitted and would be delivered to recipients shortly.