Article View: pl.comp.lang.perl
Article #942Re: hash'e
From: Robert Richard George 'reptile' ...
Date: Fri, 30 Jan 1998 16:51
Date: Fri, 30 Jan 1998 16:51
60 lines
3139 bytes
3139 bytes
On 98.01.29 Zbigniew Zych pressed the following keys:
> $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, $_);
> }
> }
Do tego to nie mam się gdzie przyczepić, bo sam robię podobną magię.
> 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...
> }
foreach(@header) {
/^([^:]+:\s+(.*)$/;
$klucz = $1;
$klucz =~ tr/A-Z/a-z/; # pamiętaj o tym, że pole 'name'
# nagłówka w/g rfc822 jest case instensitive!
$tresc = $2;
if ($header{$klucz}) { # pola w nagłówku mogą się powtarzać
$header{$klucz} .= ", $tresc" # należy więc wtedy raczej dodać wartość
} else { # do już istniejącego pola o tej nazwie,
$header{$klucz} = $tresc # po przecinku (albo się źle doczytałem :)
}
}
>
> Aż mnie boli jak to oglądam.... ;-)
> Ja to chce w 3 linijkach!!!!
No i teraz głowa boli jeszcze bardziej, ale zawsze jak dochodzę do tego,
pocieszam się, że gdybym żył z kopania dołów, nie bolała by mnie głowa, ale
za to bolałby mnie kręgosłup :)
> Zbigniew Zych
Gad
--
mailto:reptile@pdi.net :)
Women are more complicated than PC... :(
Look into my headers and you'll see who I am. :)
Technical Details
Message-ID:
<19980130175117.57087@address.in.sig>Path:
mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!pingwin.icm.edu.pl!news.icm.edu.pl!lublin.pl!gad!not-for-mailReferences:
<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!lublin.pl!gad!not-for-mail From: Robert Richard George 'reptile' Wal <reptile@address.in.sig> Newsgroups: pl.comp.lang.perl Subject: Re: hash'e Date: Fri, 30 Jan 1998 17:51:17 +0100 Organization: Me? Organized? Get real :) Lines: 60 Message-ID: <19980130175117.57087@address.in.sig> References: <6aqn18$juh$1@newsfeed.onet.pl> NNTP-Posting-Host: pooh.cs.net.pl Mime-Version: 1.0 X-Mailer: Mutt 0.88 In-Reply-To: <6aqn18$juh$1@newsfeed.onet.pl>; from Zbigniew Zych on Thu, Jan 29, 1998 at 07:58:32PM +0000 X-URL: http://www.pdi.net/~gad (Eternally under construction) X-IRC-Nick: Gadzinka@iRCnET.iRC.nETWORK (Gadzinka -- tiny little reptile) X-Phone: +48(0)42 593453 X-PGP-Fingerprint: 37E1D55F 29793C0C B8D39D01 61FC50CE X-PGP-Key: finger reptile@gryzmak.lodz.pdi.net X-Motto: Fact that you're paranoid doesn't imply that THEY don't follow you. X-Disclaimer: I don't answer mail or news articles below some arbitrary mark. X-Favourites: women, cats, Amiga, Linux, TeX, vim, music, sci-fi, poetry. X-Mount-Entry: mount -t human /dev/reptile /earth/europe/poland/lodz Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit