in reply to Code for readablity or fewer lines?

I advocate brevity and conciseness in my code, as well as using idioms and any little efficiency-fiend out there. (This is not to say my code is not readable or maintainable -- I just choose to code in a form that is understandable and brief.) As such, I use tr/// for character deletions instead of some s///g. I use tricks where they save time and effort. For my job, we keep information in a form of XML in files. When I need to go through the file and change a section, I don't use regexes. I use $/:
sub updateRecord { my ($srml_file,$n,$new) = @_; my ($offset, $data, $post); local $/; # no concurrent access, so no locking open CACHE, "+< $srml_file" or return setError($!); $/ = "<!-- START RECORD $n -->\n"; <CACHE>; # get up to the good stuff $offset = tell CACHE; $/ = "<!-- END RECORD $n -->\n"; <CACHE>; # waste what's there undef $/; $post = <CACHE>; # get what's left seek CACHE, $offset, 0; truncate CACHE, $offset; # in case new data is shorter print CACHE "<!-- START RECORD $n -->\n", getSRML($new), "<!-- END RECORD $n -->\n", $post; close CACHE; return -s $srml_file; }
Before I introduced this trick, they'd been reading through the file line-by-line, and using regexes (without using qr// objects) which got a bit expensive. So this was a speed boost, and the brief comments are all that was needed to explain the process.

The measure of efficiency comes not from the number of lines used, but from the algorithms used. Redundancy can occur in small programs as well as large ones.

japhy -- Perl and Regex Hacker