I am new to Perl and trying to sort out an issue but did not have success. I am trying to read data from a text file. The code is:
open FH, 'D:\Learning\Test.txt' or die $!;
my @data_line;
while (<FH>)
{
@data_line = split (/\|\~/);
print @data_line;
}
The file content is like this:
101|~John|~This line is broken and showing space in print|~version123|~data|~|~|~ 102|~Abrahim|~This is a line to be print|~version1.3|~|~|~|~
And the output is:
101JohnThis line is broken and showing space in printversion123data 102AbrahimThis is a line to be printversion1.3
I just want to show the data in one line between the delimiters like:
101JohnThis line is broken and showing space in printversion123data 102AbrahimThis is a line to be printversion1.3
Please suggest me what should I do. I had tried chomp(@data_line)
also, but it did not work.
I am using Windows operating system.
I want to insert these "|~" separated values in different fields of a table. I had added : $_ =~ s/\n//g; before @data_line = split (/\|\~/); it printed the details as per my requirement but not inserting data properly in my database table. Please suggest me what should i do ? Thanks in advance.