Matt, sorry for not mentioning it before, but welcome to TWF, and thanks for your contributions so far!
Just a simple thing with your code, if he was planning on printing any output to the browser, he will need:
print "Content-type:text/html\n\n";
.
Here is my simple solution
#!/usr/bin/perl -w my $file = 'filename.html'; print "Content-type:text/html\n\n"; open(IN,$file) or die "Cannot open $file: $!"; print while <IN>; close(IN);
'
Just curious, is there a reason to flock the file when reading content? I always thought that flock was only required when writing to a file?
Quote: Just curious, is there a reason to flock the file when reading content? I always thought that flock was only required when writing to a file?
I always lock to read and write out of habit. A file lock is conditional, so if it's locked to write (flock FH, 2 or better flock FH, LOCK_EX) and a non-locked request to read is made, the write lock is dropped and the data *can* be flushed before it's printed back.
I learnt that the hard way.
my $friends = qq[=:Jilly , Andrew , Peter & Harry:=];
print &welcome($friends), "2"; my @home;
sub welcome{my $s=shift; $s=~s{^(=\(.+?)(\:=)$}
{$_=$2;@home=split/[&,]/;}esgx;$friends= join'me',@home;
$friends=~s{(\A|\S|\s+)([A-Z]).+?(\s|\Z)}{$2}sge;my$c=-1;
$friends=~s{(me|\Z)}{++$c;@_=(qw|ust nother erl acker|);qq!$_[$c] !;}eg; $friends}
Matt@Ikonboard posted this at 11:42 — 16th January 2001.
Oh, and a good habit to get into is to be explicit about the file read/write request.
Use either '<$file' to read, '>$file' to write and '>>$file' to append. Using '$file' on it's own can lead to exploitation of the file while the data is being processed.
I got my ass burned at comp.lang.perl.misc for just using open FH, $File;
my $friends = qq[=:Jilly , Andrew , Peter & Harry:=];
print &welcome($friends), "2"; my @home;
sub welcome{my $s=shift; $s=~s{^(=\(.+?)(\:=)$}
{$_=$2;@home=split/[&,]/;}esgx;$friends= join'me',@home;
$friends=~s{(\A|\S|\s+)([A-Z]).+?(\s|\Z)}{$2}sge;my$c=-1;
$friends=~s{(me|\Z)}{++$c;@_=(qw|ust nother erl acker|);qq!$_[$c] !;}eg; $friends}
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.
Matt@Ikonboard posted this at 03:01 — 16th January 2001.
They have: 16 posts
Joined: Jan 2001
How long is a piece of string?
Can you refine the question somewhat? If you want to take a HTML page, and include it for output in your script, then something like:
open FH, '</path/to/file.html' or die $!;
flock FH, 1 or die $!;
while (<FH>) { print $_ }
close FH;
Would do it.
my $friends = qq[=:Jilly , Andrew , Peter & Harry:=];
print &welcome($friends), "2"; my @home;
sub welcome{my $s=shift; $s=~s{^(=\(.+?)(\:=)$}
{$_=$2;@home=split/[&,]/;}esgx;$friends= join'me',@home;
$friends=~s{(\A|\S|\s+)([A-Z]).+?(\s|\Z)}{$2}sge;my$c=-1;
$friends=~s{(me|\Z)}{++$c;@_=(qw|ust nother erl acker|);qq!$_[$c] !;}eg; $friends}
Rob Pengelly posted this at 03:39 — 16th January 2001.
They have: 850 posts
Joined: Jul 1999
Matt, sorry for not mentioning it before, but welcome to TWF, and thanks for your contributions so far!
Just a simple thing with your code, if he was planning on printing any output to the browser, he will need:
print "Content-type:text/html\n\n";
.
Here is my simple solution
#!/usr/bin/perl -w
my $file = 'filename.html';
print "Content-type:text/html\n\n";
open(IN,$file) or die "Cannot open $file: $!";
print while <IN>;
close(IN);
Just curious, is there a reason to flock the file when reading content? I always thought that flock was only required when writing to a file?
http://www.thehungersite.com - http://www.therainforestsite.com
http://www.ratemymullet.com - Beauty is only mullet deep.
Matt@Ikonboard posted this at 11:38 — 16th January 2001.
They have: 16 posts
Joined: Jan 2001
Hi Rob, thanks for the welcome
I always lock to read and write out of habit. A file lock is conditional, so if it's locked to write (flock FH, 2 or better flock FH, LOCK_EX) and a non-locked request to read is made, the write lock is dropped and the data *can* be flushed before it's printed back.
I learnt that the hard way.
my $friends = qq[=:Jilly , Andrew , Peter & Harry:=];
print &welcome($friends), "2"; my @home;
sub welcome{my $s=shift; $s=~s{^(=\(.+?)(\:=)$}
{$_=$2;@home=split/[&,]/;}esgx;$friends= join'me',@home;
$friends=~s{(\A|\S|\s+)([A-Z]).+?(\s|\Z)}{$2}sge;my$c=-1;
$friends=~s{(me|\Z)}{++$c;@_=(qw|ust nother erl acker|);qq!$_[$c] !;}eg; $friends}
Matt@Ikonboard posted this at 11:42 — 16th January 2001.
They have: 16 posts
Joined: Jan 2001
Oh, and a good habit to get into is to be explicit about the file read/write request.
Use either '<$file' to read, '>$file' to write and '>>$file' to append. Using '$file' on it's own can lead to exploitation of the file while the data is being processed.
I got my ass burned at comp.lang.perl.misc for just using open FH, $File;
my $friends = qq[=:Jilly , Andrew , Peter & Harry:=];
print &welcome($friends), "2"; my @home;
sub welcome{my $s=shift; $s=~s{^(=\(.+?)(\:=)$}
{$_=$2;@home=split/[&,]/;}esgx;$friends= join'me',@home;
$friends=~s{(\A|\S|\s+)([A-Z]).+?(\s|\Z)}{$2}sge;my$c=-1;
$friends=~s{(me|\Z)}{++$c;@_=(qw|ust nother erl acker|);qq!$_[$c] !;}eg; $friends}
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.