On Sat, Nov 26, 2011 at 04:19:58PM +0100, JPH wrote: > Also I wasn't aware of the || construction to use for setting > default values when ARGV (in this case) is undefined.
Modern Perls have a new operator, defined-or, which is //. This is similar to || except that it tests the left operand's defined-ness instead of its truthiness. It's technically more correct to use if you only want to make sure @ARGV has /some/ value in the appropriate slot (truthful or not). It's not available in older Perls though. Apparently defined-or was introduced in 5.10 (almost 4 years ago, in December 2007, according to Wikipedia). That said, there are still some distros that have older Perls. >_> This VPS is now running 5.10.1, but I think 5.10.x is relatively new to Debian stable. So keep that in mind if you need to support older Perls. See 'perldoc perlop' for details about operators in Perl. Personally, I found that there were a number of core perldocs that are essential to read when you begin learning Perl. They're also quite interesting so it's fun to do. See 'perldoc perl' for a list of documents that should pique your interest. The ones that I can list off the top of my head are perlsyn[1], perldata, perlvar, perlsub, perlfunc, perlop, perlre, and perlref (this is definitely NOT a complete list). I just skimmed perlop again and it doesn't seem to explicitly say that && and || and other related operators return the last evaluated operand instead of a boolean (the latter being what C and many other "static" languages do). I guess it's just something that you need to know from experience (many other languages with similar features to Perl also work this way). Regards, -- Brandon McCaig <bamcc...@gmail.com> <bamcc...@castopulence.org> Castopulence Software <https://www.castopulence.org/> Blog <http://www.bamccaig.com/> perl -E '$_=q{V zrna gur orfg jvgu jung V fnl. }. q{Vg qbrfa'\''g nyjnlf fbhaq gung jnl.}; tr/A-Ma-mN-Zn-z/N-Zn-zA-Ma-m/;say' [1] OK, I cheated and looked that one up.
signature.asc
Description: Digital signature