Cool/useful short examples of Perl?

Chris Jack chris_jack at msn.com
Wed Jun 8 14:25:49 BST 2011





> From: london.pm-request at london.pm.org
> Subject: london.pm Digest, Vol 68, Issue 13
> To: london.pm at london.pm.org
> Date: Wed, 8 Jun 2011 14:00:37 +0100
> 
> Send london.pm mailing list submissions to
> london.pm at london.pm.org
> 
> To subscribe or unsubscribe via the World Wide Web, visit
> http://london.pm.org/mailman/listinfo/london.pm
> or, via email, send a message with subject or body 'help' to
> london.pm-request at london.pm.org
> 
> You can reach the person managing the list at
> london.pm-owner at london.pm.org
> 
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of london.pm digest..."
> 
> 
> Today's Topics:
> 
> 1. Re: Someone needs to take jwz aside... (Paul Makepeace)
> 2. Re: Someone needs to take jwz aside... (Denny)
> 3. Re: Someone needs to take jwz aside... (Peter Edwards)
> 4. Re: Cool/useful short examples of Perl? (Abigail)
> 5. Re: Cool/useful short examples of Perl? (Bill Crawford)
> 6. Re: Cool/useful short examples of Perl? (Tom Hukins)
> 7. Re: Cool/useful short examples of Perl? (Paul Makepeace)
> 8. Re: Cool/useful short examples of Perl? (Peter Corlett)
> 9. Re: Cool/useful short examples of Perl? (Roger Burton West)
> 10. Re: Cool/useful short examples of Perl? (David Matthewman)
> 
> 
> ----------------------------------------------------------------------
> 
> Message: 1
> Date: Wed, 8 Jun 2011 12:07:01 +0100
> From: Paul Makepeace <paulm at paulm.com>
> Subject: Re: Someone needs to take jwz aside...
> To: "London.pm Perl M[ou]ngers" <london.pm at london.pm.org>
> Message-ID: <BANLkTinumqtmy=Tmbpx7yh0XLtTok90nJg at mail.gmail.com>
> Content-Type: text/plain; charset=ISO-8859-1
> 
> On Wed, Jun 8, 2011 at 11:21, David Cantrell <david at cantrell.org.uk> wrote:
> > Of course, it's possible that the Comprehensive Python Archive Network
> > or similar for ruby/javascript/java/C/whatever does exist but I just
> > can't find it. ?But then, if I can't find it, it's not much use.
> 
> (If you were a python programmer and yet had still somehow managed to
> assiduously avoid all mentions of it, you could search for 'python
> packages' (because that's what they're called in python) and would
> find the top result is http://pypi.python.org/pypi)
> 
> 
> Paul
> 
> 
> 
> ------------------------------
> 
> Message: 2
> Date: Wed, 08 Jun 2011 12:15:51 +0100
> From: Denny <2011 at denny.me>
> Subject: Re: Someone needs to take jwz aside...
> To: "London.pm Perl M[ou]ngers" <london.pm at london.pm.org>
> Message-ID: <1307531751.13033.12.camel at serenity.denny.me>
> Content-Type: text/plain; charset="utf-8"
> 
> On Wed, 2011-06-08 at 12:07 +0100, Paul Makepeace wrote:
> > On Wed, Jun 8, 2011 at 11:21, David Cantrell <david at cantrell.org.uk> wrote:
> > > Of course, it's possible that the Comprehensive Python Archive Network
> > > or similar for ruby/javascript/java/C/whatever does exist but I just
> > > can't find it. But then, if I can't find it, it's not much use.
> > 
> > (If you were a python programmer and yet had still somehow managed to
> > assiduously avoid all mentions of it, you could search for 'python
> > packages' (because that's what they're called in python) and would
> > find the top result is http://pypi.python.org/pypi)
> 
> As helpfully documented here:
> http://wiki.python.org/moin/MovingToPythonFromOtherLanguages
> 
> -------------- next part --------------
> A non-text attachment was scrubbed...
> Name: not available
> Type: application/pgp-signature
> Size: 490 bytes
> Desc: This is a digitally signed message part
> Url : http://london.pm.org/pipermail/london.pm/attachments/20110608/5c15a72b/attachment-0001.pgp
> 
> ------------------------------
> 
> Message: 3
> Date: Wed, 8 Jun 2011 12:19:15 +0100
> From: Peter Edwards <peter at dragonstaff.co.uk>
> Subject: Re: Someone needs to take jwz aside...
> To: "London.pm Perl M[ou]ngers" <london.pm at london.pm.org>
> Message-ID: <BANLkTimEAhQ-+dc4sk3fBbHM7LkLU9Hcgw at mail.gmail.com>
> Content-Type: text/plain; charset=ISO-8859-1
> 
> >
> > On Wed, 8 Jun 2011, David Cantrell wrote:
> >
> > It's the lack of a CPAN-a-like for any other language that keeps me
> >> coming back to perl.
> >>
> >> Of course, it's possible that the Comprehensive Python Archive Network
> >> or similar for ruby/javascript/java/C/whatever does exist but I just
> >> can't find it. But then, if I can't find it, it's not much use.
> >>
> >>
> >> Python repo
> http://pypi.python.org/pypi
> 
> It was fairly chastening a couple of years back looking for a library
> implementing Role Based Access Control and finding that there was a Python
> one but no Perl one
> http://pypi.python.org/pypi?%3Aaction=search&term=role+based+access+control&submit=search
> http://search.cpan.org/search?query=role+based+access+control&mode=all
> 
> Then when I was doing WxWidgets programming from ActivePerl having to use
> the wxPython library docs http://www.wxpython.org/ because they were more up
> to date and complete than the Perl ones
> http://wxperl.sourceforge.net/documentation.html in terms of calling from a
> wrapper (more useful than the C++ docs).
> 
> 
> Node.js repo
> http://npm.mape.me/
> V8 seems to work well on Unix and takes little code to implement an
> event-driven networking app using server-side JS.
> 
> If you can get over the 'Nam-style flashbacks to old skool javascript hacks
> for IE5.0
> 
> 
> Regards, Peter
> http://perl.dragonstaff.co.uk
> 
> 
> ------------------------------
> 
> Message: 4
> Date: Wed, 8 Jun 2011 14:00:41 +0200
> From: Abigail <abigail at abigail.be>
> Subject: Re: Cool/useful short examples of Perl?
> To: "London.pm Perl M\[ou\]ngers" <london.pm at london.pm.org>
> Message-ID: <20110608120041.GA26510 at almanda>
> Content-Type: text/plain; charset=us-ascii
> 
> On Wed, Jun 08, 2011 at 09:24:50AM +0100, Dirk Koopman wrote:
> > On 08/06/11 08:31, Abigail wrote:
> >>
> >>
> >> unless (!something) {
> >> ...
> >> }
> >> else {
> >> ... # Unless not something isn't true.
> >> }
> >>
> >
> > An earnest question in the interview test along the lines of "what does 
> > this mean and when would you use it" should weed several people out.
> >
> > Instant sacking (or promotion if in Britain) on sight would seem to be 
> > an answer.
> >
> 
> 
> I'd rather go for sacking people that don't know the difference 
> between 
> 
> if (something) { ... }
> 
> and
> 
> unless (!something) { ... }
> 
> 
> 
> Or does everyone think they are always equivalent?
> 
> 
> 
> Abigail
> 
> 
> ------------------------------
> 
> Message: 5
> Date: Wed, 8 Jun 2011 13:10:28 +0100
> From: Bill Crawford <billcrawford1970 at gmail.com>
> Subject: Re: Cool/useful short examples of Perl?
> To: "London.pm Perl M[ou]ngers" <london.pm at london.pm.org>
> Message-ID: <BANLkTinf9Yu_aJbYpspSV71uMg0Ue9az8w at mail.gmail.com>
> Content-Type: text/plain; charset=UTF-8
> 
> On 8 June 2011 13:00, Abigail <abigail at abigail.be> wrote:
> 
> > I'd rather go for sacking people that don't know the difference
> > between
> >
> > ? ?if (something) { ... }
> >
> > and
> >
> > ? ?unless (!something) { ... }
> >
> >
> >
> > Or does everyone think they are always equivalent?
> 
> There are those (though I wouldn't be so stern) who would advocate
> sacking people who wrote overloaded operators that made them not do
> the same thing :)
> 
> > Abigail
> 
> Will.
> 
> 
> 
> ------------------------------
> 
> Message: 6
> Date: Wed, 8 Jun 2011 13:17:08 +0100
> From: Tom Hukins <tom at eborcom.com>
> Subject: Re: Cool/useful short examples of Perl?
> To: "London.pm Perl M\[ou\]ngers" <london.pm at london.pm.org>
> Message-ID: <20110608121708.GB6118 at eborcom.com>
> Content-Type: text/plain; charset=us-ascii
> 
> On Wed, Jun 08, 2011 at 02:00:41PM +0200, Abigail wrote:
> > I'd rather go for sacking people that don't know the difference 
> > between 
> > 
> > if (something) { ... }
> > 
> > and
> > 
> > unless (!something) { ... }
> 
> It's sunny outside and pubs are open: I can think of worse times to
> lose my job.
> 
> > Or does everyone think they are always equivalent?
> 
> I'm not everyone, and with a language as flexible as Perl I hesitate
> to make strong statements involving words like "always", but I don't
> recall encountering a situation where they differ.
> 
> In response to your question, I started out thinking about "zero but
> true" values, but this doesn't matter because double negation of
> truthfulness won't care about the value. So I got stuck.
> 
> The only special situation I can think of would be when someone
> overloads the "!" operator. I would console anyone doing this on code
> I maintain by mentioning that it's sunny outside and pubs are open.
> 
> I suspect I've missed lots of other interesting syntactical
> peculiarities, though. Would you mind sharing them?
> 
> Tom
> 
> 
> ------------------------------
> 
> Message: 7
> Date: Wed, 8 Jun 2011 13:41:29 +0100
Paul Makepeace paulm at paulm.com wrote:
> On Wed, Jun 8, 2011 at 13:17, Tom Hukins <tom at eborcom.com> wrote:
> > On Wed, Jun 08, 2011 at 02:00:41PM +0200, Abigail wrote:
> >> I'd rather go for sacking people that don't know the difference
> >> between
> >>
> >> ? ? if (something) { ... }
> >>
> >> and
> >>
> >> ? ? unless (!something) { ... }
> >
> > It's sunny outside and pubs are open: ?I can think of worse times to
> > lose my job.
> >
> >> Or does everyone think they are always equivalent?
> >
> > I'm not everyone, and with a language as flexible as Perl I hesitate
> > to make strong statements involving words like "always", but I don't
> > recall encountering a situation where they differ.
> 
> $ perl -le 'print "$_ == !!$_ ? ", $_ == !!$_ ? "yes" : "no" for (-1,
> 0, 1, 2, undef)'
> -1 == !!-1 ? no
> 0 == !!0 ? yes
> 1 == !!1 ? yes
> 2 == !!2 ? no
> == !! ? yes

Um: you're doing a numeric comparison with a boolean rhs. If you do this:

$ perl -le 'print "$_ == !!$_ ? ", $_ ? !!$_ ? "yes" : "no" : !!!$_ ? "fyes" : "fno" for (-1,0, 1, 2, undef)'
-1 == !!-1 ? yes
0 == !!0 ? fyes
1 == !!1 ? yes
2 == !!2 ? yes
== !! ? fyes

It seems to back Tom up (ooh - triple negative).

Regards
Chris 		 	   		  


More information about the london.pm mailing list