The following is a subroutine I'm using for a script to process a bunch of data, one chunk at a time. The problem is the data amounts both need to be looped over, so I'm constructing a new script to process each file, 500 at a time, and then write the output.
This subroutine takes in $testdata, a file handle, and $c a number at which to start adding the data to the data array, '@emailsText' and $timetowrite, which is the upper limit of the set of data I'm trying to get into the array.
It's returning numbers, instead of data pieces...does anybody have any ideas on this one?
[perl]
sub openText {
($testdata,$timetowrite,$c) = (@_);
my ($email, $blank);
open STUFF, "$testdata" or die "noop";
while (<STUFF>) {
($key, $value)= split (/ /, $_);
# $email = $_;
if ($c le $key) {
push @emailsText, $value;
# print "added email to the array\n";
$_++; }
elsif ($timetowrite eq $key) {
close (STUFF);
return @emailsText; }
elsif ($blank eq $key) {
close (STUFF);
return @emailsText;
}
$_++;
}
close (STUFF);
return 0;
}
[/perl]
Here's my thinking:
[perl]
@array = ("hello","world");
$noquotes = @array;
$withquotes = "@array";
print "Array syntax, NO quotes = $noquotes"; # prints 2
print "<br>Array syntax, WITH quotes = $withquotes"; # prints the words
[/perl]
This lame piece of code is "supposed" to check to see if the line is blank:
if ($blank == $key) {
close (STUFF);
return @emailsText;
}
However, that's not working...the rest, seems to work fine.
(modified sub routine follows) Any thoughts?
[perl]
sub openText {
($testdata,$timetowrite,$c) = (@_);
my $blank = '';
open STUFF, "$testdata" or die "noop";
foreach (<STUFF>) {
($key, $value)= split (/ /, $_);
# $email = $_;
if ($c <= $key ) {
push @emailsText, $value;
print "added $value to the array\n"; }
if ($timetowrite == $key) {
close (STUFF);
return @emailsText; }
if ($blank == $key) {
close (STUFF);
return @emailsText;
}
}
close (STUFF);
return 0;
}
[/perl]