in reply to Re: Practical example of "Is Perl code maintainable"
in thread Practical example of "Is Perl code maintainable"

There is "readable" and then there is "rambling and confusing"


At the cost of using a module, I'd go a bit further if readability were really the goal.

use File::stat qw(stat); sub file_mode { my ($path) = @_; -f $path or return -1; my $stat = stat($path) or return -1; return $stat->mode; }

That's assuming I didn't have permission to replace whatever was calling file_mode with File::stat in the first place. Something is calling file_mode, storing the result, checking for -1, etc., etc. That part is probably just as crufty.

Update: ysth pointed out that I omitted '-f', so I re-wrote the code to be more explicit.


Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.