Here comes one more alternative...

open (FILE, 'input.txt');
while (<FILE>) {s/\s*//g; $output.=$_.'|';}
close (FILE);
chop $output;
print $output;

where input.txt is something like:
line1\n
line2               \n
line3\t\t\n
line4\n
line5     \t    \n

script removes all possible sorts of "white spaces" and linefeds.

then $output is: line1|line2|line3|line4|line5

Viktoras

[EMAIL PROTECTED] wrote:

Hi all,

Here is the script I finally came up with. For some reason I need to
find \n within "context" i.e. possible surrounding white spaces and \n.

Daniel

--

my $outputFile = "Out_input.txt";

open (INPUTFILEHANDLE, "input.txt");
open (OUTPUTFILEHANDLE, ">". $outputFile);

$/ = undef;
$theFile = <INPUTFILEHANDLE>;

# remove all trailing \n
$theFile =~ s/(\s{0,})(\n{1,})/ /g;

# add to each end of field delimiter a \n
$theFile =~s/}~/}~\n/g;

# add to each end of record delimniter a \n
$theFile =~s/\|/\|\n/g;

# remove trailing spaces after a \n
$theFile =~ s/\n(\s{1,})/\n/g;

print OUTPUTFILEHANDLE $theFile . "\n";

close OUTPUTFILEHANDLE;
close INPUTFILEHANDLE;

exit 0;

_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs



--
Your favorite stores, helpful shopping tools and great gift ideas. Experience the convenience of buying online with [EMAIL PROTECTED] http://shopnow.netscape.com/



_______________________________________________ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to