From: Mark Atwood Newsgroups: alt.hackers Subject: Perl one-liners and pet hacks Date: 08 Feb 1998 12:03:19 -0500 Organization: Ampersand, Inc. Lines: 25 Approved: zot@ampersand.com Message-ID: References: <6atq6t$k0l$1@news2.digex.net> <6bhd5g$8ho$1@prefetch.san.rr.com> <87d8gzh7uf.fsf@erlenstar.demon.co.uk> <87k9b6cig9.fsf@erlenstar.demon.co.uk> NNTP-Posting-Host: tick X-Newsreader: Gnus v5.2.40/Emacs 19.31 Path: ccw.ch!aetna.dolphins.ch!news.planetc.com!newsfeed.usit.net!news-out.internetmci.com!newsfeed.internetmci.com!4.1.16.34!cpk-news-hub1.bbnplanet.com!cam-news-feed5.bbnplanet.com!news.bbnplanet.com!ftp.ampersand.com!not-for-mail Andrew Gierth writes: > > ObHack: > > %h = map { /^(.*?):\s(.*)$/ ? (lc $1, $2) : () } split(/\n(?!\s)/, $h); I dont get it. All it seems to do is lowercase the names of the header lines of an article. Is it supposed to do something deeper than that, or did I missread it? ObHack: We have a cat that started using the bathtub instead of her litter box. This got really annoying, really fast. We tried several ways to discourage her. (it is impossible to "punish" a cat, BTW.. Any negative consequences have to be immediate and "natural" or they don't "get it".) Finaly, INSPIRATION! We leave the tub full. She hates getting wet, and has gone back to using her box. -- Mark Atwood | Thank you gentlemen, you are everything we have come to zot@ampersand.com | expect from years of government training. -- MIB Zed ###### From: ben@thelonious.new.ox.ac.uk (Ben North) Newsgroups: alt.hackers Subject: Re: Perl one-liners and pet hacks Date: 8 Feb 1998 17:57:36 -0000 Organization: New College, Oxford University Lines: 40 Approved: The Lord High Chancellor Message-ID: <6bkrmg$em8$1@thelonious.new.ox.ac.uk> References: <6atq6t$k0l$1@news2.digex.net> <87k9b6cig9.fsf@erlenstar.demon.co.uk> NNTP-Posting-Host: thelonious.new.ox.ac.uk Path: ccw.ch!aetna.dolphins.ch!news.planetc.com!leto.ou.edu!news.ecn.uoknor.edu!feed1.news.erols.com!news-peer.sprintlink.net!news.sprintlink.net!Sprint!news-peer.gip.net!news-lond.gip.net!news.gsl.net!gip.net!baron.netcom.net.uk!netcom.net.uk!server3.netnews.ja.net!news.ox.ac.uk!not-for-mail Mark Atwood wrote: > Andrew Gierth writes: > > > > ObHack: > > > > %h = map { /^(.*?):\s(.*)$/ ? (lc $1, $2) : () } split(/\n(?!\s)/, $h); > > I dont get it. All it seems to do is lowercase the names of the header > lines of an article. Is it supposed to do something deeper than that, > or did I missread it? Seems to me that it puts into the associative array %h a mapping from the lowercased header titles to their contents. Then later on in the code you can do stuff like @refs = split(/\s+/, $h{references}); to get an ordered list of the contents of the References: header. Perl's map function rocks (all of Perl rocks, in fact), and that's a sweet application of it. The split() call to pick out the headers while maintaining continuation lines is also nice. A fine ObHack from Mr Gierth, I'd say. Guess I need one of my own, now. I hope this counts; it certainly involved a Leatherman, which ought to help. ObBicycleLockHack: Trying to leave work one evening, my bicycle lock (a D-lock with cylindrical lock) refused to unlock. This was not good, since I needed to get to the shops before they shut. I hadn't really been looking after it properly, and there was quite a bit of rust all over the place, including the lock mechanism itself. A bit of examination (in the dark, with a not-very-bright front light) revealed that one of the pins was stuck all the way down. Holding a straightened-out staple in my Leatherman allowed me to prod at the pin until it jiggled free and popped back up again, allowing me to unlock the lock. A good dose of 3-in-1 when I got back made sure it hasn't happened again. (Yes, I know --- I haven't got any graphite powder.) Ben.