You don't mention why you wanted to re-invent the wheel here. What purpose was there for this? Plus it doesn't look like it would even pass as a drop in replacement for the include method within the CGI::SSI module.
I also wondered why you went to the trouble of using read only to create an array with the following line:
my @data_arr = $data;
Sorry but that doesn't look right (to my early morning eyes anyway :P ) surely it would have been better to:
my @data_arr = <DATA>;
In this instance?
On a different note, you include the the flock call via Fcntl but then you have the flock call commented out. I think you need to clean that up a little bit.
SP | [reply] [Watch: Dir/Any] [d/l] [select] |
Good points, simon.proctor. I guess I used my @data_arr = $data; because I had used it in writing a guestbook and it had worked pretty well. I commented out the flock call because it isn't supported on my winblows box, and I suppose I forgot to un-comment it. As far as my desire to re-invent the wheel, I wanted to provide a quick access function snippet for people not using CGI::SSI, for people like me who haven't had a chance to install it.
Well, that's my "defense". I'm sure it doesn't hold a candle to CGI::SSI's version, but it was quick, and that's what I wanted. Thanks for the pointers, I'll fix it next version.
Hi, my name is Dhoss, I like to play Quake 3 arena, I drink Vanilla Coke, and I like long walks on the beach while the sun goes down.
| [reply] [Watch: Dir/Any] [d/l] [select] |
I use this kind of code in a sort of an html-template way:
I first edit my html file with wysiwyg FrontPage.
Then add some comments with some special character, to later replace with a dessired chunk of values processed by Perl.
Then, at the script, I load the html file in a scalar and s/usbstitute the established comments with the fresh chunk of data processed with the script.
I don't need any module to do all these!
(Note: I am first trying to manage without the use of modules so as to learn the basics and common scripting habbits. Later, when needing to speed up code creation, I am going to study some basic code implementation:)
| [reply] [Watch: Dir/Any] |
sub file2scalar {
my $filename = shift;
return "Error: $filename doesn't exist" unless -f $filename;
open FH, $filename || return "Error: can't read $filename";
return do{local $/; <FH>};
}
When you call this sub:
my $include = file2scalar('foo.html');
$include will either contain the contents of the
file or an error message. Instead of differentiating between
the two, i recommend just printing $include to the
browers, much like PHP does when you give it's
include() function a file that doesn't exist or
can't be read. (of course, my real recommendation is
to just go ahead and install CGI::SSI instead)
jeffa
L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)
| [reply] [Watch: Dir/Any] [d/l] [select] |