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

Re: shift/pop like function for a filehandle?

Expand Messages
  • Brian
    as usually happens, I realized a flaw to my question right after I asked it; I can t pop off the last record, because I won t know what it is when the script
    Message 1 of 4 , Feb 29 9:03 AM
    • 0 Attachment
      as usually happens, I realized a flaw to my question right after I
      asked it; I can't pop off the last record, because I won't know what
      it is when the script starts. Duh.

      So, with that said, I'd still like a way to drop that first test. Is
      my best bet to open the handle, read a single loop, then start the
      MAIN loop after that? Or is there an actual function to drop that
      first record?

      Sorry for the extra email :)

      Brian

      --- In perl-beginner@yahoogroups.com, "Brian" <brianlamere@...> wrote:
      >
      > hi - can't find something, hoping someone can help :(
      >
      > Have a record that can be really long (it has reached 10G in the
      > past...) and I need to parse it.
      >
      > here's the basic idea:
      >
      > open (AUDISP, "$audcmd $audfile |") or die "Cannot open $audcmd pipe:
      > $!\n";
      > my $ct = "-1";
      > $/ = "~" x 105 . "\n";
      > MAIN: while (<AUDISP>) {
      > $ct++;
      > next MAIN if ( $ct == 0 );
      > last MAIN unless /\S/;
      >
      >
      > I know the first and last records will be junk, so I don't want to do
      > anything to them. But instead of testing every single loop for
      > whether they are the first or last record, are there pop/shift-like
      > functions for filehandles, such that I could just remove the darn
      > things without a test?
      >
      > Is that a dumb question? Can be many millions of the loop, and 2
      > useless tests times "many millions" means wasted time.
      >
      > Thanks!
      > Brian
      >
    • Jeff Pinyan
      ... The simplest solution is just to read one record first and then enter your loop: open my($fh),
      Message 2 of 4 , Feb 29 9:59 AM
      • 0 Attachment
        On Fri, Feb 29, 2008 at 12:03 PM, Brian <brianlamere@...> wrote:
        >
        > as usually happens, I realized a flaw to my question right after I
        > asked it; I can't pop off the last record, because I won't know what
        > it is when the script starts. Duh.
        >
        > So, with that said, I'd still like a way to drop that first test. Is
        > my best bet to open the handle, read a single loop, then start the
        > MAIN loop after that? Or is there an actual function to drop that
        > first record?

        The simplest solution is just to read one record first and then enter your
        loop:

        open my($fh), "<", $filename or die "can't read $filename: $!";
        <$fh>; # waste a record
        while (<$fh>) {
        # ...
        }

        --
        [Mary said,] "Do whatever he tells you." ~ John 2:5
        The Cross Reference - http://thecrossreference.blogspot.com/
        Nos autem praedicamus Christum crucifixum (1 Cor 1:23)


        [Non-text portions of this message have been removed]
      • Brian
        ... enter your ... perfect, didn t realize it could be done so easily. I m a happier camper Thanks! Brian
        Message 3 of 4 , Feb 29 12:18 PM
        • 0 Attachment
          > The simplest solution is just to read one record first and then
          enter your
          > loop:
          >
          > open my($fh), "<", $filename or die "can't read $filename: $!";
          > <$fh>; # waste a record

          perfect, didn't realize it could be done so easily. I'm a happier camper

          Thanks!
          Brian
        Your message has been successfully submitted and would be delivered to recipients shortly.