From grant at mclean.net.nz Sun Feb 6 17:09:55 2005 From: grant at mclean.net.nz (Grant McLean) Date: Sun Feb 6 17:10:12 2005 Subject: [Wellington-pm] Meeting in two weeks Message-ID: <1107738595.14768.13.camel@localhost> Hi Mongers Just a quick reminder that the next Perl Mongers meeting is in two weeks on Monday the 21st of Feb. That's one week later than usual to allow people to celebrate the card company festival on the 14th without missing their monthly Perl fix. Our presenters now only have 13 days left before they have to start putting their presentations together. :-) Since the February meeting is a week late, the following meeting in March is a scan 5 weeks from today. I'm sure you've all been giving a lot of thought to your 5 minute lightning talks for the March meeting. If you need to refresh your memory about what you'll be doing, here's the message from the archive: http://mail.pm.org/pipermail/wellington-pm/2004-December/000232.html Regards Grant From grant at mclean.net.nz Sun Feb 6 23:46:22 2005 From: grant at mclean.net.nz (Grant McLean) Date: Sun Feb 6 23:46:50 2005 Subject: [Wellington-pm] [Fwd: Newsletter from O'Reilly UG Program, Feb 3] Message-ID: <1107762382.4463.6.camel@localhost> -------- Forwarded Message -------- > From: Marsee Henon > To: perlmongers@catalyst.net.nz > Subject: Newsletter from O'Reilly UG Program, Feb 3 > Date: Thu, 03 Feb 2005 15:19:56 -0800 > ================================================================ > O'Reilly News for User Group Members > February 3, 2005 > ================================================================ > ---------------------------------------------------------------- > Book News > ---------------------------------------------------------------- > -AppleScript: The Missing Manual > -Creating Photomontages with Photoshop: A Designer's Notebook > -Internet Annoyances > -Google Hacking for Penetration Testers > -Home Networking Annoyances > -Linux Server Security, 2nd Edition > -Buffer Overflow Attacks > -Configuring NetScreen Firewalls > ---------------------------------------------------------------- > Upcoming Events > ---------------------------------------------------------------- > -Hadley Stern ("iPod & iTunes Hacks"), Boston Macintosh User Group, > Boston, MA--February 9 > -Tim O'Reilly, EclipseCon, Burlingame, CA--February 28-March 3 > -O'Reilly at PhotoShop World, Las Vegas, NV--March 9 > ---------------------------------------------------------------- > Conference News > ---------------------------------------------------------------- > -OSCON Call For Proposals Now Open > -Register for the 2005 O'Reilly Emerging Technology Conference, > San Diego, CA--March 14-17 > -Registration Is Open for the 2005 MySQL Users Conference, > Santa Clara, CA--April 18-21 > ---------------------------------------------------------------- > News > ---------------------------------------------------------------- > -Hacking Google > -Get Your Hands Dirty! > -"Make" subscriptions now available > -Don't Miss O'Reilly at LinuxWorld, Boston, MA--February 15-17 > -Programming eBay Web Services with PHP 5 and Services_Ebay > -Freevo: Freedom For Your TV > -Michael Stutz On Using Linux For Everyday Activities > -Top Ten AppleScript Tips > -Output Like a Pro with iPhoto 5 > -Fix Hot Spot Annoyances > -Working with Roaming User Profiles > -IRC Text to Speech with Java > -Internals of Java Class Loading > -Build Your Own PVR (for Free) with HackTV > -Featured Photographer--Ofer Halevi: The Art of Juxtaposition > -Learning Lab: Save 40% on Web Programming Certificate Courses > -A-Z Web Site Indexes Explained > > ================================================ > Book News > ================================================ > Did you know you can request a free book to review for your > group? Ask your group leader for more information. > > For book review writing tips and suggestions, go to: > http://ug.oreilly.com/bookreviews.html > > Don't forget, you can receive 20% off any O'Reilly, No Starch, > Paraglyph, Pragmatic Bookshelf, SitePoint, or Syngress book you > purchase directly from O'Reilly. > Just use code DSUG when ordering online or by phone 800-998-9938. > http://www.oreilly.com/ > > ***Free ground shipping is available for online orders of at > least $29.95 that go to a single U.S. address. This offer > applies to U.S. delivery addresses in the 50 states and Puerto Rico. > For more details, go to: > http://www.oreilly.com/news/freeshipping_0703.html > > ---------------------------------------------------------------- > New Releases > ---------------------------------------------------------------- > ***AppleScript: The Missing Manual > Publisher: O'Reilly > ISBN: 0596008503 > Macintosh's ultimate scripting tool, AppleScript, has one major > shortcoming: it comes without a manual. This Missing Manual fills the > void. While its hands-on approach, with dozens of scripting examples, > certainly keeps novices from feeling intimidated, this book is also suited > for professionals from system administrators to musicians, ensuring that > anyone can learn how to control Mac applications in timesaving and > innovative ways. > http://www.oreilly.com/catalog/applescripttmm/index.html > > Chapter 5, "Controlling Files," is available online: > http://www.oreilly.com/catalog/applescripttmm/chapter/index.html > > > ***Creating Photomontages with Photoshop: A Designer's Notebook > Publisher: O'Reilly > ISBN: 0596008589 > This collection of groundbreaking digital creations by well-known French > artists is a visual smorgasbord for digital imaging professionals, graphic > artists, photographers, and anyone involved in the creation of digital > images and animations. But it's more than a full-color feast for the eyes: > reflecting the very best of French graphic design, it guides Photoshop > users through all aspects of the photomontage creation process, from > initial concept through step-by-step execution. > http://www.oreilly.com/catalog/photoshopadn/ > > > ***Internet Annoyances > Publisher: O'Reilly > ISBN: 0596007353 > Recognizing the universal nature of the Net, "Internet Annoyances" strives > to make using the internet as stress-free as possible for everyone. This > insightful guide effectively addresses and presents solutions for the many > glitches that still complicate the internet experience. You'll learn how > to thwart would-be hackers, ensure greater security while surfing, > eliminate pop-up ads, maximize online services, conduct effective > searches, and much more. > > Chapter 8, "Searching Annoyances," is available online: > http://www.oreilly.com/catalog/internetannoy/chapter/index.html > > > ***Google Hacking for Penetration Testers > Publisher: Syngress > ISBN: 1931836361 > "Google Hacking for Penetration Testers" explores the explosive growth of > a technique known as "Google Hacking." This simple tool can be bent by > hackers and those with malicious intent to find hidden information, break > into sites, and access supposedly secure information. Borrowing the > techniques pioneered by malicious "Google hackers," this book aims to show > security practitioners how to properly protect clients from this often > overlooked and dangerous form of information leakage. > http://www.oreilly.com/catalog/1931836361/index.html > > > ***Home Networking Annoyances > Publisher: O'Reilly > ISBN: 0596008082 > Need a cure for the headaches associated with running a home network? This > book tackles all the common annoyances your network dishes up, whether > it's wired or wireless, Mac or PC. With a friendly, off-the-cuff approach, > this book guides you safely through common home networking glitches, > including file sharing, printing, security, and more. Take a stand against > annoyances now: this book is your ticket to serenity. > http://www.oreilly.com/catalog/homenetannoy/ > > Chapter 4, "File-Sharing Annoyances," is available online: > http://www.oreilly.com/catalog/homenetannoy/chapter/index.html > > > ***Linux Server Security, 2nd Edition > Publisher: O'Reilly > ISBN: 0596006705 > "Linux Server Security, 2nd Edition" expertly conveys to administrators > and developers the tricks of the trade that can help them avoid serious > security breaches. The book covers both background theory and practical, > step-by-step instructions for protecting a server that runs Linux. Geared > toward Linux users with little security expertise, the author explains > security concepts and techniques in clear language, beginning with the > fundamentals. Stay one step ahead of potential adversaries. > http://www.oreilly.com/catalog/linuxss2/ > > Chapter 12, "System Log Management and Monitoring," is available online: > http://www.oreilly.com/catalog/linuxss2/chapter/index.html > > > ***Buffer Overflow Attacks > Publisher: Syngress > ISBN: 1932266674 > The SANS Institute maintains a list of the "Top 10 Software > Vulnerabilities." Currently, over half of these vulnerabilities are > exploitable by buffer overflow attacks, which allow an attacker to run > arbitrary code on a victim's machine. This is the first book specifically > aimed at detecting, exploiting, and preventing the most common and > dangerous attacks. It provides specific, real code examples on exploiting > buffer overflow attacks from a hacker's perspective, and on defending > against these attacks for the software developer. > http://www.oreilly.com/catalog/1932266674/ > > > ***Configuring NetScreen Firewalls > Publisher: Syngress > ISBN: 1932266399 > "Configuring NetScreen Firewalls" delivers an in-depth look at the > NetScreen firewall product line. It covers all of the aspects of the > NetScreen product line from the SOHO devices to the Enterprise NetScreen > firewalls. Advanced troubleshooting techniques and the NetScreen Security > Manager are also covered. > http://www.oreilly.com/catalog/1932266399/index.html > > ================================================ > Upcoming Events > ================================================ > ***For more events, please see: > http://events.oreilly.com/ > > ***Hadley Stern ("iPod & iTunes Hacks"), Boston Macintosh User Group, > Boston, MA--February 9 > Come join this O'Reilly author to find out all the cool things that you > can do with your iPod! > Boston Macintosh User Group > MIT Building E51 > Room 315 > Cambridge, MA > http://www.bmac.org/meetings.html > > > ***Tim O'Reilly, EclipseCon, Burlingame, CA--February 28-March 3 > Tim is a keynote speaker at this event. > http://www.eclipsecon.org/2005/index.htm > > > ***O'Reilly at PhotoShop World, Las Vegas, NV--March 9 > Come by and say hi and check out our latest Digital Media books at our > booth (#220). > Mandalay Bay Resort, Las Vegas, NV > http://www.photoshopworld.com/ > > ================================================ > Conference News > ================================================ > ***OSCON Call For Proposals Now Open > Circle August 1-5 on your calendar and join us at the O'Reilly Open Source > Convention in beautiful Portland, Oregon. OSCON 2005 will be at the Oregon > Convention Center, where we'll have tutorials, sessions, parties, BOFs, > and a huge exhibit hall. > http://conferences.oreillynet.com/os2005/ > > The call for participation is open, and you're invited to submit a > proposal to lead tutorials and sessions. Visit the submissions page for > all the details on tracks and proposal guidelines. Proposals are due no > later than February 13, 2005. > http://conferences.oreillynet.com/cs/os2005/create/e_sess > > > ***2005 O'Reilly Emerging Technology Conference, > San Diego, CA--March 14-17 > This year's conference theme is "Remix," which infuses ETech's > roll-up-your-sleeves tutorials, to-the-point plenary presentations, and > real world focused breakout sessions. Come to ETech and discover how > applications and hardware are being deconstructed and recombined in > unexpected ways. Learn how users and customers are influencing new > interfaces, devices, business models, and services. For all the scoop on > tutorials, featured speakers, and conference events, check out: > http://conferences.oreillynet.com/etech/ > > Hurry up before it sells out! > > User Group members use code DSUG when you register, and receive 20% off > the registration price. > > To register for the conference, go to: > http://conferences.oreillynet.com/cs/et2005/create/ord_et05 > > > ***Register for the 2005 MySQL Users Conference, > Santa Clara, CA--April 18-21 > The MySQL Users Conference, co-presented by O'Reilly Media and MySQL AB, > brings together experts, users, and industry leaders with unique MySQL > insights, offering attendees a detailed look into new features in MySQL > 5.0, sessions and workshops designed to teach best practices, and exposure > to new open source technologies. > For more information, go to: > http://www.mysqluc.com/ > > User Group members who register before Febuary 28, 2005 get a double > discount. Use code DSUG when you register, and receive 20% off the > early registration price. > > To register for the conference, go to: > http://conferences.oreillynet.com/cs/mysqluc2005/create/ord_mysql05 > > ================================================ > News From O'Reilly & Beyond > ================================================ > --------------------- > General News > --------------------- > ***Hacking Google > With access to more than three million documents in over 30 languages, > Google is a researcher's dream. But like any invaluable tool, knowing the > insider tricks of the trade is a must to save time and needless effort. > Tara Calishain and Rael Dornfest, authors of "Google Hacks, 2nd Edition," > have set out to educate the masses to the ins and outs of Google. In > today's excerpt, they offer the inside scoop on scattersearching, > cartography, Google on the go, Gmail-lite, and AdSense. With over 150 > million Google searches conducted every day, why be just a number? > http://www.oreillynet.com/pub/a/network/excerpt/ggl_hcks/index.html > > > ***Get Your Hands Dirty! > Hackers of all stripes refuse to just take what they???re given. They???re > driven to remake it, and getting there is more than half the fun. Here at > O'Reilly, we've got the information you need to hack, remix, and master > technology at home and at work. In this letter for our Winter 2005 > Catalog, Tim O'Reilly talks about how we're celebrating the hacker > impulse. > http://tim.oreilly.com/articles/dirtyhands_0105.html > > You'll find all of Tim's collected writings and speeches at: > http://tim.oreilly.com/ > > > ***"Make" subscriptions now available > The annual subscription price for four issues is $34.95. When you > subscribe with this link, you'll get a free issue--the first one plus four > more for $34.95. So subscribe for yourself or friends with this great > offer for charter subscribers: five volumes for the cost of four. > Subscribe at: > https://www.pubservice.com/MK/Subnew.aspx?PC=MK&PK=M5ZUGLA > > --------------------- > Open Source > --------------------- > > ***Don't Miss O'Reilly at LinuxWorld, Boston, MA--Feb 15-17 > Stop by our booth (#509) to check out our latest Linux and open source > titles and listen to our authors including Jonathan Corbet ("Linux Device > Drivers, 3rd Ed."), Kyle D. Dent ("Postfix: The Definitive Guide"), Jay > Beale ("Snort 2.1 Intrusion Detection, 2nd Ed."), Sam Hiser and Tom > Adelstein ("Exploring the JDS Linux Desktop"), and Adam Trachtenberg ("PHP > Cookbook"). We will have daily demonstrations on our new magazine "Make" > and SafariU (http://academic.oreilly.com/safariu-more.csp). > > Here is our schedule of events: > http://www.oreilly.com/examples/oreilly/ug/linuxworld_speaker_sched.pdf > > > ***Programming eBay Web Services with PHP 5 and Services_Ebay > PHP 5 added several new features to the language, yet laundry lists and > high-level overviews don't really show what they are or why you might use > them. Fortunately, Adam Trachtenberg writes for us. Here's how to use the > new features of PHP 5 for writing web services clients. > http://www.onlamp.com/pub/a/php/2005/01/27/ebay_webservices.html > > > ***Freevo: Freedom For Your TV > PVRs may be the next big thing in home entertainment, but relying on a > closed box leaves you few options for customization. The Freevo project is > building a platform for developing television-aware applications, whether > recording, timeshifting, or general-purpose mayhem. Howard Wen explains > the Freevo project and interviews its developers. > http://www.linuxdevcenter.com/pub/a/linux/2005/01/27/freevo.html > > > ***Michael Stutz On Using Linux For Everyday Activities > Michael Stutz, author of "The Linux Cookbook, 2nd Edition" (No Starch) > discusses what inspired him to write this book, when he first started > using Linux, and other world views in this LinuxWorld interview. > http://www.linuxworld.com/story/47810.htm?DE=1 > > --------------------- > Mac > --------------------- > ***Top Ten AppleScript Tips > AppleScript lets you control Microsoft Word, Adobe Photoshop, FileMaker > Pro, and hundreds of other Mac programs with just a few lines of code. But > if you think of AppleScript as just a nerdy workflow-automation tool, > you're missing out on a lot of power. Truth is, AppleScript has lots of > hidden tricks and timesavers built in--and they all come for free with > your Mac. Adam Goldstein, author of "AppleScript: The Missing Manual," has > hand selected ten of the most useful tips for making AppleScript work for > you. > http://www.macdevcenter.com/pub/a/mac/2005/02/01/applscrpt_mm.html > > > ***Output Like a Pro with iPhoto 5 > Earlier, Derrick Story discussed how iPhoto 5's RAW capability lets you > input like a pro. But some of its new output features are quite > sophisticated. Here Derrick takes a look at how to create sophisticated > slideshows and QuickTime downloads using only iPhoto 5. > http://www.macdevcenter.com/pub/a/mac/2005/02/01/iphoto.html > > --------------------- > Windows/.NET > --------------------- > ***Fix Hot Spot Annoyances > Using a Wi-Fi hot spot is a great way to stay connected when you're away > from home or the office. But beware: you may be vulnerable to snoopers; > you may be unable to send email; and your connection may flake out. > Preston Gralla, author of "Internet Annoyances," fixes all your hot spot > woes. > http://www.windowsdevcenter.com/pub/a/windows/2005/02/01/hot_spot.html > > > ***Working with Roaming User Profiles > If you have a highly mobile local user base and are constantly fielding > concerns about personalized settings and desktop customizations that don't > seem to travel with your users, then roaming user profiles may make your > life a lot easier. In this article, Jonathan Hassell, author of "Learning > Windows Server 2003," explains how roaming user profiles can save you time > and energy. > http://www.windowsdevcenter.com/pub/a/windows/2005/02/01/rmng_usr.html > > --------------------- > Java > --------------------- > ***IRC Text to Speech with Java > Paul Mutton creates a multi-platform IRC bot that uses the FreeTTS Java > speech synthesizer library to convert IRC messages into audible speech. > Why would you want to use an IRC text-to-speech system? By reading out > messages as they arrive, you can keep working, diverting your attention to > IRC only when necessary. Paul is the author of "IRC Hacks." > http://www.onjava.com/pub/a/onjava/2004/09/08/IRCinJava.html > > > ***Internals of Java Class Loading > When are two classes not the same? When they're loaded by different class > loaders. This is just one of many curious side effects of Java's > class-loading system. Binildas Christudas shows how different class > loaders relate to one another and how (and why) to build your own custom > class loader. > http://www.onjava.com/pub/a/onjava/2005/01/26/classloading.html > > --------------------- > Digital Media > --------------------- > ***Build Your Own PVR (for Free) with HackTV > HackTV is a developer app for Mac OS X that you can download for free. It > enables you to watch TV (or any video source) on your Mac. Better yet, it > enables you to download that content to your hard drive. Erica Sadun shows > you the ins and outs of HackTV. > http://digitalmedia.oreilly.com/2005/01/26/hacktv.html > > > ***Featured Photographer--Ofer Halevi: The Art of Juxtaposition > Whether it's a man standing beside a mannequin in Amsterdam, or a poster > of Rabin staring up at a passerby in Israel, Ofer Halevi has an eye for > recording the juxtaposition of people and their inanimate environment. In > this portfolio you can experience Ofer's passion for detail, interaction, > and patterns. > http://digitalmedia.oreilly.com/2005/01/12/featured.html > > --------------------- > Web > --------------------- > ***Learning Lab: Save 40% on Web Programming Certificate Courses > This six-course series from the O'Reilly Learning Lab teaches you the > skills needed for web programming, web administration, and website > development. You'll learn HTML, JavaScript, XML, SQL, Perl, and Unix. Upon > completion of the series, students receive a Certificate of Professional > Development from the University of Illinois Office of Continuing > Education. Sign up by February 22nd, and save 40% on all Web Programming > Certificate courses. > http://www.oreilly.com/redirector.csp?link=UAWeb&type=news > > > ***A-Z Web Site Indexes Explained > A-Z Indexes are a far more accurate than search engines for searching the > content of a web site or intranet. For the value they can bring to a site, > A-Z indexes are worth the additional cost, but, if you decide to add an > index to your site, it's important to find the right person to do the > job. > http://www.sitepoint.com/article/a-z-indexes > > ================================================ > >From Your Peers > =============================================== > Don't forget to check out the O'Reilly UG wiki to see what user groups > across the globe are up to: > http://wiki.oreillynet.com/usergroups/index.cgi > > > Until next time-- > > Marsee From grant at mclean.net.nz Sun Feb 20 13:56:57 2005 From: grant at mclean.net.nz (Grant McLean) Date: Sun Feb 20 13:57:07 2005 Subject: [Wellington-pm] Reminder: Meeting tonight Message-ID: <1108936617.15702.9.camel@localhost> Hi Mongers Meeting tonight at 6:00pm http://wellington.pm.org/ Cheers Grant From sweetpea-perl at tentacle.net Sun Feb 20 19:46:12 2005 From: sweetpea-perl at tentacle.net (Kevin Dorne) Date: Sun Feb 20 19:46:20 2005 Subject: [Wellington-pm] The Perl Way: References & subroutines Message-ID: <20050221034612.GA56459@chaos.tentacle.net> Hi folks, A pretty simple question, I hope. I'm writing a subroutine that fetches some data externally and returns it as a hash. I'm just not sure the best way to do this in Perl. For example, my %nxt = fetch_next(); sub fetch_next { ... my %msg = ( 'a' => 'b', ); return %msg; } vs my $msg = fetch_next(); sub fetch_next { ... my $msg = { 'a' => 'b', }; return $msg; } vs my %msg; fetch_next(\%msg); sub fetch_next { my $msg = shift; ... } and so on. Suggestions? -- Peace, love & happiness to you from me =) -Sweetpea http://sweetpea.tentacle.net "Conformation needed ASAP... please reply!" - Spam From andy at catalyst.net.nz Sun Feb 20 19:58:12 2005 From: andy at catalyst.net.nz (Andrew Chilton) Date: Sun Feb 20 19:58:30 2005 Subject: [Wellington-pm] The Perl Way: References & subroutines In-Reply-To: <20050221034612.GA56459@chaos.tentacle.net> References: <20050221034612.GA56459@chaos.tentacle.net> Message-ID: <16921.23636.531350.338210@gargle.gargle.HOWL> Hi Kevin, Kevin Dorne writes: > I'm writing a subroutine that fetches some data externally and returns it as a hash. I'm just not sure the best way to do this in Perl. For example, > > my %nxt = fetch_next(); > sub fetch_next { > ... > my %msg = ( 'a' => 'b', ); > return %msg; > } This will return %msg in a (big?) long list back to the caller. It is 'flattened' on the way out of fetch_next() but then restored/assigned to the %nst hash. This takes a while since you'll have to copy the whole list. > vs > my $msg = fetch_next(); > sub fetch_next { > ... > my $msg = { 'a' => 'b', }; > return $msg; > } This creates the hash as it goes along and the only thing it passes back to $msg is the reference to the hash. This would be quicker than the above. > vs > my %msg; > fetch_next(\%msg); > sub fetch_next { > my $msg = shift; > ... > } I would suggest using (2) unless all of this code happens to be in a bigger loop. In which case (3) would save re-creating the hash everytime and (2) would be slightly slower. Depending on how big %msg/$msg is, I wouldn't be too worried. I'd say to go for (2) or (3) though. My preference would be (2) unless it was all in a loop itself. Andy From sweetpea-perl at tentacle.net Sun Feb 20 20:08:24 2005 From: sweetpea-perl at tentacle.net (Kevin Dorne) Date: Sun Feb 20 20:08:34 2005 Subject: [Wellington-pm] The Perl Way: References & subroutines In-Reply-To: <16921.23636.531350.338210@gargle.gargle.HOWL> References: <20050221034612.GA56459@chaos.tentacle.net> <16921.23636.531350.338210@gargle.gargle.HOWL> Message-ID: <20050221040824.GA56883@chaos.tentacle.net> Thanks, Andy. I'll probably end up passing in references (3) as I originally intended; just wanted to make sure this was something folks actually did in Perl and that I wasn't going to antagonise anyone's lunch with my code. (Well, that may happen anyway, but at least not for this reason...) Cheers, -k -- Peace, love & happiness to you from me =) -Sweetpea http://sweetpea.tentacle.net "Who's whoami? Oh! Who am I!" -TJ From srdjan at catalyst.net.nz Sun Feb 20 20:12:47 2005 From: srdjan at catalyst.net.nz (Srdjan) Date: Sun Feb 20 20:12:56 2005 Subject: [Wellington-pm] The Perl Way: References & subroutines In-Reply-To: <16921.23636.531350.338210@gargle.gargle.HOWL> References: <20050221034612.GA56459@chaos.tentacle.net> <16921.23636.531350.338210@gargle.gargle.HOWL> Message-ID: <42195FBF.7020502@catalyst.net.nz> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 | > vs | > my %msg; | > fetch_next(\%msg); | > sub fetch_next { | > my $msg = shift; | > ... | > } | | I would suggest using (2) unless all of this code happens to be in a bigger loop. In which case (3) would save re-creating the hash everytime and (2) would be slightly slower. I wold suggest using (2) *always*. It's by no means slower then (3), because you would have to clean the hash before assigning new values, or go through a hassle of making sure to always set values for specified keys. | | Depending on how big %msg/$msg is, I wouldn't be too worried. I'd say to go for (2) or (3) though. My preference would be (2) unless it was all in a loop itself. | | Andy | | _______________________________________________ | Wellington-pm mailing list | Wellington-pm@pm.org | http://mail.pm.org/mailman/listinfo/wellington-pm | | -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFCGV++ZtcHxCitRpgRAmEuAJ9+pUVj0KfYpXvxapC5rDKQ+5I7hwCeLv/Z ICH7RopRmPvvPn+xx5Qa3tA= =hcY9 -----END PGP SIGNATURE----- From jarich at perltraining.com.au Sun Feb 20 20:27:08 2005 From: jarich at perltraining.com.au (Jacinta Richardson) Date: Sun Feb 20 20:27:20 2005 Subject: [Wellington-pm] The Perl Way: References & subroutines In-Reply-To: <20050221034612.GA56459@chaos.tentacle.net> References: <20050221034612.GA56459@chaos.tentacle.net> Message-ID: <4219631C.80106@perltraining.com.au> Kevin Dorne wrote: > my %msg; > fetch_next(\%msg); > sub fetch_next { > my $msg = shift; > ... > } Be aware that this is action from a distance. If I don't expect fetch_next to change my hash then I might be rudely upset when it does. As a code maintainer, it's always nicer to see $msg = fetch_next(); than fetch_next(\%msg); because then I can easily see that the contents of $msg is the result of calling fetch_next. In the second case it's too easy to assume that fetch_next merely uses the contents of %msg without making changes. I suggest trying to code with the principal of least surprise. Which means going with your example (2). There should be no appreciable efficiency difference between the two. All the best, Jacinta -- ("`-''-/").___..--''"`-._ | Jacinta Richardson | `6_ 6 ) `-. ( ).`-.__.`) | Perl Training Australia | (_Y_.)' ._ ) `._ `. ``-..-' | +61 3 9354 6001 | _..`--'_..-_/ /--'_.' ,' | contact@perltraining.com.au | (il),-'' (li),' ((!.-' | www.perltraining.com.au | From douglas at paradise.net.nz Sun Feb 20 20:27:40 2005 From: douglas at paradise.net.nz (Douglas Bagnall) Date: Sun Feb 20 20:30:10 2005 Subject: [Wellington-pm] The Perl Way: References & subroutines In-Reply-To: <20050221034612.GA56459@chaos.tentacle.net> References: <20050221034612.GA56459@chaos.tentacle.net> Message-ID: <1108960060.4219633c74a4b@www.paradise.net.nz> Quoting Kevin Dorne : > I'm just not sure the best way > to do this in Perl. You're not supposed to. > my %nxt = fetch_next(); > sub fetch_next { > ... > my %msg = ( 'a' => 'b', ); > return %msg; > } Here, in fetch_next, you are constructing a hash and throwing it away again (which is generally ok). return %msg; returns a list representation of %msg, and the assignment to %nxt turns the list into another hash. You might as well use an array, or simply a list: return ( 'a' => 'b' ); the difference being that the list or array version retains the order of pairs, which could conceivably be useful, but might make fetch_next less readable. > my $msg = fetch_next(); > sub fetch_next { > ... > my $msg = { 'a' => 'b', }; > return $msg; > } This time you're only making one hash, which may save perl some work, especially if is large. Depending how you think, the extra indirection and unitary nature of the reference might please or confuse you. If you're used to python for instance, do this. On the other hand, you loose the easy readability of the earlier example: nobody knows that $msg is a hashref until they find and read fetch_next. consider also sub fetch_next { my %msg = ( 'a' => 'b', ); #etc return \%msg; } you can save characters by building a plain hash and only making the reference to return. > my %msg; > fetch_next(\%msg); > sub fetch_next { > my $msg = shift; > ... > } that way you can have values already in %msg, and have fetch_next update it. That can be useful, but if you're doing that though, it's not much more to make $msg an object, and go $msg->fetch_next(); which might make the effect on $msg seem less like a side effect, and make it harder for people to call fetch_next on the wrong things. So, it all depends. cheers Douglas Bagnall From grant at mclean.net.nz Mon Feb 21 14:42:40 2005 From: grant at mclean.net.nz (Grant McLean) Date: Mon Feb 21 14:42:53 2005 Subject: [Wellington-pm] Next meeting in three weeks Message-ID: <1109025760.20164.18.camel@localhost> Hi Mongers Thanks very much to Srdjan and Finlay, our two speakers last night. The slides are up in the archive section of the web site. And after the laptop battery debacle, I just know I'm going to be heckled with 'is it plugged in?' quips for the rest of my days. Quick reminder: the next meeting is only three weeks away (as this one was delayed a week). The March meeting is a lightning talk meeting and YOU NEED TO SIGN UP FOR IT. http://wellington.pm.org/lightning_talks.html We have got a number of speakers, but we need more. It will be fun, but only if you join in. Regards Grant From grant at mclean.net.nz Sun Feb 27 12:00:00 2005 From: grant at mclean.net.nz (Grant McLean) Date: Sun Feb 27 12:00:21 2005 Subject: [Wellington-pm] [Fwd: Newsletter from O'Reilly UG Program, February 18] Message-ID: <1109534400.18656.0.camel@localhost> -------- Forwarded Message -------- > From: Marsee Henon > To: perlmongers@catalyst.net.nz > Subject: Newsletter from O'Reilly UG Program, February 18 > Date: Fri, 18 Feb 2005 14:41:35 -0800 > ================================================================ > O'Reilly News for User Group Members > February 18, 2005 > ================================================================ > ---------------------------------------------------------------- > Book News > ---------------------------------------------------------------- > -Head First Java, 2nd Edition > -Linux Device Drivers, 3rd Edition > -Surviving PC Disasters, Mishaps, and Blunders > -Linux Network Administrator's Guide, 3rd Edition > -Windows XP in a Nutshell, 2nd Edition > ---------------------------------------------------------------- > Upcoming Events > ---------------------------------------------------------------- > -Adam Goldstein ("AppleScript: The Missing Manual"), Apple Store, > Short Hills, NJ--February 25th > -Jim Aspinwall ("PC Hacks"), Golden Gate Computer Society, > San Rafael, CA--February 28 > -O'Reilly at PhotoShop World, Las Vegas, NV--March 9 > -Gordon Meyer ("Smart Home Hacks"), North Coast Mac Users Group, > Rohnert Park, CA--March 15 > -Sarah Milstein ("Google: The Missing Manual"), Golden Gate Computer > Society, San Rafael, CA--March 28 > > ---------------------------------------------------------------- > Conference News > ---------------------------------------------------------------- > -Register for the 2005 O'Reilly Emerging Technology Conference, > San Diego, CA--March 14-17 > -Register for the 2005 MySQL Users Conference, > Santa Clara, CA--April 18-21 > ---------------------------------------------------------------- > News > ---------------------------------------------------------------- > -MAKE on Slashdot > -Getting Real-Time Data From the Web in Excel > -Stewart Butterfield on Flickr > -Jolt Awards Finalists > -500 O'Reilly Books on Safari > -Fear and Loathing in Information Security > -Object Oriented PHP Programming & Performance > -Michael Stutz on Computer Outlook/KLAV Radio > -Writing Apache's Logs to MySQL > -iPod shuffle Tips and Tricks > -Apache and AppleScript > -Encrypting Connection Strings in Web.config > -Building the Perfect Budget PC, Part 1 > -JDMK and Legacy IT Management > -Eclipse Plugins Exposed, Part 1: A First Glimpse > -High Definition in Focus at 2005 Sundance Festival > -Raymond Soemarsono: Natural Eye > -Introduction to Browser Specific CSS Hacks > -Web Programming Certificate Series Extended until February 28 > > ================================================ > Book News > ================================================ > Did you know you can request a free book to review for your > group? Ask your group leader for more information. > > For book review writing tips and suggestions, go to: > http://ug.oreilly.com/bookreviews.html > > Don't forget, you can receive 20% off any O'Reilly, No Starch, > Paraglyph, Pragmatic Bookshelf, SitePoint, or Syngress book you > purchase directly from O'Reilly. > Just use code DSUG when ordering online or by phone 800-998-9938. > http://www.oreilly.com/ > > ***Free ground shipping is available for online orders of at > least $29.95 that go to a single U.S. address. This offer > applies to U.S. delivery addresses in the 50 states and Puerto Rico. > For more details, go to: > http://www.oreilly.com/news/freeshipping_0703.html > > ---------------------------------------------------------------- > New Releases > ---------------------------------------------------------------- > ***Head First Java, 2nd Edition > Publisher: O'Reilly > ISBN: 0596009208 > "Head First Java, 2nd Edition" delivers a highly interactive, > multi-sensory learning experience that lets new programmers pick up the > fundamentals of the Java language quickly. Through mind-stretching > exercises, memorable analogies, humorous pictures, and casual language, > "Head First Java" encourages readers to think like Java programmers. This > revised second edition focuses on Java 5.0, the latest version of the Java > development platform. > http://www.oreilly.com/catalog/hfjava2/ > > Chapter 2, "A Trip to Objectville," and Chapter 8, "Serious > Polymorphism," > are available online: > http://www.oreilly.com/catalog/hfjava2/chapter/index.html > > > ***Linux Device Drivers, 3rd Edition > Publisher: O'Reilly > ISBN: 0596005903 > Over the years, this best-selling guide has helped countless programmers > learn how to support computer peripherals and how to develop new hardware > under the Linux operating system. Now, with this third edition, it's even > more helpful, covering all the significant changes to Version 2.6 of the > Linux kernel. The guide even includes full-featured examples that > programmers can compile and run without special hardware. > http://www.oreilly.com/catalog/linuxdrive3/ > > Chapter 13, "USB Drivers," is available online: > http://www.oreilly.com/catalog/linuxdrive3/chapter/index.html > > > ***Surviving PC Disasters, Mishaps, and Blunders > Publisher: Paraglyph Press > ISBN: 1932111980 > "Surviving PC Disasters, Mishaps, and Blunders" is the must-have survival > guide for every PC user. Written in an engaging, reassuring, and fun > style, it gives you the answers you need immediately to fix the thorniest > PC problems. It also provides valuable insight on measures that can > prevent a difficult and often expensive cure. (Who's got money to waste > these days on fixing mishaps and blunders anyway?) > http://www.oreilly.com/catalog/1932111980/index.html > > > ***Linux Network Administrator's Guide, 3rd Edition > Publisher: O'Reilly > ISBN: 0596005482 > This refreshed resource takes an in-depth look at everything you need to > know to join a network. Topics covered include all of the essential > networking software that comes with the Linux operating system, plus > information on a host of cutting-edge services including wireless hubs, > spam filtering, IPv6, OpenLDAP, and more. > http://www.oreilly.com/catalog/linag3/ > > Chapter 18, "Wireless Networking," is available online: > http://www.oreilly.com/catalog/linag3/chapter/index.html > > > ***Windows XP in a Nutshell, 2nd Edition > Publisher: O'Reilly > ISBN: 0596009003 > "Windows XP in a Nutshell, 2nd Edition" documents everything there is to > know about the world's most widely used operating system. Updated to > include information on the security technologies featured in Service Pack > 2 (SP2), this must-have desktop reference is dedicated to making your > time at the computer safer, easier, and more fun. It's the ultimate > resource for IT professionals and Windows XP power users everywhere. > http://www.oreilly.com/catalog/winxpnut2/ > > Chapter 8, "The Registry," is available online: > http://www.oreilly.com/catalog/winxpnut2/chapter/index.html > > ================================================ > Upcoming Events > ================================================ > ***For more events, please see: > http://events.oreilly.com/ > > > ***Adam Goldstein ("AppleScript: The Missing Manual"), Apple Store, > Short Hills, NJ--February 25th > Adam will be giving and talk and signing books. Adam was a technical > editor for O'Reilly's "Mac OS X: The Missing Manual." When he's not > writing books or code, Adam attends high school in New Jersey, where he > is captain of the Debate and Quizbowl teams and an editor of the school > paper. > > Read a recent review of Adam's book on Slashdot: > http://books.slashdot.org/books/05/02/06/222219.shtml?tid=156&tid=6&tid=3 > > Apple Store Short Hills at 7pm February 25th > 1200 Morris Turnpike > Short Hills, NJ 07078 > (973) 467-4890 > http://www.apple.com/retail/shorthills/week/20050213.html > > > ***Jim Aspinwall ("PC Hacks"), Golden Gate Computer Society, > San Rafael, CA--February 28 > Jim will be giving a talk on "Computer Security, PC Hacks, and > Troubleshooting Tips." > The meeting starts at 7:15 pm at the Embassy Suites Hotel,101 McInnis > Parkway, San Rafael. > http://www.ggcs.org/thismonth.html > > > ***O'Reilly at PhotoShop World, Las Vegas, NV--March 9 > Come by and say hi and check out our latest Digital Media books at our > booth (#220). > Mandalay Bay Resort, Las Vegas, NV. > http://www.photoshopworld.com/ > > > ***Gordon Meyer ("Smart Home Hacks"), North Coast Mac Users Group, > Rohnert Park, CA--March 15 > Gordon will be presenting automation tips and hacks from his book. The > meeting starts at 7pm at the Rohnert Park Senior Center, 6800 Hunter > Drive--Suite A, Rohnert Park. > http://www.ncmug.org/ > > > ***Sarah Milstein ("Google: The Missing Manual"), Golden Gate Computer > Society, San Rafael, CA--March 28 > An O'Reilly editor and author, Sarah will start with the Google basics > and quickly move on to the sophisticated ways to search, covering > search syntax, techniques, and hidden tricks to hone in on relevant > content. The meeting starts at 7:15 pm at the Embassy Suites Hotel, > 101 McInnis Parkway, San Rafael. > http://www.ggcs.org/gen-next.html > > ================================================ > Conference News > ================================================ > ***2005 O'Reilly Emerging Technology Conference, > San Diego, CA--March 14-17 > This year's conference theme is "Remix," which infuses ETech's > roll-up-your-sleeves tutorials, to-the-point plenary presentations, and > real world focused breakout sessions. Come to ETech and discover how > applications and hardware are being deconstructed and recombined in > unexpected ways. Learn how users and customers are influencing new > interfaces, devices, business models, and services. For all the scoop on > tutorials, featured speakers, and conference events, check out: > http://conferences.oreillynet.com/etech/ > > User group members use code DSUG when you register, and receive 20% off > the registration price. > > To register for the conference, go to: > http://conferences.oreillynet.com/cs/et2005/create/ord_et05 > > > ***Register for the 2005 MySQL Users Conference, Santa Clara, CA-- > April 18-21 > The MySQL Users Conference, co-presented by O'Reilly Media and MySQL AB, > brings together experts, users, and industry leaders with unique MySQL > insights, offering attendees a detailed look into new features in MySQL > 5.0, sessions and workshops designed to teach best practices, and > exposure to new open source technologies. > For more information, go to: > http://www.mysqluc.com/ > > User Group members who register before Febuary 28, 2005 get a double > discount. Use code DSUG when you register, and receive 20% off the > early registration price. > > To register for the conference, go to: > http://conferences.oreillynet.com/cs/mysqluc2005/create/ord_mysql05 > > ================================================ > News From O'Reilly & Beyond > ================================================ > --------------------- > General News > --------------------- > ***User Groups Benefit from Safari > When O???Reilly developers needed someone to user-test the new Safari > Affiliate Program, Stephen Henry from the North Coast Mac Users Group was > the ideal choice. Situated 40 miles north of San Francisco, NCMUG has > been active since the Mac first arrived in 1984. Henry created an excellent > working example of how user groups can implement the Affiliate Program to > benefit their members. Ed Stephenson brings you the details. > http://oreilly.com/news/ncmug.html > > > ****MAKE on Slashdot > http://books.slashdot.org/books/05/02/17/1958221.shtml?tid=222&tid=159&tid=126&tid=6 > > The MAKE blog is available at: > http://www.makezine.com/blog/ > > MAKE Subscriptions Available > The annual subscription price for four issues is $34.95. When you > subscribe with this link, you'll get a free issue--the first one plus > four more for $34.95. So subscribe for yourself or friends with this > great offer for charter subscribers: five volumes for the cost of four. > Subscribe at: > https://www.pubservice.com/MK/Subnew.aspx?PC=MK&PK=M5ZUGLA > > > ***Getting Real-Time Data From the Web in Excel > Did you know that you can use Excel for more than just storing and > organizing static data? In this article, Matthew MacDonald, author of > "Excel: The Missing Manual," shows you how to use Excel as a tool to > handle up-to-the-minute information like sales figures and currency > exchange rates. > http://www.windowsdevcenter.com/pub/a/windows/2005/02/08/xcel_mm.html > > > ***Stewart Butterfield on Flickr > Not even a year old and still in beta, Flickr is a revolutionary photo > storage, sharing, and organization application boasting roughly 270,000 > members. Richard Koman catches Flickr CEO Stewart Butterfield for a few > words on what has made Flickr so revolutionary and where it may be > headed. > > http://www.oreillynet.com/pub/a/network/2005/02/04/sb_flckr.html > > > ***Jolt Awards Finalists > "Software Development Magazine" recently announced the finalists for the > 15th Annual Jolt Product Excellence Awards. Several O'Reilly titles and > sites were nominated: "Head First Design Patterns" in the General Books > category; and "Better, Faster, Lighter Java," "Head First Servlets & > JSP," "Hibernate: A Developer's Notebook," and "Mono: A > Developer's Notebook" in the Technical Books category. Java.net > and the O'Reilly Network were named finalists in the Web > Sites and Developer Networks category. > http://www.sdmagazine.com/jolts/15th_jolt_finalists.html > > > ***500 O'Reilly Books on Safari > O'Reilly now boasts over 500 books on Safari, the premier electronic > reference library for IT professionals and programmers. With Safari, you > can search electronic versions of a broad range of the best technical > books from leading publishers including O'Reilly. Check out our newest > title, "All About Your iPod Photo," and learn how to get the most out of > your favorite toy. Give Safari a try today with a free trial > subscription. > http://www.oreilly.com/go/safari-ug > > --------------------- > Open Source > --------------------- > ***Fear and Loathing in Information Security > "Society has always treated innovators and whistle blowers with > ambivalence," writes author Michael D. Bauer in reference to hackers. In > this article, Michael discusses why information security professionals > demonize hackers and why that tendency is both irrational and > counterproductive. Michael is the author of "Linux Server Security, 2nd > Edition." > http://www.oreillynet.com/pub/a/network/2005/02/11/mbauer_1.html > > > ***Object Oriented PHP Programming & Performance > Harry explores the trade-offs between object oriented and procedural > programming in PHP in a lengthy discussion on the pros and cons of each. > http://www.sitepoint.com/blog-post-view.php?id=223760 > > > ***Michael Stutz on Computer Outlook/KLAV Radio > Listen to the author of No Starch's "The Linux Cookbook, 2nd Edition." > http://computeroutlook.com/audiostudio.html > > > ***Writing Apache's Logs to MySQL > Adding a few performance statistics to your Apache httpd logs can help > you profile your applications. Digging through flat files for information is > a drag, though. Logging to a relational database can make reporting and > analysis much more convenient. Chris Josephes demonstrates how to install > and configure mod_log_mysql and shows off what you can do with it. > http://www.onlamp.com/pub/a/apache/2005/02/10/database_logs.html > > --------------------- > Mac > --------------------- > ***iPod shuffle Tips and Tricks > The iPod shuffle is the easiest-to-use iPod to date. But that doesn't > mean you can't customize how you listen and upload music. Scott > Knaster shows you some very handy tips and tricks for the shuffle > and iTunes 4.7.1. > http://www.macdevcenter.com/pub/a/mac/2005/02/15/shuffle.html > > > ***Apache and AppleScript > AppleScript traditionally interacts with Mac applications and Apache is > the web server that powers most of the Internet. David Miller shows you > how AppleScript can invoke Unix utilities through its do shell script > command, thereby creating some interesting intersections with Apache. > http://www.macdevcenter.com/pub/a/mac/2005/02/11/applescript.html > > --------------------- > Windows/.NET > --------------------- > ***Encrypting Connection Strings in Web.config > One of the best practices in ASP.NET is to save your database connection > strings in the Web.config file instead of hard-coding it in your code. > It's not such a good idea to save your connection strings as plain text > in Web.config--you should ideally encrypt the connection strings so it > leaves no chance for a potential hacker to easily get more information > about your database server. In ASP.NET 2.0, Microsoft has taken this further > by allowing you to encrypt the connection strings in Web.config, all without > much plumbing on your part. In this new article by Wei-Meng Lee, he shows > you how it works. > http://www.ondotnet.com/pub/a/dotnet/2005/02/15/encryptingconnstring.html > > > ***Building the Perfect Budget PC, Part 1 > You can build a powerhouse system without breaking the bank. In this > first part of a two-part article, Robert Bruce Thompson and Barbara Fritchman > Thompson, authors of "Building the Perfect PC," show you which components > to buy. > http://www.windowsdevcenter.com/pub/a/windows/2005/02/15/Perfect_BudgetPC.html > > --------------------- > Java > --------------------- > ***JDMK and Legacy IT Management > Keeping a network with legacy (and possibly unreliable) devices is nearly > impossible without some automated help. Stephen Morris shows how to use > the Java Dynamic Management Kit to keep tabs on your network and find > potential points of failure. > http://www.onjava.com/pub/a/onjava/2005/02/16/jdmk.html > > > ***Eclipse Plugins Exposed, Part 1: A First Glimpse > Many developers use Eclipse out of the box as an IDE, never investigating > its powerful extensibility. But as Emmanuel Proulx shows in this first > installment of a new series, Eclipse's modular system of plugins allow > you to customize it to your suit your development needs. > http://www.onjava.com/pub/a/onjava/2005/02/09/eclipse.html > > --------------------- > Digital Media > --------------------- > ***High Definition in Focus at 2005 Sundance Festival > Cheaper than film, bigger and better than plain, old digital video, > high-definition digital video definitely came into its own during this > year's Sundance Film Festival. According to Sony, nearly half of the > features, documentaries, and shorts screened in Park City were shot in > HD. > Susan Boyer reports. > http://digitalmedia.oreilly.com/2005/02/09/hd.html > > > ***Raymond Soemarsono: Natural Eye > Some people are meant to be artists. Self-taught photographer Raymond > Soemarsono has a natural eye for composing stunning landscape scenes, > then taming his digital camera to record them according to his vision. His > gallery features many places with which you're probably familiar. Maybe > it's time to get in the car and revisit them? > http://digitalmedia.oreilly.com/2005/02/16/featured.html > > --------------------- > Web > --------------------- > ***Introduction to Browser Specific CSS Hacks > CSS leaves your layout open to interpretation by browsers...or does it? > In this hands-on trouble-shooter, Trenton explains why and how different > browser-specific CSS hacks work--and provides code to help you regain > control over your layouts. > http://www.sitepoint.com/article/browser-specific-css-hacks > > > ***Web Programming Certificate Series Extended until February 28 > This six-course series from the O'Reilly Learning Lab teaches you the > skills needed for web programming, web administration, and web site > development. You'll learn HTML, JavaScript, XML, SQL, Perl, and Unix. > Upon completion of the series, students receive a Certificate of Professional > Development from the University of Illinois Office of Continuing Education. > Sign up today and save 40% on all Web Programming Certificate courses. > Offer extended until February 28. > http://www.oreilly.com/redirector.csp?link=UAWeb&type=news > > ================================================ > >From Your Peers > =============================================== > Don't forget to check out the O'Reilly UG wiki to see what user groups > across the globe are up to: > http://wiki.oreillynet.com/usergroups/index.cgi > > Until next time-- > > Marsee From finlay at catalyst.net.nz Mon Feb 28 19:07:14 2005 From: finlay at catalyst.net.nz (Finlay Thompson) Date: Mon Feb 28 19:07:23 2005 Subject: [Wellington-pm] Sum in one line Message-ID: <4223DC62.9080005@catalyst.net.nz> Hi Everyone I frequently want the sum of an array of numbers, and cant believe that perl has no "sum" function. Probably its coming in perl 6. Anyway, does anyone know of a good oneliner ? The best I can do is: my $total = sub {my $s = 0; $s += $_ for @_; $s }->(@numbers); Finlay From jarich at perltraining.com.au Mon Feb 28 19:13:07 2005 From: jarich at perltraining.com.au (Jacinta Richardson) Date: Mon Feb 28 19:13:19 2005 Subject: [Wellington-pm] Sum in one line In-Reply-To: <4223DC62.9080005@catalyst.net.nz> References: <4223DC62.9080005@catalyst.net.nz> Message-ID: <4223DDC3.3020609@perltraining.com.au> Finlay Thompson wrote: > Anyway, does anyone know of a good oneliner ? The best I can do is: > > my $total = sub {my $s = 0; $s += $_ for @_; $s }->(@numbers); $total += $_ for @numbers; of course if you're defining $total as well, it's a little harder. Perhaps: my $total; $total += $_ for @numbers; strictly speaking it's two lines, but it's shorter than your suggestion. ;) Good question! All the best, Jacinta -- ("`-''-/").___..--''"`-._ | Jacinta Richardson | `6_ 6 ) `-. ( ).`-.__.`) | Perl Training Australia | (_Y_.)' ._ ) `._ `. ``-..-' | +61 3 9354 6001 | _..`--'_..-_/ /--'_.' ,' | contact@perltraining.com.au | (il),-'' (li),' ((!.-' | www.perltraining.com.au | From finlay at catalyst.net.nz Mon Feb 28 19:15:24 2005 From: finlay at catalyst.net.nz (Finlay Thompson) Date: Mon Feb 28 19:15:31 2005 Subject: [Wellington-pm] Sum in one line In-Reply-To: <4223DDC3.3020609@perltraining.com.au> References: <4223DC62.9080005@catalyst.net.nz> <4223DDC3.3020609@perltraining.com.au> Message-ID: <4223DE4C.5070702@catalyst.net.nz> thanks , thats much better! Jacinta Richardson wrote: > > Finlay Thompson wrote: > >> Anyway, does anyone know of a good oneliner ? The best I can do is: >> >> my $total = sub {my $s = 0; $s += $_ for @_; $s }->(@numbers); > > > $total += $_ for @numbers; > > of course if you're defining $total as well, it's a little harder. > Perhaps: > > my $total; $total += $_ for @numbers; > > strictly speaking it's two lines, but it's shorter than your > suggestion. ;) > > Good question! > > All the best, > > > Jacinta > From michael at diaspora.gen.nz Mon Feb 28 19:18:34 2005 From: michael at diaspora.gen.nz (michael@diaspora.gen.nz) Date: Mon Feb 28 19:18:47 2005 Subject: [Wellington-pm] Sum in one line In-Reply-To: Your message of "Tue, 01 Mar 2005 16:07:14 +1300." <4223DC62.9080005@catalyst.net.nz> Message-ID: Finlay Thompson writes: >Anyway, does anyone know of a good oneliner ? The best I can do is: > > my $total = sub {my $s = 0; $s += $_ for @_; $s }->(@numbers); I'd try: # remove the init my $total = sub {my $s; $s += $_ for @_; $s }->(@numbers); # remove the sub! my $total; $total += $_ for @numbers; And lastly, for total inefficency, but functional programming like foo: my $total = scalar map { (1) x $_ } @numbers; From andrew.ruthven at catalyst.net.nz Mon Feb 28 19:25:23 2005 From: andrew.ruthven at catalyst.net.nz (Andrew Ruthven) Date: Mon Feb 28 19:25:32 2005 Subject: [Wellington-pm] Sum in one line In-Reply-To: <4223DDC3.3020609@perltraining.com.au> References: <4223DC62.9080005@catalyst.net.nz> <4223DDC3.3020609@perltraining.com.au> Message-ID: <1109647523.2935.42.camel@dirk.catalyst.net.nz> [Now that this email address is subscribed to the list I'll try again...] Or if you like to use map we have: my $total; map $total += $_, @numbers; (Which is one character longer than Jacinta's. Damn.) On Tue, 2005-03-01 at 14:13 +1100, Jacinta Richardson wrote: > Finlay Thompson wrote: > > > Anyway, does anyone know of a good oneliner ? The best I can do is: > > > > my $total = sub {my $s = 0; $s += $_ for @_; $s }->(@numbers); > > $total += $_ for @numbers; > > of course if you're defining $total as well, it's a little harder. Perhaps: > > my $total; $total += $_ for @numbers; > > strictly speaking it's two lines, but it's shorter than your suggestion. ;) > > Good question! > > All the best, > > > Jacinta > -- Andrew Ruthven, Wellington, New Zealand Catalyst IT Limited --> http://www.catalyst.net.nz At work: andrew.ruthven@catalyst.net.nz At home: andrew@etc.gen.nz GPG fpr: 34CA 12A3 C6F8 B156 72C2 D0D7 D286 CE0C 0C62 B791 From douglas at paradise.net.nz Mon Feb 28 19:27:52 2005 From: douglas at paradise.net.nz (Douglas Bagnall) Date: Mon Feb 28 19:27:59 2005 Subject: [Wellington-pm] Sum in one line In-Reply-To: <4223DC62.9080005@catalyst.net.nz> References: <4223DC62.9080005@catalyst.net.nz> Message-ID: <4223E138.60708@paradise.net.nz> > Anyway, does anyone know of a good oneliner ? not "good", but my $total = eval(join(' + ',@numbers)); douglas From finlay at catalyst.net.nz Mon Feb 28 19:33:36 2005 From: finlay at catalyst.net.nz (Finlay Thompson) Date: Mon Feb 28 19:33:44 2005 Subject: [Wellington-pm] Sum in one line In-Reply-To: <4223DE4C.5070702@catalyst.net.nz> References: <4223DC62.9080005@catalyst.net.nz> <4223DDC3.3020609@perltraining.com.au> <4223DE4C.5070702@catalyst.net.nz> Message-ID: <4223E290.6040501@catalyst.net.nz> However, to do it anonymously ? for example as the argument to another routine : my $total; map $total += @numbers; my $pretty_sum = format_number($total); still seems a bit long .... I wish there was a routine, so you could do it without having to declare another variable. my $pretty_sum = format_number(sum @numbers); There is such a thing in the module: use List::Util qw(sum); Finlay Finlay Thompson wrote: > thanks , thats much better! > > > > Jacinta Richardson wrote: > >> >> Finlay Thompson wrote: >> >>> Anyway, does anyone know of a good oneliner ? The best I can do is: >>> >>> my $total = y; >> >> >> >> $total += $_ for @numbers; >> >> of course if you're defining $total as well, it's a little harder. >> Perhaps: >> >> my $total; $total += $_ for @numbers; >> >> strictly speaking it's two lines, but it's shorter than your >> suggestion. ;) >> >> Good question! >> >> All the best, >> >> >> Jacinta >> > > _______________________________________________ > Wellington-pm mailing list > Wellington-pm@pm.org > http://mail.pm.org/mailman/listinfo/wellington-pm >