In your loop that builds your string, replace the following statement: $string .= $_;
with these:
chomp; #Removes trailing new-line character from $_
$string .= "$_ "; # "$_ followed by one space"
http://perldoc.perl.org/functions/chomp.html
Hi,
I have a file.txt, I need to enter the data in string. Currently my code looks like this,
#!/usr/bin/perl open myfiles, "file.txt" or die "couldn't find file: $!"; while (<myfiles>){ $string .= $_; } print $string; close(myfiles);
The output when I print the string is like
hello.c
work.c
office.cIs it possible to get the output of the string ot be in 1 line with spaces such as
hello.c work.c office.c
If there is a was which can place the data in the string initially like this or if there is a way I can manipulate the string it will be really helpful.
Thanks,
Rahul