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 warnings; #why was this left out?

> use strict;
> use Fcntl;
> 
> $/ = "\n\n";
# I assume you know what you're doing here....
> sysopen(readFile, "cnnArticle.txt", O_RDONLY) || die $!;
> sysopen(writeFile, "fortuneCookie.txt", O_WRONLY|O_CREAT) || die $1;

#nuh uh.
sysopen(writeFile, "fortuneCookie.txt", O_WRONLY|O_CREAT) || die $!;

> 
> my @articleArray = <readFile>;
> 
> while(<@articleArray>)

#bah. why slurp the whole file into memory at once, when you're only 
# printing a line at a time? what if the file was a web-log gigabytes
# long?  
while (<readFile>)

> {
> print $_;

#you have to specify the output filehandle
print writeFile; #$_ is superfluous here as it is the default.

> }

# always close (and test the closing of) file handles
close readFile or die "Unable to close input file: $!";
close writeFile or die "Unable to close output file: $!";
#always use descriptive error messages.


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

Reply via email to