After reading your comments, I am guessing that your problem is that your source file does not contain any newlines: I.e. the entire file is just one line. Some text editors just wrap the text without actually adding any line break characters.
There is no "solution" to that problem; You have to add line breaks where you want them. You could write a script to do it, but I doubt it would make much sense. It all depends on what you want to do with this text.
Here's my code suggestions for your snippet.
chomp(@array = <FILE>);
s/[()]//g for @array;
print "$_\n" for @array;
or
@array = <FILE>;
s/[()]//g for @array;
print @array;
Note that if you have a file from another filesystem, you may get \r characters left over at the end of your strings after chomp, causing the output to look corrupted, overwriting itself.
Additional notes:
(\)|\() is better written as a character class: [()].
@array = <FILE> will read the entire file into the array. No need
to loop.
- As shown in my examples,
print can be assigned a list of items
(e.g. an array) as arguments. And you can have a postfix loop to
print sequentially.
- With a (postfix) loop, all the loop elements are aliased to
$_,
which is a handy way to do substitutions on the array.
"He\ngoes\nto\nthe\nschool\everyday\n"given that@array. Any chance of getting a whole minimal script along with sample input and output?qw(He goes to the school)example. =) Because that is clearly false. Use your actual input/output.