tag:blogger.com,1999:blog-6655636091625157671.post419231139348360203..comments2017-01-08T14:49:10.999-05:00Comments on robkinyon on Perl: What makes code Perlish?Rob Kinyonhttp://www.blogger.com/profile/07966252008096453177noreply@blogger.comBlogger4125tag:blogger.com,1999:blog-6655636091625157671.post-15522541866174178172009-07-29T18:48:54.406-04:002009-07-29T18:48:54.406-04:00Well, if all you are concerned with is the extra v...Well, if all you are concerned with is the extra variable you can say<br /><br />a ^= b;<br />b ^= a;<br />a ^= b;<br /><br />Humorously, this even works on strings in Perl:<br /><br />#!/usr/bin/perl<br /><br />use strict;<br />use warnings;<br /><br />my $x = "foo";<br />my $y = "quux";<br /><br />$x ^= $y;<br />$y ^= $x;<br />$x ^= $y;<br /><br />print "x $x y $y\n";Chas. Owenshttps://www.blogger.com/profile/11716389363199045015noreply@blogger.comtag:blogger.com,1999:blog-6655636091625157671.post-72215342517933337272009-07-29T07:11:00.896-04:002009-07-29T07:11:00.896-04:00This might not be the best example for concision b...This might not be the best example for concision because it's the lack of a temp that's the real win. That is, the Perlish code isn't better just because it's shorter; it's <em>really</em> better because it doesn't create another variable. We didn't just save 200 lines, we saved 100 temporary variables. Or worse, the same variable scoped globally (or, at least, wider than necessary) reused 99 more times.oylenshpeegulhttps://www.blogger.com/profile/08957521303556290217noreply@blogger.comtag:blogger.com,1999:blog-6655636091625157671.post-2421301056460191492009-07-29T01:11:50.056-04:002009-07-29T01:11:50.056-04:00AdamKennedy, have you considered sorting algorithm...AdamKennedy, have you considered sorting algorithms?Naveedhttps://www.blogger.com/profile/17432756577312704826noreply@blogger.comtag:blogger.com,1999:blog-6655636091625157671.post-21765552279710368062009-07-29T00:19:00.407-04:002009-07-29T00:19:00.407-04:00I find this a spurious example, because I'm no...I find this a spurious example, because I'm not aware of any real situations (in well written code) in which you'd want to swap variables :)Unknownhttps://www.blogger.com/profile/16880485256236829010noreply@blogger.com