$append = 0; if ($append) { open(MYOUTFILE, ">clean_text"); #open for write, overwrite } else { open(MYOUTFILE, ">>clean_text"); #open for write, append }
looks like you are overwriting if $append is true and appending if it is false. Perhaps a little misleading?
The use of the three argument form of open is to be encouraged as is the use of lexically scoped filehandles. You should also test that the open succeeded. Most importantly, putting the lines use strict; and use warnings; at the top of your scripts will save you a lot of wasted time in the long run as it will help you spot typos like
$append = 1; ... if ( $apped ) { # Append to my file } else { # Trample all over my irreplaceable data }
Using strictures, three argument open and lexical handles your piece of code might look like
my $append = 0; my $cleanedFile = q{clean_text}; if ( $append ) { open my $cleanedFH, q{>>}, $cleanedFile or die qq{open: $cleanedFile for append: $!\n}; } else { open my $cleanedFH, q{>}, $cleanedFile or die qq{open: $cleanedFile for overwrite: $!\n}; }
I hope these thoughts are of use.
Cheers,
JohnGG
In reply to Re: html into an array
by johngg
in thread html into an array
by monkeybus
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |