in reply to Re: Re: split and sysread()
in thread split and sysread()

The issue with the above is it still reads in the file one line at a time, right?.

Wrong! Perl reads from the file in a buffer and only goes back out to disk when the buffer is empty. What <FILEHANDLE> does is read from the buffer up to the newline. I think you are falling prey to premature optimization.

while (<INPUT>) { my @fields = split /\|/ , $_; #Do stuff with particular field }

Cheers - L~R

Update: See this node by chromatic as he was setting me straight on the very same matter

Replies are listed 'Best First'.
Re: Re: Re: Re: split and sysread()
by relaxed137 (Acolyte) on Apr 19, 2003 at 00:32 UTC
    Hmmm... That's what I had before I started to use sysread... I've noticed that sysread will read a file much faster though... Maybe I can make the read buffer bigger instead to tune "while <input>" ?
    open (INFILE, "/sentry/ecisock/ecisock.rpt"); while (<INFILE>) { chomp; ($serverhostname, $execdate, $cicstranid, $sentryapi, $elapsedtime, $errorcode, $corphdr, $channelcode, $clientprodcode, $clientipaddr, $sentrytermid, $signonid, $accountnum, $branch, $campaign, $segment, $custid, $localsysid, $remotesysid, $sentrytarget, $hfb, $sentryver, $corphdrfailreason, $corphdrfailtype, $corphdrbussvc, $corphdrclientcode, $mfcicstasknum, $sentrycicstasknum, $foo1, $foo2, $cpsm)=split(/\|/,$_); ########################################### # Counts total calls ########################################### $totalsentrycalls++; (.. Etcetera ..)
      Just a note: rather than split into a zillion variables, IMO it's more maintainable to list your field names in an array, then split into a hash variable:
      my @fields = qw( serverhostname execdate etc. ); while (<INFILE>) { chomp; my %stuff; @stuff{@fields} = split /\|/; # Easy iteration over fields (e.g. for debugging) print "[$_][$stuff{$_}]\n" for @fields; }