[8279] in Perl-Users-Digest
Perl-Users Digest, Issue: 1896 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Feb 14 02:07:49 1998
Date: Fri, 13 Feb 98 23:00:22 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Fri, 13 Feb 1998 Volume: 8 Number: 1896
Today's topics:
[HELP] Works on Irix, Solaris...pukes on Linux -> Perl <hanzo@sni.net>
Re: A Pubilc Apology. <joseph@5sigma.com>
Appending information to a referring html document <cravaccio@usa.net>
Arrgh! :-0 Syntax problems? <jess@links.magenta.com>
Re: Basic File Manipulation <ebohlman@netcom.com>
Re: Basic File Manipulation <cybersky@generation.net_no_spam>
Re: Binary Search Trees (Abigail)
Re: Can you flush a print statement to the browser imme (David Efflandt)
Re: convert Perl for UNIX to NT 4.0 (Troy Denkinger)
Re: environment under NT ? (Troy Denkinger)
Re: FAQless Forays (was: Code Example Needed) (Chip Salzenberg)
Free Fast Web Counter <password@password.com>
Re: help: Question on hash ref <danboo@negia.net>
Re: help: Question on hash ref <danboo@negia.net>
Re: How do I tell if a process is running in WIN32 perl (Troy Denkinger)
Re: Is this correct? File Locking <rebel@wantree.com.au>
Re: Killfile Triage (Nicholas Carey)
Re: Learning Perl (James L. Taylor)
Re: Name of an download file (David Efflandt)
Reg Exp How Do I... djcyr@NOSPAM.connix.com
Re: Sample, simple script which uses threads ? (Jonathan Feinberg)
Substitution in perl for newbie (Jerry)
Re: what does "deprecate" mean? <joseph@5sigma.com>
Re: Where to start. (Jonathan Feinberg)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 14 Feb 1998 05:01:31 GMT
From: "Hanzo" <hanzo@sni.net>
Subject: [HELP] Works on Irix, Solaris...pukes on Linux -> Perl Socket Code
Message-Id: <01bd3905$7c5050e0$01df83cc@galford.sni.net>
I wrote a perl script about a year ago that used UDP to query a server and
read in some data. I recall writing it on Perl for Solaris, and testing on
Irix and some other flavors of Unix. When I brought the code home to my
Linux box...it didn't work, puking on (I believe) either the send() or
gethostbyname() function (actually, I'm pretty sure send() puked *because
of* gethostbyname()).
Anyway, I managed to fix it. That was a year ago, and the code is long
since gone.
Now, a year later, I've tried to write a similar program. Once again,
using UDP, I'm trying to query a server and read in data. And I've tested
the script on Irix and Solaris. Works like a charm.
Brought it home to my Linux box...what do you think happened? ;)
Here are the errors at the prompt:
======
Useless use of gethostbyname in void context at
/usr/lib/perl5/Sys/Hostname.pm l
ine 42.
Use of uninitialized value at ./q2query.pl line 29.
Use of uninitialized value at ./q2query.pl line 48.
Content-type: text/html
<html>
ERROR: Send at ./q2query.pl line 120.
======
...and here are the errors from the web server, when the script is run as a
CGI:
======
sh: /dev/null: Permission denied
sh: /dev/null: Permission denied
Can't exec "/com/host": No such file or directory at
/usr/lib/perl5/Sys/Hostname
.pm line 87.
Cannot get host name of local machine at
/usr/local/etc/httpd/apache/cgi-bin/q2q
uery.pl line 42
[Fri Feb 13 22:56:23 1998] access to
/usr/local/etc/httpd/apache/cgi-bin/q2query
.pl failed for 204.131.223.1, reason: Premature end of script headers
=======
Keep in mind that my networking (and DNS) are all working fine on the Linux
box.
Hopefully, those of you who are skilled with sockets can take a glimpse at
this code and tell me what I need to tweak for a Linux platform.
--
Shawn Holmes - Senior Project Manager
Banished Entertainment - http://www.sni.net/banished
Code Begins Here:
-----------------
#!/usr/bin/perl -w
require 5.002;
use strict;
use Socket;
use Sys::Hostname;
my ($input_host, $count, $rout, $rin, @output, $amount, $nogood,
$q2_response, $name, $value, %contents, @pairs, $pair, $buffer,
@newoutput, $newamount, @newline, $lineamount);
if ($ENV{'REQUEST_METHOD'} eq 'POST')
{
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs)
{
($name, $value) = split(/=/,$pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$contents{$name} = $value;
}
}
my $internet_address = gethostbyname(hostname());
my $protocol = getprotobyname('udp');
my $port = 0; #random port
my $port_address = sockaddr_in($port,$internet_address);
my $a = 0;
my $b = 0;
my $q2_server = inet_aton($contents{SERVER}) || die "ERROR: Unknown
Host\n\n";
my $q2_port = sockaddr_in($contents{PORT},$q2_server);
my $q2_msg = sprintf ("\xFF\xFF\xFF\xFFstatus\0");
my $q2_response = "";
print "Content-type: text/html\n\n";
print "<html>\n";
&Connect_and_query($q2_msg);
if ($q2_response ne "")
{
@output = split(/\\/,$q2_response);
$amount = @output;
$nogood = shift(@output);
print "<head><title>Results</title></head>\n";
print "<body bgcolor=\"000000\" text=\"00FF00\">\n";
print "<hr><br>\n";
print "<b>Server info settings:</b><p><font face=\"Courier New\"
size=\"2\">\n";
print "<table border=\"1\" cellpadding=\"0\" cellspacing=\"0\">\n";
while($output[$a] ne "hostname")
{
printf "<tr><td><font face=\"Courier New\"
size=\"2\">%s</font></td>\n",$output[$a];
printf "<td><font face=\"Courier New\"
size=\"2\">%s</font></td></tr>\n",$output[$a+1];
$a+=2;
}
@newoutput = split(/\n/,$output[$a+1]);
$newamount = @newoutput;
printf "<tr><td><font face=\"Courier New\"
size=\"2\">%s</font></td>\n",$output[$a];
printf "<td><font face=\"Courier New\"
size=\"2\">%s</font></td></tr>\n",$newoutput[$b];
print "</table>\n";
print "</font>\n";
if ($newoutput[1])
{
print "<hr><table border=\"1\" cellpadding=\"4\"
cellspacing=\"0\">\n";
print "<tr><td><b>Frags</b></td><td><b>Ping</b></td><td><b>Name of
Player</b></td></tr>\n";
while ($b < ($newamount - 1))
{
$b++;
@newline = split(/ /,$newoutput[$b]);
$lineamount = @newline;
printf "<tr><td><font face=\"Courier New\"
size=\"2\">%s</font></td><td><font face=\"Courier New\"
size=\"2\">%s</font></td><td><font face=\"Courier New\"
size=\"2\">%s</font></td></tr>\n",$newline[0],$newline[1],$newline[2];
}
print "</table>\n";
} else {
print "<hr><br>\n";
print "<b><font size=\"3\">No Players Current On Server</b>\n";
}
print "</font><br>\n";
print "</body></html>\n";
$count--;
} else {
print "<head><title>WARNING</title></head>\n";
print "<body bgcolor=\"000000\" text=\"00FF00\">\n";
print "<hr><b>WARNING: Server not Responding!!!</b><p>\n";
print "<font face=\"Courier New\" size=\"2\">Check the IP address
and/or port,<br>\n";
print "or verify that the server is up<br>\n";
print "</font><hr></body></html>\n";
}
### PROGRAM END ###
sub Connect_and_query
{
$count++;
socket(SOCKET,PF_INET,SOCK_DGRAM,$protocol) || die "ERROR: Socket:
$!\n\n";
bind(SOCKET,$port_address) || die "ERROR: Bind $!\n\n";
defined(send(SOCKET,$_[0],$port,$q2_port)) || die "ERROR: Send
$q2_server: $!\n\n";
$rin = "";
vec($rin, fileno(SOCKET), 1) = 1;
while ($count && select($rout = $rin, undef, undef, 10.0))
{
$q2_port = recv(SOCKET,$q2_response,2048,0) || die "ERROR: Recv $!\n\n";
}
}
------------------------------
Date: Fri, 13 Feb 1998 22:45:17 -0700
From: "Joseph N. Hall" <joseph@5sigma.com>
Subject: Re: A Pubilc Apology.
Message-Id: <34E52EF6.B1E25E57@5sigma.com>
Generally speaking, a posting that says "please respond via email"
and has a mangled reply-to address is flame bait. I don't think
you'll find much disagreement there.
Mangled addresses have changed my former habit of sending email
copies of postings. I no longer do it, even if the address
looks good offhand.
-joseph
whose mail is about 75% spam some days, even with filtering
Sitaram Chamarty wrote:
> I only responded to a post about munging FROM addresses. That's
> the only one I do not agree with him on - for reasons stated in
> that post, which I will not repeat. That whole post was *only*
> about that and nothing else.
--
Joseph N. Hall, prop., 5 Sigma Productions mailto:joseph@5sigma.com
Author, Effective Perl Programming . . . . . http://www.effectiveperl.com
Perl Training . . . . . . . . . . . . . . . http://www.perltraining.com
------------------------------
Date: Sat, 14 Feb 1998 01:29:06 -0500
From: "Eric" <cravaccio@usa.net>
Subject: Appending information to a referring html document
Message-Id: <6c3dgp$5om$1@viper.shadow.net>
Please help!?!?!?
Does somebody know what I need to write in a perl script to append some
data to the referring HTML document that called up the script?
If so what is the variable or syntax?
Also, what is the syntax for file permissions through a script on that file
so that way others can write to it?
I would really appreciate any suggestions.....
Eric..
------------------------------
Date: Fri, 13 Feb 1998 21:04:26 -0700
From: Jess Askey <jess@links.magenta.com>
Subject: Arrgh! :-0 Syntax problems?
Message-Id: <34E517CA.7B67@links.magenta.com>
Hello,
I have the following sniplet of code that I can't get to work..
> open (FOO, "-|") || exec 'find /a/gamearchive -ctime -7 ' , '%p\n';
> @pages = <FOO>;
> foreach $page (@pages) {
> @out=split(/\.\//,$page);
> $tmp=join('/','',$out[1]);
> $new=substr($tmp,0,length($tmp)-1);
> print("<a href=",$new,">",$new,"</a><br>\n");
> }
I can run "find /a/gamearchive -ctime -7" and it works fine from the
command line,
so Im guessing that Im getting really confused with the way that exec is
set up.
any ideas?
Thank you for your time.
jess (just bought "learning perl" but can't find the answer in
there):-(
--
Jess M. Askey *** Coming Soon - The Game Archive ***
Game Spot/Audio Analyst * Pinball, Video, Parts, Collecting *
509 S. 2nd Street Unit B * http://www.gamearchive.com *
Laramie WY 82070 **************************************
------------------------------
Date: Sat, 14 Feb 1998 03:58:05 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: Basic File Manipulation
Message-Id: <ebohlmanEoCoCt.14t@netcom.com>
Amine <cybersky@generation.net_no_spam> wrote:
: sub ArrayIndexSize #Return the size of the index file
: {
: $Separator = $/;
: $/ = ' ';
: local($File) = @_;
: local (@list);
: open(Index,$File) || die "\nCouldn't open $FILE : $!\n";
: local(@list) = <Index>;
: $c = scalar(@list);
: close(Index) ;
: $/ = $Separator;
: return($c);
: }
: sub AccessLine #Access the line of the index file
: {
: local($LineNumber,$Index,$File,$ArrayAddress) = @_;
: $a = scalar(@$ArrayAddress);
: open(FILE,$File) || die "\nCouldn't open $$FILE : $!\n";
: seek(FILE,$$ArrayAddress[$LineNumber],0);
: $/ = $Separator;
: $line = <FILE>;
: chop($line);
: return($line);
: close(FILE);
: close(Index);
: }
This is going to tremendously slow you down, since you do this repeatedly.
Presumably the index file is small enough to keep in memory; I suggest you
read it into an array in ArrayIndexSize and just pull lines out of that
array in the above routine.
: sub IndexLines # Index the lines of the file
: {
: local($FILE) = @_;
You're copying an array to a single-element list. Replace with:
my $file=shift;
: local(@list);
replace with:
my @list;
: $i = 0;
: $a = '';
Junk the above two lines.
: open(MGRFILE,"$$FILE") || die "\nCouldn't open $$FILE : $!\n";
Why the double dollar signs?
Junk everything from here:
: push(@list,$i);
: while (!eof(MGRFILE))
: {
: seek(MGRFILE,$i,0);
: read(MGRFILE,$a,1);
: if ($a eq "\n")
: {
: $i++; #<==== Delete this for Unix
: push(@list,$i+1);
: }
: $i++;
: }
to the last line, and replace them with:
push @list,0;
while (<MGRFILE>) {
push @list,tell MGRFILE;
: return @list;
: }
It is *very* expensive in Perl to do things character-by-character!
You might also get some speedup by returning a reference to the list,
rather than a copy of the list. Of course, you'll have to slightly
modify your main program to deal with this.
------------------------------
Date: Sat, 14 Feb 1998 10:06:42 +0000
From: Amine <cybersky@generation.net_no_spam>
Subject: Re: Basic File Manipulation
Message-Id: <34E56CB2.3AED@generation.net_no_spam>
Hello ALL,
But i must clear much my idea :)
Well as you will notice the index.txt file will be in average 1/6 the
size of the
file, so my next step is to split you 500Mo+ fixed file and generate
for every file
those indexes like index1.txt index2.txt ...
so if your file is 500Mo and you split it in chunks of 100Mo the
index.txt for
every file will be in average 1/6 that's mean 100/6 = ~16Mo so this
will
not be a problem to slurp all the index.txt chunks :)
Did you understand my idea ?
Thanks and hear from you guys :)
Amine Moulay Ramdane
KHeise wrote:
>
> I am a new Perl user with some prior programming knowledge, and so far I just
> love it. There are a couple of questions I have about manipulating and
> outputting I have.
>
> Background: I am dealing with very large, fixed length data files (500M+ -
> 1,000,000+ records (lines)).
>
> Question 1: Luckily our company appends a CRLF (carriage-return line-feed) at
> the end of each record (line) even though we don't really need it, so it has
> been easy for me to isolate records (lines), but there are times when I wont
> want to use the CRLF as a record delimiter. I will want to define the records
> according to x number of bytes (i.e.record1 = byte 0 - 199, record2 = 200-399,
> etc.). It seems like an easy problem, but I can't figure out a clean,
> efficient, and **fast** to deal with a file in this manner.
>
> Question 2: I want to reverse the lines in a large file.
> (i.e. File = "AA""AB""AC""AD"- Reversed File = "AD""AC""AB""AA"). Is there an
> easy way to do this? Remember, these files are pretty huge, so I can't simply
> reverse the contents of a list(I think).
>
> Question 3: How do you return the number of bytes in a file?
>
> Any comments, code, advice, etc. would be greatly appreciated. I'm really
> exited about Perl and I could use all the help I can get to improve my
> programming skills.
>
> Jay
>
> e-mail addr - kheise@pgicompanies.com
------------------------------
Date: 14 Feb 1998 06:46:56 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Binary Search Trees
Message-Id: <6c3el0$pcn$1@client3.news.psi.net>
Tom Christiansen (tchrist@mox.perl.com) wrote on 1624 September 1993 in
<URL: news:6bpul1$ibb$1@csnews.cs.colorado.edu>:
++ [courtesy cc of this posting sent to cited author via email]
++
++ In comp.lang.perl.misc, rjk@coos.dartmouth.edu writes:
++ :How about, trees can keep their elements in sorted order.
++
++ True. But how often is it more efficient to blow a whole hash
++ per node instead of just extracting the keys first and running
++ an N*logN sort on those before your traversal? I believe that
++ for most applications don't need the heavy hit.
What's the point in putting your keys in a hash if you want to do things
once? Both hashes and trees are data structures which can be used if
your algorithm benefits from preprocessing your data set. If you want
to do simple queries, hashes work well in practise. If you want to do
range queries, or nearest neighbour queries, trees beat linear search,
which is equivalent in using hashes.
++ To test this, I've made several benchmarks. All work on the
++ same datafile containing 100000 random (but distinct) words
++ out of a very large version of /usr/dict/words.
++
++ |----TIMES----| |----MEMORY---|
++ User System Size RSS
++ reghash 3.13 0.16 16240 13864
++ simtree 34.66 0.31 27886 22909
++ trhash 47.38 0.28 27831 22909
++ dbhash1 21.57 13.81 2068 1456
++ dbhash2 22.71 12.83 2068 1460
++
++ reghash is a couple line of code using a regular old hash and then
++ sorting the keys. Notice how very quick it is.
That's a nice table, but what did you benchmark? What's the problem
you're solving?
Abigail
--
perl5.004 -wMMath::BigInt -e'$^V=new Math::BigInt+qq;$^F$^W783$[$%9889$^F47$|88768$^W596577669$%$^W5$^F3364$[$^W$^F$|838747$[8889739$%$|$^F673$%$^W98$^F76777$=56;;$^U=substr($]=>$|=>5)*(q.25..($^W=@^V))=>do{print+chr$^V%$^U;$^V/=$^U}while$^V!=$^W'
------------------------------
Date: Sat, 14 Feb 1998 05:42:20 GMT
From: efflandt@xnet.com (David Efflandt)
Subject: Re: Can you flush a print statement to the browser immediately?
Message-Id: <34ea2e29.10389763@flood.xnet.com>
Tom Christiansen <tchrist@mox.perl.com> wrote:
>:been run. Is there any way to "flush" the print commands to the screen
>:immediately so that the user can see that something's going on?
>
>Yes, sometimes; but dealing with flushing as the very first question of
>perlfaq5 explains is only part of it (you did read that, didn't you?).
>
>You are going to have to deal with user buffering, kernel buffering,
>server buffering, and network buffering. Oh, what fun!
>
>You'll have to go look up NPH scripts. This is not a perl issue.
>
>--tom
You forgot browser buffering, as in: MSIE and other Mosaic based
browsers do not display anything until they get the whole page.
David Efflandt/Elgin, IL USA
efflandt@xnet.com http://www.xnet.com/~efflandt/
------------------------------
Date: Fri, 13 Feb 1998 04:39:11 GMT
From: troy@whadda.com (Troy Denkinger)
Subject: Re: convert Perl for UNIX to NT 4.0
Message-Id: <6c37bq$4gh$1@hirame.wwa.com>
[cc'd via email]
In article <6c1p35$rnm$0@208.207.70.134>, "Chris Podurgiel"
<podurgiel@goodnewsnet.net> wrote:
>Is there a way to convert a Perl app made for Unix to work under an NT4.0
>server?
Your second question has been appropriately answered, so
I'll field this one.
You haven't provided any example code so...
In short, you probably won't have to do anything. Make sure
your #! path is correct and try it out. If it fails, figure
out why. Use -d to debug if you have to.
I run scripts on both platforms and they usually run fine
out of the gate. If you're using stuff that isn't
implemented on NT, you'll have to figure out a different
way for the NT version.
Regards,
Troy Denkinger
------------------------------
Date: Fri, 13 Feb 1998 04:48:18 GMT
From: troy@whadda.com (Troy Denkinger)
Subject: Re: environment under NT ?
Message-Id: <6c37ss$4gh$2@hirame.wwa.com>
[cc'd via email]
In article <6c0rv7$osn$1@narses.hrz.tu-chemnitz.de>,
cbo@hrz.tu-chemnitz.de (Christian Bobber) wrote:
>Hello,
>I would set an environment variable from perl for NT.
>The following command don't work:
>
>1. $ENV{'VARIABLE'} = "VALUE";
>2. system('set variable=value');
Impossible to say. Since you haven't included the example
program, we can't really try it out.
If you're code is right, it's very likely an OS problem.
You might find an answer if you check the
comp.os.ms-windows.nt.* groups. Please check their FAQs
first.
Regards,
Troy Denkinger
------------------------------
Date: Sat, 14 Feb 1998 04:16:58 GMT
From: chip@mail.atlantic.net (Chip Salzenberg)
Subject: Re: FAQless Forays (was: Code Example Needed)
Message-Id: <6c35up$nct$1@cyprus.atlantic.net>
According to gabor@vmunix.com (Gabor):
>local ($/) = undef;
Two nits. First, parens on local and my are not required if there's
only one variable. Thus:
local $/ = undef;
Second, "local ... = undef" is redundant; the initial localized
value of any scalar is undef. Thus:
local $/;
--
Chip Salzenberg - a.k.a. - <chip@pobox.com>
"Hoist the failure sails, men! We're goin' home!" // MST3K
-> Ask me about Perl training and consulting <-
Like Perl? Want to help out? The Perl Institute: www.perl.org
------------------------------
Date: Sat, 14 Feb 1998 06:11:19 +0700
From: "PassWord." <password@password.com>
Subject: Free Fast Web Counter
Message-Id: <34E4D317.4F81@a.com>
Free . . .=-=-=>>> Fast Web Counter
http://205.147.208.53/freecount/
------------------------------
Date: Fri, 13 Feb 1998 23:26:07 -0500
From: Dan Boorstein <danboo@negia.net>
Subject: Re: help: Question on hash ref
Message-Id: <34E51CDF.A4E22CDC@negia.net>
TomH wrote:
>
> "my" makes the variable %TEST out of scope inside the RetVal subroutine.
>
[snip]
> >
> > #!/usr/local/bin/perl
> > # This script does not work
> > my %TEST= ( "FIRST" => 1, "SECOND" => 2 );
> > my %TEST2= ( "WHITE" => "FFFFFF", "BLACK" => "000000" );
> > my $VAL= &RetVal( ARRAY => "TEST", POS => "FIRST" );
> > print $VAL; # exactly equal to print $TEST{FIRST};
> >
> > sub RetVal {
> > my %Q= @_;
> > $A= $Q{ARRAY};
> > return $$A{$Q{POS}};
> > }
are you sure about that? so are you saying that this won't print 'potato'?
try it.
my $myVar = 'potato';
print &RetVal;
sub RetVal {
return $myVar;
}
--
danboo rstein
------------------------------
Date: Sat, 14 Feb 1998 00:01:13 -0500
From: Dan Boorstein <danboo@negia.net>
Subject: Re: help: Question on hash ref
Message-Id: <34E52519.9B305CB@negia.net>
Tommy wrote:
[snip]
>
> #!/usr/local/bin/perl
> # This script does not work
> my %TEST= ( "FIRST" => 1, "SECOND" => 2 );
> my %TEST2= ( "WHITE" => "FFFFFF", "BLACK" => "000000" );
> my $VAL= &RetVal( ARRAY => "TEST", POS => "FIRST" );
> print $VAL; # exactly equal to print $TEST{FIRST};
>
> sub RetVal {
> my %Q= @_;
> $A= $Q{ARRAY};
> return $$A{$Q{POS}};
> }
symbolic references can only be used to access package variables. though
%TEST is not out of scope, it cannot be accessed with symbolic references.
note what happens when you remove the 'my' declaration from %TEST in the
code above.
--
danboo rstein
------------------------------
Date: Fri, 13 Feb 1998 05:10:22 GMT
From: troy@whadda.com (Troy Denkinger)
Subject: Re: How do I tell if a process is running in WIN32 perl???
Message-Id: <6c3969$4gh$3@hirame.wwa.com>
[cc'd via email]
In article <6bvttj$m27$1@bashir.ici.net>, sbourgeo@ici.net
(Steve Bourgeois) wrote:
>I'm trying to get a perl-based utility working that needs to run on UNIX and
>Windows NT. On UNIX, I could use the "ps" command or kill a process with
>the null signal "kill -0" to see if it's running.
>
>Is there a clever way to do this in NT??? I tried the "kill -0" approach,
>but NT's lack of POSIX compliance seems to make the null signal
>unavailable.
To view/kill currently running processes:
Ctrl-Alt-Del | Task Manager | Processes
Future questions of this type should be aimed at
comp.os.ms-windows.nt.*
Regards,
Troy Denkinger
------------------------------
Date: Sat, 14 Feb 1998 16:52:47 -1100
From: Chris <rebel@wantree.com.au>
To: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Is this correct? File Locking
Message-Id: <34E6668F.2C72@wantree.com.au>
Tom Christiansen wrote:
>
> [courtesy cc of this posting sent to cited author via email]
>
> In comp.lang.perl.misc, rebel@wantree.com.au writes:
> :I know this is a bit of an old subject, but I felt impelled to respond
> :to it.
> :I am, like Bill coming to terms with perl,cgi and unix (I'm on a windoze
> :machine).
> :perhaps you should not have been so hard on him.
> :I can relate to his story, and he did choose wisely to consult the
> :"experts" on the matter.
>
> You have no idea how ugly that paragraph miswrapped. :-(
Well turn off your line wrapper!
>
> : sub lock {
> : flock(MBOX,$LOCK_EX);
> : # and, in case someone appended
> : # while we were waiting...
> : seek(MBOX, 0, 2);
> : }
> : sub unlock {
> : flock(MBOX,$LOCK_UN);
> : }
> : open(MBOX, ``>>/usr/spool/mail/$ENV{'USER'}'')
> : or die ``Can't open mailbox: $!'';
> : lock();
> : print MBOX $msg,"\n\n";
> : unlock();
>
> The problem was that when I wrote that, I didn't realize that
> few people understood issues of stdio buffering. So in 5.004,
> we changed LOCK_UN so it pre-flushes.
>
> --tom
I dont think its so much the buffering, as the locking process, that
people perhaps don't fully understand.
One would assume, and obviously incorrectly so, that if your operating
system is going to buffer a file, that it would be intelligent enough to
include the buffer as part of that file, with respect to locking the
file.
In other words, I believe that it should be up to the operating system*
to flush any buffers before releasing a lock. thats the logical and
safest thing to do.
*not Perl.
--
Regards
Chris
---
They say that the more you learn, the more you find there is to learn.
Therefore: the smarter you think you are, the dumber you actually are.
---
------------------------------
Date: Sat, 14 Feb 1998 04:43:41 GMT
From: a-bnc@microsoft.com (Nicholas Carey)
Subject: Re: Killfile Triage
Message-Id: <34e4f51f.27691875@newsvr>
Shmuel (Seymour J.) Metz <spamtrap@library.lspace.org> whined:
>Newsgroups: comp.lang.perl.misc,news.software.readers
>Subject: Re: Killfile Triage
>Date: Wed, 11 Feb 98 08:12:19 -0500
>Organization: Atid/2
>Lines: 33
>Message-ID: <34e1a3b3$1$fuzhry$mr2ice@news1.mnsinc.com>
>References: <6bnv7o$n1g$1@csnews.cs.colorado.edu>
>NNTP-Posting-Host: 206.55.10.86
>X-Cise: "Tony Schliesser" <aschlies@citynet.net>
>X-CompuServe-Customer: Yes
>X-Coriate: AGIS
>X-Punge: Micro$oft
>X-Terminate: SPA(GIS)
>X-Newsreader: MR/2 Internet Cruiser Edition for OS/2 v1.46 b46
>Xref: news.microsoft.com comp.lang.perl.misc:105932 news.software.readers:28232
>In <6bnv7o$n1g$1@csnews.cs.colorado.edu>, on 02/09/1998
> at 10:16 PM, Tom Christiansen <tchrist@mox.perl.com> said:
>>The last directive in the following group
>>destroys any postings related to spam in any fashion. In particular,
>>this is to get rid of postings by people who like to put quirky "nospam"
>>gimmicks in their addresses, making it difficult to contact these people.
>>Let them eat /dev/null! Such "From" lines are not just a pain in the
>>butt; they are also not legal, and I zap illegal messages.
>Sigh! Good advice costs nothing and it's worth the price. The presence of
>"nospam" in an address does not mean that it is munged, that it is illegal
>or even that it is undeliverable. Anyone with half a clue would recognize
>that this filter will hit valid addresses as well as the invalid ones.
>Bottom line: do your own research on the consequences of a filter; don't
>just rely on the author.
>--
>-----------------------------------------------------------
> Shmuel (Seymour J.) Metz, SysProg and JOAT
> Atid/2
> Team OS/2
> Team PL/I
>Any unsolicited commercial junk E-mail will be subject to legal action. I
>reserve the right to publicly post or ridicule any abusive E-mail.
>I mangled my E-mail address to foil automated spammers; reply to domain
>acm dot org user shmuel to contact me. Do not reply to
>spamtrap@library.lspace.org
>-----------------------------------------------------------
On 13 Feb 1998 17:03:11 +0000, Richard Caley <spt@cstr.ed.ac.uk>
wrote:
>In article <6bnv7o$n1g$1@csnews.cs.colorado.edu>, Tom Christiansen (tc) writes:
>
>tc> /spam/h:j
>
>So, people who put requests not to be spammed in their headers should
>be killed but people like me who have applied some spamproofing should
>not. I'm not clear on the logic here.
>
>--
>Mail me as rjc not spt@cstr.ed.ac.uk _O_
> |<
>
------------------------------
Date: Sat, 14 Feb 1998 04:35:22 GMT
From: cowboy@cnnw.net (James L. Taylor)
Subject: Re: Learning Perl
Message-Id: <34e51e24.83532638@news.cnnw.net>
On 13 Feb 1998 08:26:42 GMT, "Eric D. Friedman" <friedman@uci.edu>
wrote:
>In article <34e3fe9c.9914092@news.cnnw.net>,
>James L. Taylor <cowboy@cnnw.net> wrote:
>
><sub init_words {
><open(WORDSLIST, "wordslist.pl"); # I have this named wordslist &
>
>does "Learning Perl" really have an open() without the
>accompanying check for an error?
>
>You should always write open() this way:
>
>open WORDLIST, "<wordlist" || die "Can't open wordlist: $!";
>
>(note the chance of the filename: you're opening your program source
>and not the datafile)
>
>
>--
>Eric D. Friedman
>friedman@uci.edu
Ok I made the change to: open WORDSLIST, "<wordslist.pl" || die
"Can't open wordlist: $!";
and it still wont open, I still get wrong try again?
I have just gone thru the book and made sure everything was the same
except that line and I still get the wrong message???
James L. Taylor
www.bannerfx.com
------------------------------
Date: Sat, 14 Feb 1998 05:38:32 GMT
From: efflandt@xnet.com (David Efflandt)
Subject: Re: Name of an download file
Message-Id: <34e92770.8668193@flood.xnet.com>
Beranger Bruneton <beran@isdnet.net> wrote:
>>
>> I wrote an cgi with perl to download
>> a file but when the Fileselector appear
>> the name of the download file is the name
>> of my cgi.
>>
>> How can i change the name ?
This question should have been directed to a cgi newsgroup since the
specific question has nothing to do with perl.
For browsers other than Netscape, the only thing you can do is give
the script the same name that you want the download file to have and
enable that file extension as a CGI script. The actual files are kept
in a separate directory. On a Unix system you can link a single
script to multiple names and look at the name you were called as for
the file to download (symlinks normally, hard links with apache
suexec).
The only servers I know how to do this on are NCSA and Apache, *IF*
you allow to set this in an .htaccess file.
Another problem if you are trying to limit downloads is that MSIE
actually makes 2 requests for each file downloaded. But I have not
gotten around to checking if one is just a HEAD request (to get file
size) that would distinguish it from a GET request to retrieve the
actual file. MSIE ignores most headers including Content-type: so you
should advise the user to right click on the link.
David Efflandt/Elgin, IL USA
efflandt@xnet.com http://www.xnet.com/~efflandt/
------------------------------
Date: 14 Feb 1998 06:07:21 GMT
From: djcyr@NOSPAM.connix.com
Subject: Reg Exp How Do I...
Message-Id: <6c3cap$78v@beast.connix.com>
This seems like a really simple problem:
How do I remove all commas from a text file, EXCEPT
those commas where there is a space immediately after the comma?
Any help would be appreciated.
TIA
------------------------------
Date: Sat, 14 Feb 1998 00:50:51 -0500
From: jdf@pobox.com (Jonathan Feinberg)
Subject: Re: Sample, simple script which uses threads ?
Message-Id: <MPG.f4efac29bdb9fef9896c4@news.concentric.net>
[This followup was posted to comp.lang.perl.misc and a copy was sent to the
cited author.]
lmb@pointer.teuto.de said...
> Like, how do I start a new thread and how do I communicate between threads.
> How do I declare variables local to a thread.
Perl does not yet support threads. Perl5.005, I believe, will have such
support. Perhaps you want fork() and its cousins?
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
------------------------------
Date: Sat, 14 Feb 1998 05:41:56 GMT
From: nospam@nospam.com (Jerry)
Subject: Substitution in perl for newbie
Message-Id: <34e62d99.174287792@192.168.1.1>
hello,
I'm trying to get a substitution/cut to work in a script. I'm not
having any luck. Any help would be appreciated. I have both Learning
Perl and the Camel and in addition I've looked through the FAQ's on
perl.com/perl.org. Still no luck. I'm just not making the
connection.
Here's what I want to do:
I'm going to get the remote address ip, say 205.213.42.193. I know
how to do that(amazing). However I want to basically cut off the last
part of the address so it will be 205.213.42 and that's it. Easy
right?
I've tried a more than a few different methods, but still can't get
it. Must be a mental block.
Thank you for any help.
------------------------------
Date: Fri, 13 Feb 1998 20:53:15 -0700
From: "Joseph N. Hall" <joseph@5sigma.com>
Subject: Re: what does "deprecate" mean?
Message-Id: <34E514B8.E1552EC1@5sigma.com>
Wasn't this a Pink Floyd lyric?
"The way you made them suffer,
Your exquisite wife and mother,
Fills me with the urge to deprecate"
No, maybe that wasn't quite it. :-)
-joseph
Kevin B Cohen wrote:
>
> okay, i *know* what it means to "deprecate" in english, but what does
> it mean in perlish? here are some examples of usage (hope i'm not
> violating any laws of copyright...):
--
Joseph N. Hall, prop., 5 Sigma Productions mailto:joseph@5sigma.com
Author, Effective Perl Programming . . . . . http://www.effectiveperl.com
Perl Training . . . . . . . . . . . . . . . http://www.perltraining.com
------------------------------
Date: Sat, 14 Feb 1998 01:28:43 -0500
From: jdf@pobox.com (Jonathan Feinberg)
Subject: Re: Where to start.
Message-Id: <MPG.f4f03a3d66bd9789896c5@news.concentric.net>
brad@liquid-web.com said...
> I want to try and learn Perl programming, CGI whatever you want to call
> it. Anyone have any good online tutorials, or have seen some?!
*sigh*
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
------------------------------
Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Mar 97)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V8 Issue 1896
**************************************