Your skill will accomplish what the force of many cannot |
|
PerlMonks |
Re: read/write subroutineby grinder (Bishop) |
on Jun 29, 2001 at 11:56 UTC ( [id://92549]=note: print w/replies, xml ) | Need Help?? |
epoptai, I'm starting to become familiar with your code! Have pored over xNN and reputer, I have a number of comments to make. The thing that has caused me the most grief working with you code is your die calls. Saying...
... is next to useless, you may was well omit the die, because the client has no idea what why things went amiss. Please, please, please, in future, use...
You owe it to yourself and your users to come up with more explicit error messages. When I had these cryptic messages appearing, the first thing I had to do was to edit the die call and then rerun the code to understand what was happening. Another issue I have with this is the use of mode parameters. One has to pass the routine a string containing 'read' or 'write'. Get that wrong that the routine mysteriously does nothing at all. What's more, there is absolutely no shared code between the read mode and the write mode, so I would say that you need two subroutines. In a similar vein, there is a second mode parameter that has to be 'array' or 'slurp'. I don't see the need for this. I see you expect arrays to be passed by reference, in which case that can be deduced by the ref operator. I would tend to just pass by value. You also seem to go through all sorts of contorsions to return a scalar or an array, when wantarray will do it for you. I hereby present the code that I used in my own hacked up copy of reputer. Note that I don't bother to check the return values from close. This is according to the belief that one can only check for the errors that you can do something about. I've never found a useful course of corrective action that a program can take if a close blows up. (Note that this is after many, many years in C and C++ of checking close return values and never having seen one fail). YMMV.
I want to apologise in advance if this comes out sounding harsh. I find your PM applications simply amazing, but I find the code is exceptionally idiosyncratic and hard to comprehend. And I know I'm not alone. Someone asked about using cookies in the CB a few weeks ago and wanting to see some example code, so I told the person to take a look at reputer and the reply came back lightening fast "I can't read epoptai's code." -- g r i n d e r
In Section
Cool Uses for Perl
|
|