Erwin Zavala wrote:
I know I could use the filehandle but I am trying to understand why I cannot use the array and print each element at the time.

#!/usr/bin/perl
use strict;
use Fcntl;

$/ = "\n\n";
sysopen(readFile, "cnnArticle.txt", O_RDONLY) || die $!;
sysopen(writeFile, "fortuneCookie.txt", O_WRONLY|O_CREAT) || die $1;

my @articleArray = <readFile>;

while(<@articleArray>)
{
print $_;
}

Where is your 'use warnings'?


In particular any reason you need 'sysopen' instead of plain old 'open'? Are the elements of the array not printing at all or are they just not printing to your output file? I assume since you open an output file that is where you want the content to go, in which case you need to add the 'writeFile' handle as a parameter of the print, so:

print writeFile $_;

Should do the trick. I assume you know what you are doing by changing $/ but often it is nice to set it back to the original value...

Don't forget to close your file handles, and common practice in Perl is to uppercase the whole file handle name, though this is not required.

http://danconia.org


-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to