N
nntpman68
Hi,
I'm having files, which I'd like to slurp into an array
(one file per array)
However I'd like to get rid of the end of line characters of the files.
As files were created by windows users or linux users the lines will end
with either \n or with \r\n.
Additionally linux files might have been modified by windows users
(or vice versa) and not all editors are smart enough to adapt to the
files mode. so some files might have mixed line endings.
I came up with
@a = <$filehandle>
foreach $l (@a) { $l =~ s/(\r\n|\r)$//; }
or with
@a = grep { s/(\r\n|\r)$// } <$filehandle>
or with
@a=()
while(<$fh){ s/(\r\n|\r)$// ; push(@a); }
In above examples I could also replace the substitute with tr/\r\n//d
Is there already something like a strip_eof() function, or should I
stick with one of the above?
N
I'm having files, which I'd like to slurp into an array
(one file per array)
However I'd like to get rid of the end of line characters of the files.
As files were created by windows users or linux users the lines will end
with either \n or with \r\n.
Additionally linux files might have been modified by windows users
(or vice versa) and not all editors are smart enough to adapt to the
files mode. so some files might have mixed line endings.
I came up with
@a = <$filehandle>
foreach $l (@a) { $l =~ s/(\r\n|\r)$//; }
or with
@a = grep { s/(\r\n|\r)$// } <$filehandle>
or with
@a=()
while(<$fh){ s/(\r\n|\r)$// ; push(@a); }
In above examples I could also replace the substitute with tr/\r\n//d
Is there already something like a strip_eof() function, or should I
stick with one of the above?
N