jimmybeaches has asked for the wisdom of the Perl Monks concerning the following question:
So, I am new to Perl... bought a book and I think I am off the right start with chomp or chop, except I am trying to remove a blank space from the front of a line.
I am simply trying to open the contents of a text file into an array and print them, except every line AFTER the first line prints with a blank space in front of it?! Is there some way of stripping the blank space away from every line in the array?
Contents of the text file:
one. two. three. four.
the code in my script:
my $messagebody = "message.txt"; open(messagebody, $messagebody) || Error ('open', 'file'); flock (messagebody, 2) || Error ('lock', 'file'); my @messagebody = <messagebody>; print @messagebody; sub Error { print "The server can't $_[0] the $_[1]: $! \n"; exit; }
The file prints like this:
one. two. three. four.
Is there a way to reverse what chop? (if that makes any sense...)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Getting rid of first space?
by tall_man (Parson) on Mar 16, 2003 at 04:13 UTC | |
|
Re: Getting rid of first space?
by pfaut (Priest) on Mar 16, 2003 at 04:15 UTC | |
|
Re: Getting rid of first space?
by thpfft (Chaplain) on Mar 16, 2003 at 04:21 UTC | |
by Anonymous Monk on Mar 16, 2003 at 04:32 UTC | |
|
Re: Getting rid of first space?
by jasonk (Parson) on Mar 16, 2003 at 04:15 UTC | |
|
Re: Getting rid of first space?
by Anonymous Monk on Mar 16, 2003 at 04:18 UTC | |
by jasonk (Parson) on Mar 16, 2003 at 04:23 UTC | |
by Anonymous Monk on Mar 16, 2003 at 04:39 UTC | |
|
Re: Getting rid of first space?
by Anonymous Monk on Mar 16, 2003 at 04:45 UTC | |
by tall_man (Parson) on Mar 16, 2003 at 18:04 UTC |