[vienna.pm] zeilenende unter unix/windows
Peter J . Holzer
hjp at wsr.ac.at
Thu Aug 16 11:12:07 CDT 2001
On 2001-08-16 09:44:33 +0200, roland.bauer at fff.at wrote:
> Hallo Peter,
>
> > Unter Dos ist das Zeilenende ja mit chr13/chr10 definiert.
>
> Vollstaendig (in Hex):
> \x0A ... unix
> \x0D\x0A ... dos
> \x0A\x0D ... mac
Ist das nicht nur \x0D beim Mac?
> > Kann ich den chomp-befehl einfach ueberschreiben?
>
> Wuerde ich nicht empfehlen.
>
> Chomp verwendet $/, das koenntest Du ev. ueberschreiben.
>
> Ich wuerde aber dann die Leseroutine kapseln, damit
> $/ nur lokal umdefiniert wird:
>
> # ...
> # befehle
> # ...
> {
> # Einlesen:
> # Zeilenende herausfinden
Wie wär's damit?
local $/ = undef;
open (IN, "<$file") or die;
binmode(IN);
my $content = <IN>; # slurp whole file or use sysread to read a
# chunk large enough to get at least one line
# separator.
my ($rs) = m/(\x0D\x0A|\x0A|\x0D)/;
close(IN);
# entweder
@lines = split($rs, $content);
for (@lines) {
...
}
# oder
$/ = $rs;
open (IN, "<$file") or die;
binmode(IN);
while (<IN>) {
chomp;
...
}
hp
--
_ | Peter J. Holzer | My definition of a stupid question is
|_|_) | Sysadmin WSR / LUGA | "a question that if you're embarassed to
| | | hjp at wsr.ac.at | ask it, you stay stupid."
__/ | http://www.hjp.at/ | -- Tim Helck on dbi-users, 2001-07-30
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 371 bytes
Desc: not available
Url : http://mail.pm.org/archives/vienna-pm/attachments/20010816/55aa9a83/attachment.bin
More information about the Vienna-pm
mailing list