List Info

Thread: shift/pop like function for a filehandle?




shift/pop like function for a filehandle?
country flaguser name
United States
2008-02-29 10:36:16

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&quot; means wasted time.

Thanks!
Brian

__._,_.___
.

__,_._,___
Re: shift/pop like function for a filehandle?
country flaguser name
United States
2008-02-29 11:03:08

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%40yahoogroups.com">perl-beginneryahoogroups.com, "Brian" <brianlamere...> wrote:
&gt;
> 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:
&gt;
> open (AUDISP, "$audcmd $audfile |") or die "Cannot open $audcmd pipe:
&gt; $!n";
> my $ct = "-1&quot;;
>; $/ = "~&quot; x 105 . "n&quot;;
> 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?
&gt;
> Is that a dumb question? Can be many millions of the loop, and 2
> useless tests times "many millions&quot; means wasted time.
&gt;
> Thanks!
> Brian
&gt;

__._,_.___
.

__,_._,___
Re: Re: shift/pop like function for a filehandle?
country flaguser name
United States
2008-02-29 11:59:20

On Fri, Feb 29, 2008 at 12:03 PM, Brian < brianlamere%40yahoo.com">brianlamereyahoo.com> wrote:
&gt;
> 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&gt;) {
# ...
}

--
[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]

__._,_.___
.

__,_._,___
[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )