Re: Duh v D'oh
Paul Makepeace wrote: foreach my $given_source (%publication_map_by_name) { ENOKEYS: You are locked out of the house. A
Re: Duh v D'oh
On Fri, Nov 7, 2008 at 11:48 AM, Peter Corlett [EMAIL PROTECTED] wrote: On Thu, Nov 06, 2008 at 05:00:16PM +, Nigel Rantor wrote: Paul Makepeace wrote: [...] If it's not staring out at you, you're possibly also a python programmer. Python here arguably DWIM better than perl. Does python give you the keys by default? Sort of. In Python, for loops over values returned by an iterator, and a hash implements that interface. The interface is pretty clean, my_dict = {'a': 1, 'b': 2} for k in my_dict: print k gives, a b for k, v in my_dict.items(): print k, v gives, a 1 b 2 (ObPedantry, .iteritems() is preferred since it evaluates lazily with a generator.) P
Re: Duh v D'oh
On Thu, Nov 6, 2008 at 1:33 PM, Paul Makepeace [EMAIL PROTECTED] wrote: Following on the theme from a conversation with Mark at Dim Sum today*, spot the mistake I just wasted an hour on, my $publication_stats = [['Source', 'ID Publication', 'Article count']]; foreach my $given_source (%publication_map_by_name) { push @$publication_stats, [$given_source, $publication_map_by_name{$given_source}, $article_count_by_source{$given_source}]; } If it's not staring out at you, you're possibly also a python programmer. Python here arguably DWIM better than perl. Paul * there's some mistakes where you at the end go D'oh! because perl is messing you around with its weirdness or otherwise non-intuitive behavior. Duh when you're messing around and just not paying attention. I wouldn't call that non-intuitive, it's a matter of culture. Perl coders are used to being verbose about whether they want keys/values from a hash. If someone changed the behavior to make a hash in list context return it's keys, you would confuse a lot of Perl programmers out there too. And I'm particularly fond of perl's behaviour because it allows interesting cookbook tricks such as %config = (%default, %user_provided) -- Eden Cardim Need help with your Catalyst or DBIx::Class project? Code Monkeyhttp://www.shadowcat.co.uk/catalyst/ Shadowcat Systems Ltd. Want a managed development or deployment platform? http://edenc.vox.com/http://www.shadowcat.co.uk/servers/
Re: Duh v D'oh
On Fri, Nov 07, 2008 at 09:45:34AM -0300, Eden Cardim wrote: On Thu, Nov 6, 2008 at 1:33 PM, Paul Makepeace [EMAIL PROTECTED] wrote: Following on the theme from a conversation with Mark at Dim Sum today*, spot the mistake I just wasted an hour on, my $publication_stats = [['Source', 'ID Publication', 'Article count']]; foreach my $given_source (%publication_map_by_name) { push @$publication_stats, [$given_source, $publication_map_by_name{$given_source}, $article_count_by_source{$given_source}]; } If it's not staring out at you, you're possibly also a python programmer. Python here arguably DWIM better than perl. Paul * there's some mistakes where you at the end go D'oh! because perl is messing you around with its weirdness or otherwise non-intuitive behavior. Duh when you're messing around and just not paying attention. I wouldn't call that non-intuitive, it's a matter of culture. Perl coders are used to being verbose about whether they want keys/values from a hash. If someone changed the behavior to make a hash in list context return it's keys, you would confuse a lot of Perl programmers out there too. And I'm particularly fond of perl's behaviour because it allows interesting cookbook tricks such as %config = (%default, %user_provided) I don't think the Python behaviour excludes the above trick. It is as if Python has a context that Perl doesn't have [1]: iterator context. In such a context, just the keys are returned. No doubt there will be Perl code that will break if Perl was changed such that 'for(EXPR)' provides iterator context to EXPR, and a hash in such a context acted as if it was 'scalar each %hash', but I think it would not break that much. 'for (%hash)' isn't all that useful. Now I think that it isn't worth breaking Perl to introduce this, but it would have been nice if it was there from the start. Then people could written 'for ()' without slurping in the entire file, and the 'while ()' construct wouldn't have needed fixing around 5.004. [1] There are some constructs in Perl that behave like an iterator, in scalar context, //g in scalar context, for (EXPR .. EXPR) to name a view. Abigail
Re: Duh v D'oh
On Thu, Nov 06, 2008 at 05:00:16PM +, Nigel Rantor wrote: Paul Makepeace wrote: [...] If it's not staring out at you, you're possibly also a python programmer. Python here arguably DWIM better than perl. Does python give you the keys by default? Sort of. In Python, for loops over values returned by an iterator, and a hash implements that interface.
Re: Doing a non-standard ioctl in Perl
2008/11/6 Roger Burton West [EMAIL PROTECTED]: For various reasons, I want to do an EVIOCGRAB ioctl. perldoc -f ioctl tells me require sys/ioctl.ph, and gives all sorts of scary warnings. But EVIOCGRAB isn't in sys/ioctl.ph. What's the approved way of doing this? That's the only ioctl I'm likely to want to use in this program, so I don't particularly fancy converting a whole bunch of others that I'm not going to need. If it helps: linux/input.h:#define EVIOCGRAB _IOW('E', 0x90, int) Is there a linux/input.ph or is it possible to generate one from the linux/input.h using h2ph ? EVIOCGRAB would be something like: sub EVIOCGRAB () { _IOW(ord('E'), 0x90, 'int');} where _IOW is defined in asm-generic/ioctl.ph on my system. /J\
Re: Duh v D'oh
On Fri, Nov 7, 2008 at 12:45 PM, Eden Cardim [EMAIL PROTECTED] wrote: On Thu, Nov 6, 2008 at 1:33 PM, Paul Makepeace [EMAIL PROTECTED] wrote: Following on the theme from a conversation with Mark at Dim Sum today*, spot the mistake I just wasted an hour on, my $publication_stats = [['Source', 'ID Publication', 'Article count']]; foreach my $given_source (%publication_map_by_name) { push @$publication_stats, [$given_source, $publication_map_by_name{$given_source}, $article_count_by_source{$given_source}]; } If it's not staring out at you, you're possibly also a python programmer. Python here arguably DWIM better than perl. Paul * there's some mistakes where you at the end go D'oh! because perl is messing you around with its weirdness or otherwise non-intuitive behavior. Duh when you're messing around and just not paying attention. I wouldn't call that non-intuitive, it's a matter of culture. Perl coders are used to being verbose about whether they want keys/values from a hash. If someone changed the behavior to make a hash in list context return it's keys, you would confuse a lot of Perl programmers out there too. And I'm particularly fond of perl's behaviour because it allows interesting cookbook tricks such as %config = (%default, %user_provided) I don't think that's so exciting that this equivalent isn't acceptable in its stead, config = default config.update(user_provided) I think I prefer the slightly more explicit nature of this way , even. Would be interesting exercise to compare/contrast these perl idioms and their Language X equivalents and see where perl really shines, or not. P -- Eden Cardim Need help with your Catalyst or DBIx::Class project? Code Monkeyhttp://www.shadowcat.co.uk/catalyst/ Shadowcat Systems Ltd. Want a managed development or deployment platform? http://edenc.vox.com/http://www.shadowcat.co.uk/servers/
Re: [ANNOUNCE] November social - Edgar Wallace, WC2 - Thurs 6 Nov
On Tue 04 Nov 2008, Kake L Pugh [EMAIL PROTECTED] wrote: Hello! The November social of the London Perlmongers is a mere two days away. I hope you are all excited. This month, we're going back to the Edgar Wallace, where we have the upstairs function room booked from 6:30pm. I had to run away early last night for a previous engagement, and only a handful of people had arrived at that point, so... any feedback (good or bad) on last night's social? (In terms of the pub, I mean, not in terms of the Perlmongers.) Kake
Re: Duh v D'oh
On Fri, Nov 7, 2008 at 2:08 PM, Paul Makepeace [EMAIL PROTECTED] wrote: I don't think that's so exciting that this equivalent isn't acceptable in its stead, config = default config.update(user_provided) Ditto :) I think I prefer the slightly more explicit nature of this way , even. Well, the way I see it, for k in my_dict is also implicit, and since you've manifested your preference of that construct over the explicit for keys %dict, in favour of readability, it is now clear that YMMV in regard to explicitness. Would be interesting exercise to compare/contrast these perl idioms and their Language X equivalents and see where perl really shines, or not. Yes, that'd be cool and instructive, since I haven't had the time to dig in to things like Python and Ruby. I'll confess that my vision of Perl practicity might be clouded by the previous C, C++ and Java experiences. -- Eden Cardim Need help with your Catalyst or DBIx::Class project? Code Monkeyhttp://www.shadowcat.co.uk/catalyst/ Shadowcat Systems Ltd. Want a managed development or deployment platform? http://edenc.vox.com/http://www.shadowcat.co.uk/servers/
Re: Duh v D'oh
Paul Makepeace wrote: On Fri, Nov 7, 2008 at 11:48 AM, Peter Corlett [EMAIL PROTECTED] wrote: On Thu, Nov 06, 2008 at 05:00:16PM +, Nigel Rantor wrote: Paul Makepeace wrote: [...] If it's not staring out at you, you're possibly also a python programmer. Python here arguably DWIM better than perl. Does python give you the keys by default? Sort of. In Python, for loops over values returned by an iterator, and a hash implements that interface. But by interface here we just mean it implements certain named methods that have certain semantics that everyone agrees make it an iterator...right? I mean, it's like C++ and templates, we duck type things rather than actually implement interfaces as you are required to do in Java. The interface is pretty clean, my_dict = {'a': 1, 'b': 2} for k in my_dict: print k gives, a b for k, v in my_dict.items(): print k, v gives, a 1 b 2 (ObPedantry, .iteritems() is preferred since it evaluates lazily with a generator.) Yes, well, Perl has 'each' for iterating over pairs, so they look almost identical. The main difference I can see is that python defaults to assuming you want the keys of a hash when iterating rather than the values. It's a fair enough design decision, but like any decision it's not always going to be the right thing. But yes, I agree, it is kind of DWIMier than iterating over both keys and values for a hash. If you look around though, lots of languages do this better than Perl these days. I was going to mention some languages but I can't be arsed with the inevitable flaming session. n p.s. I'm still reading the python list for a laugh. they just had a *HUGE* rant/discussion about what rebinding means and how you describe it to people coming from other languages.
Re: [ANNOUNCE] November social - Edgar Wallace, WC2 - Thurs 6 Nov
On Fri, 7 Nov 2008, Kake L Pugh wrote: On Tue 04 Nov 2008, Kake L Pugh [EMAIL PROTECTED] wrote: Hello! The November social of the London Perlmongers is a mere two days away. I hope you are all excited. This month, we're going back to the Edgar Wallace, where we have the upstairs function room booked from 6:30pm. I had to run away early last night for a previous engagement, and only a handful of people had arrived at that point, so... any feedback (good or bad) on last night's social? (In terms of the pub, I mean, not in terms of the Perlmongers.) It was a bit quieter than some of the previous socials there, which meant it was a bit less of a squeeze to get from tables to the bar. The steak sarnie was still tasty, the apple and pear crumble was ok but suffers from having built-in custard. the hatter
Re: [ANNOUNCE] November social - Edgar Wallace, WC2 - Thurs 6 Nov
On Fri 07 Nov 2008, the hatter [EMAIL PROTECTED] wrote: It was a bit quieter than some of the previous socials there, which meant it was a bit less of a squeeze to get from tables to the bar. The Bridge House last month was fairly quiet, too. Are the Perlmongers feeling the credit crunch? Kake
Re: [ANNOUNCE] November social - Edgar Wallace, WC2 - Thurs 6 Nov
On 7 Nov 2008, at 20:19, Kake L Pugh wrote: On Fri 07 Nov 2008, the hatter [EMAIL PROTECTED] wrote: It was a bit quieter than some of the previous socials there, which meant it was a bit less of a squeeze to get from tables to the bar. The Bridge House last month was fairly quiet, too. Are the Perlmongers feeling the credit crunch? The beer in the Bridge House is expensive and rather poor of late, service is often conspicuous by its absence, and it's a bit of a trek to get to. The Edgar Wallace is a cracking boozer, but I just wasn't feeling up to it last night.
Re: Duh v D'oh
Eden Cardim wrote: Yes, that'd be cool and instructive, since I haven't had the time to dig in to things like Python and Ruby. I'll confess that my vision of Perl practicity might be clouded by the previous C, C++ and Java experiences. It would be interesting if we had some basis for comparison. Paul, how's about you give us some things to accomplish and we tell you how we'd do them in different languages? I just think it might be unfair, or perhaps be perceived that way, if we chose our own examples and their other-language equivalents So, nothing too complex, it has to be do-able in less than a hundred or so lines of Perl. Or does that not make any sense? n