Thanks for whose replied especially James, Steven and
Haywood,
 Regarding your suggestions I rewrote my program. Now
it's running much faster.

Ben  

--- "G.W. Haywood" <[EMAIL PROTECTED]> wrote:
> Hi there,
> 
> An Englishman asked an Irishman for directions to a
> place some
> distance away.  The Irishman replied, "T'be sure, if
> oi was going
> there, oi wouldn't start from here!".
> 
> This *is* a bit off-topic, but the guy needs help.
> Press `D' if you're bored already.
> 
> On Sun, 16 Jan 2000, Kader Ben wrote:
> 
> > I want to check if @rec contains the string
> "Unknown" but when I do
> > so the program is very very slow (this process 6M
> file into @rec
> > array). Is there any other away to rewrite this
> code?
> 
> > for ($i = 0; $i < scalar(@rec); $i++) { $rec[$i] =
> '"'.$rec[$i].'"'; }
> > if($rec[16] eq '"Unknown"') {
> Alert_Unknown_ChannelID($rec[0]); }
> > else { my $out = join(',', @rec) . "\n"; print (G
> $out); }
> > }
> 
> I'd really need more to go on than you've given, so
> I'll make some
> wild assumptions, and here goes...
> 
> It's horribly inefficient to read a big file into an
> array with a
> large number of elements only to process it with
> things like:
> 
> $rec[$i] = '"'.$rec[$i].'"';
> 
> Think about what you're asking.  Each element has to
> grow by a couple
> of bytes...
> 
> Maybe you can manipulate smaller chunks of the file?
>  If you must add
> the quotes, do it before the pieces go into the
> array.  If you don't
> need to do any more processing on the array, just
> put the first 16
> elements into it (I assume they're relatively
> small), something like
> the code below.  Process the 16 element array as you
> do now, but deal
> with the remaining input on the fly, without putting
> it in an array.
> Try to use $_ wherever you can.
> 
> I take it you *are* using the `-w' switch and `use
> strict;'?
> 
> 73,
> Ged.
> 
> #!/usr/bin/perl -w
> # Read a file, put quotes around all the lines.
> # You can probably tell I'm really a `C' programmer.
> 
> use strict;
> 
> my @rec=();            # Small array, big file
> my $fileName =
>
"/home/ged/website/input/create/data/input/catalogue.srt";
> 
> open(FD,$fileName);
> 
> # Read first bit of file
> my $i=0;
> while( $rec[$i++]=<FD> ) { last if $i==16; }
> 
> # My file has newlines so chop 'em off before
> wrapping with quotes.
> # More efficient to print this inside the body of
> the while() above,
> # maybe you don't need the array at all...
> for( $i=0; $i<=$#rec; ) { chop($rec[$i]); print
> "\"$rec[$i++]\"\n"; }
> 
> # Announce
> print "***** Here we are at line 16. *****\n";
> 
> # Add quotes on the fly.  O'course we don't have to
> do it at all...
> if( 1 ) { while( <FD> ) { chop; print "\"$_\"\n"; }
> }
> 
> close(FD);
> 
> # EOF: ged.pl
> 
> 
> 
__________________________________________________
Do You Yahoo!?
Talk to your friends online with Yahoo! Messenger.
http://im.yahoo.com

Reply via email to