Formatting lists of integers
Hello, quick question. Is there a module that will turn eg the list 1,2,3,4,6,7,9,20 into the string 1-4, 6-7, 9, 20 (or something similar)? Kake
Re: Formatting lists of integers
On Mon, 24 Mar 2003, Kate L Pugh wrote: Hello, quick question. Is there a module that will turn eg the list 1,2,3,4,6,7,9,20 into the string 1-4, 6-7, 9, 20 (or something similar)? This was a Perl Quiz Of The Week question (week #6) http://perl.plover.com/~alias/list.cgi?mss:33:200211:eibghlhlndepedndcige Mark. -- #!/usr/bin/perl -T use strict; use warnings; print q{Mark Fowler, [EMAIL PROTECTED], http://twoshortplanks.com/};
Re: Formatting lists of integers
On Mon, 24 Mar 2003, Kate L Pugh wrote: Hello, quick question. Is there a module that will turn eg the list 1,2,3,4,6,7,9,20 into the string 1-4, 6-7, 9, 20 (or something similar)? On Mon 24 Mar 2003, Mark Fowler [EMAIL PROTECTED] wrote: This was a Perl Quiz Of The Week question (week #6) http://perl.plover.com/~alias/list.cgi?mss:33:200211:eibghlhlndepedndcige Ah, thanks, I knew I'd seen it somewhere before. Set::IntSpan is my bitch. Kake
Re: Formatting lists of integers
On Mon, 24 Mar 2003 14:09:15, Kate L Pugh [EMAIL PROTECTED] said: Is there a module that will turn eg the list 1,2,3,4,6,7,9,20 into the string 1-4, 6-7, 9, 20 (or something similar)? I ended up writing a script to do this a few years ago, after looking at obvious places for it to be (like List::Util, which is in core) and not finding anything. When it came up again on the QotW list recently, I looked at merging it into List::Util, and found that its methods are all written in XS (which makes sense). Being a bear of little XS brane, I wasn't up to rewriting my code in XS, but I've just had a thought that it would be a nice thing for someone to do as a demonstration for the list, or as part of the new mentoring idea or something. If anyone's interested, here's my original code. It's not great - back in 2001, I knew even less Perl than I do now - but it's not golf-like either, and the lack of optimisations or use of next/last probably make it easier to translate to XS than it could be otherwise: == #!/usr/bin/perl -w my @approx = @ARGV; my ($i, $inrange, $start, $end, $more); use strict; # Overview: # - Loop through the array. # - If the element after current matches (cur+1): #- Extend a range if we're in one. #- Set up a range if we aren't. # - If the element after current _isn't_ (cur+1): #- Mark/print the end of a range, or #- Print a number on its own if we weren't in a range. # - If the element after current just doesn't exist at all: #- Finish off a range or number tidily. map { # Loop through the array, using $_. my $cur= $approx[$_]; my $next = $approx[$_+1] if defined $approx[$_+1]; if ($next) { # Is there an array element after this one? if ($next != ($cur + 1)) { # If the next element _isn't_ current+1.. if ($inrange) { # If we're in a range, it needs to be finished. print $start-$end,; $inrange = 0; } else { # We're not in a range. print $cur,; } } else { # If the next array element is cur+1. if ($inrange) { # If we're already in a range, extend it by 1. $end++; } if (not $inrange) { # We're not in a range. Set start/end/inrange. $start = $approx[$_]; $end = $approx[$_+1]; $inrange = 1; } } } else { # It's the last element. Make things look tidy. if ($inrange) { print $start-$end\n; } else { print $cur\n; } } } 0..$#approx # -- end. - Chris. -- $a=printf.net; Chris Ball | [EMAIL PROTECTED] | www.$a | finger: [EMAIL PROTECTED] | Banks use perl? Let me take my $money out. | Only banks for rich people. Banks for people like you use COBOL. | -- gale:[EMAIL PROTECTED], 2002-08-26.
Re: [OT] PDA recommendation.
I've had my Zaurus SL-5500 for a couple of months. Mmmm. I haven't yet got any wireless connectivity in it, but it spends all day sitting in its synchronization cradle at work or home anyway. The PIM stuff works fine, though I haven't used a separate PDA before so I can't really compare it. My highlights: - gcc and Perl. You really can write Perl and C on the bus, I happily fart about with bad sound synthesis and the Perl Quiz of the Week on the number 12 regularly. - Ogg Vorbis player - Repton (the BBC Micro classic, brought a lump to my throat when I first played that!) - Powerchord (guitar chord dictionary and tuner with audio) - Mirroring websites and PDF's for reference - 512mb of CompactFlash for £115, and you've still got an SD slot free Bad things: Though all the Qtopia stuff can rotate, it's bolted on slightly awkwardly rather than an being integral part of most apps. Opera can choke on large PDF's, and the Media Player often seems unhappy about large files too but ogg123 works fine. Hang on for the SL-5600 if you've got the willpower (built in speakers and better battery would be worth having) but £199+vat is really a bargain anyway. Face it, we lust for toys. This is the ultimate in wget'ing, SSH'ing, wireless network-sniffing, cross-compiling, touchscreen fun. Give in to the dark side, let go of the fig-leaves of necessity and usefulness, we have paper for that.
Re: Beginners Help Needed again
On Fri, 21 Mar 2003, Brian Smart wrote: I am trying to get the following cgi script called ice_cream.cgi to work. I has been copied from the 'Learning perl' book. When I call the script I get an error message: Error Message: Permission denied Error Number: 13 Can someone explain what I might be doing wrong? It's not your script. The error is specifically about a permissions issue. Is the script executable? Assuming you are on a *NIX platform chmod u+x the script. Jason Clifford -- UKFSN.ORG Finance Free Software while you surf the 'net http://www.ukfsn.org/ Get the T-Shirt Now
Re: [OT] PDA recommendation.
Moran,B wrote: I've had my Zaurus SL-5500 for a couple of months. Mmmm. (...) My highlights: We have one at work to which we're porting our stuff, I must the commonly expressed highlight here is the very nice graphical port of Nethack. Endless hours of amusement! -- Robin Berjon [EMAIL PROTECTED] Research Engineer, Expwayhttp://expway.fr/ 7FC0 6F5F D864 EFB8 08CE 8E74 58E6 D5DB 4889 2488
[ANNOUNCE] Socal Meeting Thurs 3rd April @ The Windmill in Mayfair
Announcing the April 2003 London Perl Mongers on Thurs 3rd April. As usual, the meeting will start from 7pm, but early birds will probably be in the pub from 6pm onwards (Food is served in the pub so most people come straight from work.) The meetings normally go onto closing time, so those travelling in from further away need not worry about arriving late. This month's social meeting is located in a very central pub - just between Piccadilly Circus and Oxford Street stations. We've booked the room to the back of the pub (just right of the bar.) http://www.streetmap.co.uk/streetmap.dll?G2M?X=529001Y=180921A=YZ=1 http://grault.net/cgi-bin/grubstreet.pl?Windmill,_W1S_2AT Full directions (not that you really need them - it's really simple to get to the pub) are at the end of this email. Social meets offer a chance for people to meet up and put a face to a name (or an email address or irc nick.) Perl is the normal topic of discussion, but just like the list and IRC, other things are discussed too; Both the most hard core Perl coders and the many non-Perl programmers loosely affiliated to London.pm are more than welcome and neither normally find themselves lacking for conversation. Directions from Oxford Circus: Walk south out of the tube station onto Regent Street (not onto Oxford Street and directly away from the church). After about 200m, turn right down Conduit Street (roughly opposite Hamley's) and then turn right again down a smaller road called Mill Street, where you'll find the pub. Directions from Piccadilly Circus: Come out of the station and head north up Regent Street. After about 500m turn left onto Conduit Street (which is approximately opposite Hamley's.) After this turn right onto a smaller road called Mill Street, where you'll find the pub. Directions from Green Park: Turn east (left) out of the station, and walk for about two hundred meters. Shortly before the Royal Academy of Arts, on your left will be Old Bond Street. Walk up here about 300 meters till you'll get to Conduit Street on your right. Walk down here, and take the second left down a smaller road called Mill Street, where you'll find the pub. Directions from Bond Street: Turn east (right) out of the station. After about a hundred meters you should come to New Bond Street on your right. Walk down here for about 400m, and then turn left onto Conduit Street shortly after Sotherby's. The second left is Mill Street, where you will find the pub. Hope to see you there. Mark. P.S. I'm away for the next week. In the meantime, Kate will look after any problems with the social meet, and [EMAIL PROTECTED] will still be answered by someone in my absence (after all that's the point in having these person agnostic role emails.) -- #!/usr/bin/perl -T use strict; use warnings print q{Mark Fowler, [EMAIL PROTECTED], http://twoshortplanks.com/};
[ANNOUNCE] Mini-Tech Meeting: April 14th @ Yahoo!
Announcing London.pm mini-Techmeet Building Websites: Templating Engines and Processing Content This is a short and sweet tech meet, followed by an extended session in the local pub to allow people to talk directly to the speakers before they have to shoot off home. Speakers confirmed so far are: Andy Wardley Template Toolkit David Wheeler Bricolage Mark Lester Jake, Yahoo! interal templating language The current plan for the evening is to have a half hour talk by David Wheeler on Bricolage, then a 40min panel discussion by the other panel members with questions from the audience. The meeting will again be held at Yahoo!'s UK offices located near Victoria. This is the same venue as the previous meeting in March, full directions are below. As before you should aim to get to Yahoo! for 7pm, for a 7.15pm sharp start. The meeting should be completed by half eight, and we can all return to the pub. Directions to Yahoo!: The nearest tube station to Yahoo is Victoria, and almost all busses run to the station, though having said that it's within easy walking distance of Sloane Square. Here's a couple of maps: http://makeashorterlink.com/?E50A22503 http://www.streetmap.co.uk/streetmap.dll?G2M?X=528517Y=178491A=YZ=1 Directions from Victoria: Come out of Victoria Station onto Buckingham Palace Road (This is the road that busses enter the bus station from - you can follow the signs to Victoria Coach Station if you want) You simply have to follow the road south/west (left) for five minutes you get to Yahoo!. Keep walking along the road, past the shopping centre on your left, past the coach station on your right, until you get to a cross roads (where Ebury Bridge road branches left and Pimlico Rd branches right, just past the police station on your right.) The first building on the right hand side of Buckingham Palace Road after the crossroads is Yahoo! - identifiable as all the furniture inside is the corporate Yahoo! yellow and purple. You will probably have to identify yourself with Security when you get to the office, who will send you downstairs to the canteen where the meeting is being held. All this info is on the website: http://london.pm.org/meetings/locations/yahoo.html Hope to see you there. Mark. -- #!/usr/bin/perl -T use strict; use warnings; print q{Mark Fowler, [EMAIL PROTECTED], http://twoshortplanks.com/};
Re: Wanted: new maintainer for Mail::SpamTest::Bayesian
On Monday, March 24, 2003 13:23 + Roger Burton West [EMAIL PROTECTED] wrote: I don't have time to maintain Mail::SpamTest::Bayesian, and it needs some bug fixes (as well as a maintainer who's still interested in using it). Anyone in London.pm fancy taking it over? Not me. However, the latest version of spamassassin does Bayesian Things, so maybe they'd be willing to take it over? -- David Cantrell, experimenting with Weird Mac Mail Client