Article View: pl.comp.lang.perl
Article #943Re: hash'e
From: Krzysztof Koczyjan
Date: Sat, 31 Jan 1998 00:10
Date: Sat, 31 Jan 1998 00:10
55 lines
1912 bytes
1912 bytes
Zbigniew Zych <zych@use.address.from.sig.onet.pl> wrote in article
>
> $header = 1;
>
> while(<>) {
> chomp;
> if(/^$/ && $header) {
> $header = 0;
> } elsif ($header) {
> if(/^\t/) { # jesli nastepna linia zaczyna sie \t
> $header[$#header] .= "\n$_"; # to jest to kontynuacja poprzedniej
> } else {
> push(@header, $_);
> }
> } else { # body
> push(@body, $_);
> }
> }
>
> foreach(@header) {
> $klucz = $_;
> $tresc = $_;
> $klucz =~ s/([^\s:]+:?)\s(.*)/$1/s; # to mi sie okrutnie ni podoba,
po
> $tresc =~ s/([^\s:]+:?)\s(.*)/$2/s; # prostu musi sie dac prosciej
;-)
> $header{$klucz} = $tresc; # i w koncu mamy hasha...
> }
>
>
> Aż mnie boli jak to oglądam.... ;-)
> Ja to chce w 3 linijkach!!!!
Oryginal mial rzeczywiscie 3 linie ( + petla while ), ale ignorowal linie
przedluzenia , dodalem to i wynik ponizej:
while(<>){
chomp;
last unless $_;
if( /([^:]+):\s+(.*)/ ){
$header{lc($1)} = $2;
$lkey = lc($1);
}
else{
s/^\s+//;
$header{$lkey} .= "\n$_";
}
}
..... Czytanie tresci....
Pozdrowienia
KK
Technical Details
Message-ID:
<6atq6j$b1e@bgtnsc03.worldnet.att.net>Path:
mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!pingwin.icm.edu.pl!news.icm.edu.pl!fu-berlin.de!newsfeed.direct.ca!cpk-news-hub1.bbnplanet.com!news.bbnplanet.com!worldnet.att.net!newsadmReferences:
<6aqn18$juh$1@newsfeed.onet.pl>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!pingwin.icm.edu.pl!news.icm.edu.pl!fu-berlin.de!newsfeed.direct.ca!cpk-news-hub1.bbnplanet.com!news.bbnplanet.com!worldnet.att.net!newsadm From: "Krzysztof Koczyjan" <krzysztofK@rocketmail.com> Newsgroups: pl.comp.lang.perl Subject: Re: hash'e Date: 31 Jan 1998 00:10:59 GMT Organization: AT&T WorldNet Services Lines: 55 Message-ID: <6atq6j$b1e@bgtnsc03.worldnet.att.net> References: <6aqn18$juh$1@newsfeed.onet.pl> NNTP-Posting-Host: 12.66.112.145 X-Newsreader: Microsoft Internet News 4.70.1155 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit