[32659] in Perl-Users-Digest
Perl-Users Digest, Issue: 3935 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Apr 27 14:09:27 2013
Date: Sat, 27 Apr 2013 11:09:08 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sat, 27 Apr 2013 Volume: 11 Number: 3935
Today's topics:
Re: Ascertaing uploaded file size <dave@invalid.invalid>
Re: Ascertaing uploaded file size <Joey@still_Learning.invalid>
Re: Ascertaing uploaded file size <ben@morrow.me.uk>
Re: Ascertaing uploaded file size <Joey@still_Learning.invalid>
Re: Ascertaing uploaded file size <dave@invalid.invalid>
Re: Ascertaing uploaded file size <ben@morrow.me.uk>
Re: Ascertaing uploaded file size <jurgenex@hotmail.com>
Re: Ascertaing uploaded file size <rweikusat@mssgmbh.com>
Re: Ascertaing uploaded file size <ben@morrow.me.uk>
Re: Ascertaing uploaded file size <dave@invalid.invalid>
Re: Ascertaing uploaded file size <Joey@still_Learning.invalid>
Re: Is Perl dying or not? <nospam.gravitalsun.antispam@spamno.hotmail.anispam.com.nospam>
nice parallel file reading <nospam.gravitalsun.antispam@spamno.hotmail.anispam.com.nospam>
Re: nice parallel file reading <nospam.gravitalsun.antispam@spamno.hotmail.anispam.com.nospam>
Re: nice parallel file reading <jurgenex@hotmail.com>
Re: nice parallel file reading <hjp-usenet3@hjp.at>
Re: nice parallel file reading <jurgenex@hotmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 26 Apr 2013 16:59:10 +0000 (UTC)
From: "Dave Saville" <dave@invalid.invalid>
Subject: Re: Ascertaing uploaded file size
Message-Id: <fV45K0OBJxbE-pn2-G754MgpjtHNc@paddington.bear.den>
On Fri, 26 Apr 2013 14:04:54 UTC, Ben Morrow <ben@morrow.me.uk> wrote:
><snip>
> That affects more than just CGI.pm. The CGI.pm documentation (version
> 3.59) says
>
> | The temporary directory is selected using the following algorithm:
> |
> | 1. if $CGITempFile::TMPDIRECTORY is already set, use that
> |
> | 2. if the environment variable TMPDIR exists, use the location
> | indicated.
> |
> | 3. Otherwise try the locations /usr/tmp, /var/tmp, C:\temp,
> | /tmp, /temp, ::Temporary Items, and \WWW_ROOT.
> |
> | Each of these locations is checked that it is a directory and is
> | writable. If not, the algorithm tries the next choice.
Interesting, TMPDIR exists but OTOH it is not explicitly passed by
Apache PassEnv. Never figured out why some are passed by default and
others you have to specify. But I have certainly seen files called
CGItmpnnn or similar appearing in the cgi-bin directories. Yet another
OS/2 perl 5.8.2 funny I expect :-)
I may have a play with the first one.
--
Regards
Dave Saville
------------------------------
Date: Fri, 26 Apr 2013 11:34:09 -0700
From: "Joey@still_Learning.invalid" <Joey@still_Learning.invalid>
Subject: Re: Ascertaing uploaded file size
Message-Id: <gphln8ddundmkk463lg70cuvssu83oik3m@4ax.com>
Ben Morrow wrote:
>There is, of course, no need for $imgCnt or the corresponding field to
>exist at all. Perl arrays know how long they are, so
>
Except that imgCnt is calculated at the client and used later in error
tests, independent of what perl knows.
I capitulated to your knowledge and my ignorance and did the file sizing
with js at the client. Here is what I have...so far.
HTML:
<form id='form2' name='form2' action='cgi-bin/image_upload.pl'
method='post' enctype='multipart/form-data' onSubmit='sendItP2();'>
<input type='file' name='myFile0[]' id='myFile0' multiple='multiple'
min='1' max='1000'>
<div>
<input type='hidden' name='imgCnt' value=''>
<input type=hidden name='fileArray' value=''>
<input type=hidden name='fileNameString' value=''>
<input type=hidden name='fileSizeString' value=''>
</div>
</form>
Client-side javascript:
onLoad = add event listener -
fileselect = document.getElementById("myFile0");
fileselect.addEventListener("change", FileSelectHandler, false);
File selection:
function FileSelectHandler(e) {
var files = e.dataTransfer.files;
imgCnt = files.length;
document.forms["form2"].elements["fileArray"].value = files;
ptId = document.forms["form1"].elements['patient_id'].value;
fileNameString = ''; fileSizeString = '';
for (var i = 0; i < imgCnt; i++) {
var f = files[i];
if (i != (imgCnt -1)) {separatorString = ",";}
else {separatorString = "";}
fileNameString = fileNameString + f.name + separatorString;
fileSizeString = fileSizeString + f.size + separatorString;
}
document.forms["form2"].elements["fileNameString"].value = fileNameString;
document.forms["form2"].elements["fileSizeString"].value = fileSizeString;
document.forms["form2"].elements["imgCnt"].value = imgCnt;
} //end of file selection
function sendItP2() :
document.forms['form2'].submit();
perl:
use warnings;
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
my $query = new CGI;
$CGI::POST_MAX = 1024 * 5000;
$filePath = "/home/username/public_html/uploads/";
#Upload and test
chdir $filePath or die "$!";
$numImagesReceived = 0;
$uploadErrorFlag = 0;
@uploadFiles = param('myFile0[]');
@upload_filehandles = $query->upload("myFile0[]");
$fileNameString = param('fileNameString');
@fileNameString = split(',', $fileNameString);
$fileSizeString = param('fileSizeString');
@fileSizeString = split(',',$fileSizeString);
for (my $i=0;$i<$imgCnt;$i++) {
$filename = $fileNameString[$i];
$filename =~ s/.*[\/\\](.*)/$1/;
$filesize = $fileSizeString[$i];
$upload_filehandle = $upload_filehandles[$i];
open (UPLOADFILE, ">$filePath/$filename") or die "$!";
binmode UPLOADFILE;
local $/ = \8192;
while (<$upload_filehandle>) {
print UPLOADFILE;
}
close UPLOADFILE or die "Can't Close. $!";
}
#Finished all files uploading, now test for file and file sizes:
for ($j = 0; $j < $imgCnt; $j++) {
opendir DH,$filePath or die "$!";
$filename = $uploadFiles[$j];
$filesize = $fileSizeString[$j];
while (my $serverFileName = readdir DH) {
$serverFileSize = -s $serverFileName;
if (($serverFileName eq $filename) && ($filesize == $serverFileSize)) {
$numImagesReceived++;
}
}
}
if (($numImagesReceived != $imgCnt) {$uploadErrorFlag = 1;}
Next chore (unless I did something wrong...again) is to read in the server
directory once, instead of looping.
--
Joey
------------------------------
Date: Fri, 26 Apr 2013 21:00:50 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Ascertaing uploaded file size
Message-Id: <i03r4a-234.ln1@anubis.morrow.me.uk>
Quoth "Joey@still_Learning.invalid" <Joey@still_Learning.invalid>:
>
> I capitulated to your knowledge and my ignorance and did the file sizing
> with js at the client. Here is what I have...so far.
I would prefer you to understand what is going on rather than simply
taking my word for it...
[...]
> File selection:
> function FileSelectHandler(e) {
> var files = e.dataTransfer.files;
> imgCnt = files.length;
> document.forms["form2"].elements["fileArray"].value = files;
What does this do for you?
> ptId = document.forms["form1"].elements['patient_id'].value;
> fileNameString = ''; fileSizeString = '';
>
> for (var i = 0; i < imgCnt; i++) {
> var f = files[i];
> if (i != (imgCnt -1)) {separatorString = ",";}
> else {separatorString = "";}
> fileNameString = fileNameString + f.name + separatorString;
> fileSizeString = fileSizeString + f.size + separatorString;
You know, Javascript does have an Array.join method...
Also, the filenames are already sent as part of the value of the file
upload control. @uploadFiles below contains them.
> }
> document.forms["form2"].elements["fileNameString"].value = fileNameString;
> document.forms["form2"].elements["fileSizeString"].value = fileSizeString;
> document.forms["form2"].elements["imgCnt"].value = imgCnt;
> } //end of file selection
>
> function sendItP2() :
> document.forms['form2'].submit();
What does this do for you?
>
> perl:
> use warnings;
Last chance: you still aren't using 'strict'.
> use CGI qw(:standard);
> use CGI::Carp qw(fatalsToBrowser);
> my $query = new CGI;
> $CGI::POST_MAX = 1024 * 5000;
There is no point setting $CGI::POST_MAX after calling CGI->new, since
it won't have any effect.
> $filePath = "/home/username/public_html/uploads/";
>
> #Upload and test
> chdir $filePath or die "$!";
> $numImagesReceived = 0;
> $uploadErrorFlag = 0;
>
> @uploadFiles = param('myFile0[]');
> @upload_filehandles = $query->upload("myFile0[]");
>
> $fileNameString = param('fileNameString');
> @fileNameString = split(',', $fileNameString);
>
> $fileSizeString = param('fileSizeString');
> @fileSizeString = split(',',$fileSizeString);
>
> for (my $i=0;$i<$imgCnt;$i++) {
> $filename = $fileNameString[$i];
> $filename =~ s/.*[\/\\](.*)/$1/;
> $filesize = $fileSizeString[$i];
> $upload_filehandle = $upload_filehandles[$i];
>
> open (UPLOADFILE, ">$filePath/$filename") or die "$!";
open(my $UPLOADFILE, ">", "$filePath/$filename") or die ...;
> binmode UPLOADFILE;
> local $/ = \8192;
> while (<$upload_filehandle>) {
> print UPLOADFILE;
> }
> close UPLOADFILE or die "Can't Close. $!";
> }
Have you tried just calling rename() instead of copying the file by
hand?
> #Finished all files uploading, now test for file and file sizes:
> for ($j = 0; $j < $imgCnt; $j++) {
> opendir DH,$filePath or die "$!";
> $filename = $uploadFiles[$j];
> $filesize = $fileSizeString[$j];
> while (my $serverFileName = readdir DH) {
> $serverFileSize = -s $serverFileName;
> if (($serverFileName eq $filename) && ($filesize == $serverFileSize)) {
> $numImagesReceived++;
> }
> }
> }
> if (($numImagesReceived != $imgCnt) {$uploadErrorFlag = 1;}
>
> Next chore (unless I did something wrong...again) is to read in the server
> directory once, instead of looping.
As I said before, you don't need to read the directory at all. Since you
already have the list of names you can just call -s $filename directly.
Ben
------------------------------
Date: Fri, 26 Apr 2013 16:42:39 -0700
From: "Joey@still_Learning.invalid" <Joey@still_Learning.invalid>
Subject: Re: Ascertaing uploaded file size
Message-Id: <qj3mn85qkq225jqkg58gt894c6ujh6mb6a@4ax.com>
Ben Morrow wrote:
>Quoth "Joey@still_Learning.invalid" <Joey@still_Learning.invalid>:
>>
>> I capitulated to your knowledge and my ignorance and did the file sizing
>> with js at the client. Here is what I have...so far.
>
>I would prefer you to understand what is going on rather than simply
>taking my word for it...
I wish I had the time to fully understand this stuff. Alas... Fortunately
(for me and others), there are folks like you and others who provide just
enough guidance to help steer us.
>
>[...]
>> File selection:
>> function FileSelectHandler(e) {
>> var files = e.dataTransfer.files;
>> imgCnt = files.length;
>> document.forms["form2"].elements["fileArray"].value = files;
>
>What does this do for you?
Puts the selected file info into a form element for submittal to the perl
script.
>
>> ptId = document.forms["form1"].elements['patient_id'].value;
>> fileNameString = ''; fileSizeString = '';
>>
>> for (var i = 0; i < imgCnt; i++) {
>> var f = files[i];
>> if (i != (imgCnt -1)) {separatorString = ",";}
>> else {separatorString = "";}
>> fileNameString = fileNameString + f.name + separatorString;
>> fileSizeString = fileSizeString + f.size + separatorString;
>
>You know, Javascript does have an Array.join method...
Yes, and I can't explain why I didn't use it.
>
>Also, the filenames are already sent as part of the value of the file
>upload control. @uploadFiles below contains them.
My customers must provide a person's name, which has spaces between first
and last. The filename info is sent as space-separated values, so when I
go to output the name... I had to comma-separate to preserve the integrity
of the person's name.
>
>> }
>> document.forms["form2"].elements["fileNameString"].value = fileNameString;
>> document.forms["form2"].elements["fileSizeString"].value = fileSizeString;
>> document.forms["form2"].elements["imgCnt"].value = imgCnt;
>> } //end of file selection
>>
>> function sendItP2() :
>> document.forms['form2'].submit();
>
>What does this do for you?
>
This routine takes imgCnt and other variables and manipulates them for
purposes other than the upload, and after the process is complete, it
submits the file upload form and files.
>>
>> perl:
>> use warnings;
>
>Last chance: you still aren't using 'strict'.
>
I could, and I know good coding practice requires it, but at this point it
would be a very time-consuming process of declaring variables, most of
which are global. Call me lazy.
>> use CGI qw(:standard);
>> use CGI::Carp qw(fatalsToBrowser);
>> my $query = new CGI;
>> $CGI::POST_MAX = 1024 * 5000;
>
>There is no point setting $CGI::POST_MAX after calling CGI->new, since
>it won't have any effect.
Thanks.
>
>> $filePath = "/home/username/public_html/uploads/";
>>
>> #Upload and test
>> chdir $filePath or die "$!";
>> $numImagesReceived = 0;
>> $uploadErrorFlag = 0;
>>
>> @uploadFiles = param('myFile0[]');
>> @upload_filehandles = $query->upload("myFile0[]");
>>
>> $fileNameString = param('fileNameString');
>> @fileNameString = split(',', $fileNameString);
>>
>> $fileSizeString = param('fileSizeString');
>> @fileSizeString = split(',',$fileSizeString);
>>
>> for (my $i=0;$i<$imgCnt;$i++) {
>> $filename = $fileNameString[$i];
>> $filename =~ s/.*[\/\\](.*)/$1/;
>> $filesize = $fileSizeString[$i];
>> $upload_filehandle = $upload_filehandles[$i];
>>
>> open (UPLOADFILE, ">$filePath/$filename") or die "$!";
>
> open(my $UPLOADFILE, ">", "$filePath/$filename") or die ...;
>
>> binmode UPLOADFILE;
>> local $/ = \8192;
>> while (<$upload_filehandle>) {
>> print UPLOADFILE;
>> }
>> close UPLOADFILE or die "Can't Close. $!";
>> }
>
>Have you tried just calling rename() instead of copying the file by
>hand?
I don't understand your question.
>
>> #Finished all files uploading, now test for file and file sizes:
>> for ($j = 0; $j < $imgCnt; $j++) {
>> opendir DH,$filePath or die "$!";
>> $filename = $uploadFiles[$j];
>> $filesize = $fileSizeString[$j];
>> while (my $serverFileName = readdir DH) {
>> $serverFileSize = -s $serverFileName;
>> if (($serverFileName eq $filename) && ($filesize == $serverFileSize)) {
>> $numImagesReceived++;
>> }
>> }
>> }
>> if (($numImagesReceived != $imgCnt) {$uploadErrorFlag = 1;}
>>
>> Next chore (unless I did something wrong...again) is to read in the server
>> directory once, instead of looping.
>
>As I said before, you don't need to read the directory at all. Since you
>already have the list of names you can just call -s $filename directly.
>
Got it. Thanks.
Thanks for everything.
--
Joey
------------------------------
Date: Sat, 27 Apr 2013 11:59:20 +0000 (UTC)
From: "Dave Saville" <dave@invalid.invalid>
Subject: Re: Ascertaing uploaded file size
Message-Id: <fV45K0OBJxbE-pn2-0MHLj2TBydzH@paddington.bear.den>
On Fri, 26 Apr 2013 12:07:22 UTC, Ben Morrow <ben@morrow.me.uk> wrote:
> You're using CGI.pm? You set $CGITempFile::TMPDIRECTORY. (Yes, CGI.pm
> stomps on other random top-level namespaces, including Fh.)
>
Hi Ben - Would that be before or after calling any CGI.pm modules?
TIA
--
Regards
Dave Saville
------------------------------
Date: Sat, 27 Apr 2013 12:49:48 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Ascertaing uploaded file size
Message-Id: <sjqs4a-e0s.ln1@anubis.morrow.me.uk>
Quoth "Joey@still_Learning.invalid" <Joey@still_Learning.invalid>:
> Ben Morrow wrote:
>
> >Last chance: you still aren't using 'strict'.
> >
> I could, and I know good coding practice requires it, but at this point it
> would be a very time-consuming process of declaring variables, most of
> which are global. Call me lazy.
Asking for others' help while refusing to make a minimal effort to help
yourself isn't just lazy, it's selfish and ungrateful.
*plonk*
Ben
------------------------------
Date: Sat, 27 Apr 2013 05:23:18 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Ascertaing uploaded file size
Message-Id: <lfgnn8difkahehgpil4frlr67q7n22bnbi@4ax.com>
"Joey@still_Learning.invalid" <Joey@still_Learning.invalid> wrote:
>My customers must provide a person's name, which has spaces between first
>and last.
Or it has a comma between last name and given name ...
>The filename info is sent as space-separated values, so when I
>go to output the name... I had to comma-separate to preserve the integrity
>of the person's name.
... in which case your hack does not work any longer.
Lesson: never assume anything about user-supplied data.
jue
------------------------------
Date: Sat, 27 Apr 2013 13:49:55 +0100
From: Rainer Weikusat <rweikusat@mssgmbh.com>
Subject: Re: Ascertaing uploaded file size
Message-Id: <87mwskrvd8.fsf@sapphire.mobileactivedefense.com>
"Dave Saville" <dave@invalid.invalid> writes:
> On Fri, 26 Apr 2013 12:07:22 UTC, Ben Morrow <ben@morrow.me.uk> wrote:
>
>> You're using CGI.pm? You set $CGITempFile::TMPDIRECTORY. (Yes, CGI.pm
>> stomps on other random top-level namespaces, including Fh.)
>>
>
> Hi Ben - Would that be before or after calling any CGI.pm modules?
That would be after loading them and before processing any user data
which may contain file uploads.
------------------------------
Date: Sat, 27 Apr 2013 15:01:22 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Ascertaing uploaded file size
Message-Id: <ia2t4a-l7t.ln1@anubis.morrow.me.uk>
Quoth "Dave Saville" <dave@invalid.invalid>:
> On Fri, 26 Apr 2013 12:07:22 UTC, Ben Morrow <ben@morrow.me.uk> wrote:
>
> > You're using CGI.pm? You set $CGITempFile::TMPDIRECTORY. (Yes, CGI.pm
> > stomps on other random top-level namespaces, including Fh.)
>
> Hi Ben - Would that be before or after calling any CGI.pm modules?
I would imagine it would be before creating a CGI object; that is,
either before the call to CGI->new or before the first call to one of
the functional interface functions (which construct an object behind the
scenes). (I don't use CGI.pm, so I'm not an expert. If I were handling
upload requests without a framework I would probably use HTTP::Body.)
Ben
------------------------------
Date: Sat, 27 Apr 2013 14:14:54 +0000 (UTC)
From: "Dave Saville" <dave@invalid.invalid>
Subject: Re: Ascertaing uploaded file size
Message-Id: <fV45K0OBJxbE-pn2-hwO573gq4V1f@paddington.bear.den>
On Sat, 27 Apr 2013 14:01:22 UTC, Ben Morrow <ben@morrow.me.uk> wrote:
>
> Quoth "Dave Saville" <dave@invalid.invalid>:
> > On Fri, 26 Apr 2013 12:07:22 UTC, Ben Morrow <ben@morrow.me.uk> wrote:
> >
> > > You're using CGI.pm? You set $CGITempFile::TMPDIRECTORY. (Yes, CGI.pm
> > > stomps on other random top-level namespaces, including Fh.)
> >
> > Hi Ben - Would that be before or after calling any CGI.pm modules?
>
> I would imagine it would be before creating a CGI object; that is,
> either before the call to CGI->new or before the first call to one of
> the functional interface functions (which construct an object behind the
> scenes). (I don't use CGI.pm, so I'm not an expert. If I were handling
> upload requests without a framework I would probably use HTTP::Body.)
>
Yes it is. I now have both my upload scripts using it - Saving a file
copy. Thanks so much.
--
Regards
Dave Saville
------------------------------
Date: Sat, 27 Apr 2013 09:54:39 -0700
From: "Joey@still_Learning.invalid" <Joey@still_Learning.invalid>
Subject: Re: Ascertaing uploaded file size
Message-Id: <ui0on8l7lk61dk389195qu9n4rh5jjm4ta@4ax.com>
Jürgen Exner wrote:
>"Joey@still_Learning.invalid" <Joey@still_Learning.invalid> wrote:
>>My customers must provide a person's name, which has spaces between first
>>and last.
>
>Or it has a comma between last name and given name ...
>
>>The filename info is sent as space-separated values, so when I
>>go to output the name... I had to comma-separate to preserve the integrity
>>of the person's name.
>
>... in which case your hack does not work any longer.
>
>Lesson: never assume anything about user-supplied data.
>
I agree...I filter user input and disallow all, but standard characters,
numbers and spaces.
--
Joey
------------------------------
Date: Fri, 26 Apr 2013 22:03:49 +0300
From: "George Mpouras" <nospam.gravitalsun.antispam@spamno.hotmail.anispam.com.nospam>
Subject: Re: Is Perl dying or not?
Message-Id: <klej2n$28nj$1@news.ntua.gr>
is this a joke or something ?
------------------------------
Date: Fri, 26 Apr 2013 22:05:38 +0300
From: "George Mpouras" <nospam.gravitalsun.antispam@spamno.hotmail.anispam.com.nospam>
Subject: nice parallel file reading
Message-Id: <klej67$2973$1@news.ntua.gr>
# Read files in parallel. FileHandles are closed automatically.
# Files are read at every iteration circulary, hope you like it !
use strict;
use warnings;
my $Read_line = Read_files_round_robin( 'file1.txt', 'file2.txt',
'file3.txt' );
while ( my $line = $Read_line->() ) {
last if $line eq '__ALL_FILES_HAVE_BEEN_READ__';
chomp $line;
print "$line\n";
}
sub Read_files_round_robin
{
my $fc = $#_;
my @FH;
for(my $i=0; $i<@_; $i++) { open $FH[$#_ - $i] , $_[$i] or die "Could not
read file \"$_[$i]\" because \"$^E\"\n" }
sub
{
local $_ = '__ALL_FILES_HAVE_BEEN_READ__';
for (my $i=$fc; $i>=0; $i--)
{
if ( eof $FH[$i] )
{
close $FH[$i];
splice @FH, $i, 1;
next
}
$_ = readline $FH[$i];
last
}
$fc = $fc == 0 ? $#FH : $fc - 1;
$_
}
}
------------------------------
Date: Sat, 27 Apr 2013 16:48:11 +0300
From: "George Mpouras" <nospam.gravitalsun.antispam@spamno.hotmail.anispam.com.nospam>
Subject: Re: nice parallel file reading
Message-Id: <klgkuu$2vo4$1@news.ntua.gr>
# there was a problem with the code at my initial post
# Here is corrected, of how to read files like round-robin
# using an iterator
#!/usr/bin/perl
use strict;
use warnings;
my $Reader = Read_files_round_robin( 'file1.txt', 'file2.txt',
'file3.txt' );
while ( my $line = $Reader->() ) {
last if $line eq '__ALL_FILES_HAVE_BEEN_READ__';
chomp $line;
print "*$line*\n";
}
sub Read_files_round_robin
{
my @FH;
for (my $i=$#_; $i>=0; $i--) { if (open my $fh, $_[$i]) {push @FH, $fh} }
my $k = $#FH;
sub
{
until (0 == @FH)
{
for (my $i=$k--; $i>=0; $i--)
{
$k = $#FH if $k == -1;
if ( eof $FH[$i] )
{
close $FH[$i];
splice @FH, $i, 1;
$k--
}
else
{
return readline $FH[$i]
}
}
}
'__ALL_FILES_HAVE_BEEN_READ__'
}
}
------------------------------
Date: Sat, 27 Apr 2013 07:49:40 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: nice parallel file reading
Message-Id: <3uonn894n6uuvo8h2fu0nm5vr5esqvp1g6@4ax.com>
"George Mpouras"
<nospam.gravitalsun.antispam@spamno.hotmail.anispam.com.nospam> wrote:
># there was a problem with the code at my initial post
># Here is corrected, of how to read files like round-robin
># using an iterator
While this might be mildly interesting as an academic exercise I wonder
if there is any actual non-contrived application where you would have to
read multiple files synchronously line-by-line and at the same time the
files are too large to just load them into a variable and then process
their content.
jue
------------------------------
Date: Sat, 27 Apr 2013 17:32:18 +0200
From: "Peter J. Holzer" <hjp-usenet3@hjp.at>
Subject: Re: nice parallel file reading
Message-Id: <slrnknnrs2.blq.hjp-usenet3@hrunkner.hjp.at>
On 2013-04-27 14:49, Jürgen Exner <jurgenex@hotmail.com> wrote:
> "George Mpouras"
><nospam.gravitalsun.antispam@spamno.hotmail.anispam.com.nospam> wrote:
>># there was a problem with the code at my initial post
>># Here is corrected, of how to read files like round-robin
>># using an iterator
>
> While this might be mildly interesting as an academic exercise I wonder
> if there is any actual non-contrived application where you would have to
> read multiple files synchronously line-by-line and at the same time the
> files are too large to just load them into a variable and then process
> their content.
Not exactly like George's code, but very similar: Merge sorted files.
A similar technique could be used to implement comm(1).
hp
--
_ | Peter J. Holzer | Fluch der elektronischen Textverarbeitung:
|_|_) | Sysadmin WSR | Man feilt solange an seinen Text um, bis
| | | hjp@hjp.at | die Satzbestandteile des Satzes nicht mehr
__/ | http://www.hjp.at/ | zusammenpaßt. -- Ralph Babel
------------------------------
Date: Sat, 27 Apr 2013 09:39:14 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: nice parallel file reading
Message-Id: <ccvnn8ln35ofh355sroikolr123rvmnq6r@4ax.com>
"Peter J. Holzer" <hjp-usenet3@hjp.at> wrote:
>On 2013-04-27 14:49, Jürgen Exner <jurgenex@hotmail.com> wrote:
>> "George Mpouras"
>><nospam.gravitalsun.antispam@spamno.hotmail.anispam.com.nospam> wrote:
>>># there was a problem with the code at my initial post
>>># Here is corrected, of how to read files like round-robin
>>># using an iterator
>>
>> While this might be mildly interesting as an academic exercise I wonder
>> if there is any actual non-contrived application where you would have to
>> read multiple files synchronously line-by-line and at the same time the
>> files are too large to just load them into a variable and then process
>> their content.
>
>Not exactly like George's code, but very similar: Merge sorted files.
Fair enough, but for merge sort you explicitely do _NOT_ read files
synchronously.
The only application I could think of is testing for equality of n
files.
Or implementing a poor man's database in multiple files with each column
of a table in a separate file. Which of course would be synchronization
nightmare.
jue
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V11 Issue 3935
***************************************