wileykt has asked for the wisdom of the Perl Monks concerning the following question:
I want to grep for errors in the file before the transmission starts, so I thought about writing a sub that looks almost like the main above, by reading in each files lines to an array, then grepping the array. If I find errors, I'll move the file to another directory so it can't be sent. My question is, this seems like alot of extra work to go through to do this, is there another way to search a file all at once before I open it in the above code to start the send process?for (;;) { while (readdir OMSSEND) { @conffiles = grep { !/^\./ } readdir(OMSSEND); } foreach $file (@conffiles) { open FILE, "$senddir" . "/" . "$file" or die "Can't open: $!"; $server = IO::Socket::INET->new( PeerAddr => whatever, PeerPort => 11, Proto => 'tcp') or die "Can't connect to ..."; print $server $stx . $padsize or die "Can't send to server $!"; while (<FILE>) { print $server $_ or die "Can't send to server $!"; } close FILE;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Grep file before sending through socket
by dws (Chancellor) on Dec 08, 2001 at 01:55 UTC | |
by wileykt (Acolyte) on Dec 11, 2001 at 20:46 UTC | |
by dws (Chancellor) on Dec 11, 2001 at 22:45 UTC | |
|
Re: Grep file before sending through socket
by DrManhattan (Chaplain) on Dec 08, 2001 at 04:39 UTC |