[18119] in Perl-Users-Digest
Perl-Users Digest, Issue: 279 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Feb 13 03:05:49 2001
Date: Tue, 13 Feb 2001 00:05:09 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <982051509-v10-i279@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 13 Feb 2001 Volume: 10 Number: 279
Today's topics:
[OT] Re: Looking for alternative to Google (was deja) n <jdf@pobox.com>
cgi and NT installing and testing <nowayandnohow@hotmail.com>
Re: cgi script sending mail <camerond@mail.uca.edu>
Re: Finding multiply of prime factors (Tony L. Svanstrom)
Global Variables <pmckenna@writeme.com>
Hashes and references driving me nuts <sat@multitech.com>
Re: Hashes and references driving me nuts <joe+usenet@sunstarsys.com>
Re: Hashes and references driving me nuts <wyzelli@yahoo.com>
Re: Hashes and references driving me nuts (Damian James)
Re: Help Running Perl Scripts from a web-page <peter.sundstrom-eds@eds.com>
How bad is that Jeopardy post? (Tramm Hudson)
Re: How bad is that Jeopardy post? <godzilla@stomp.stomp.tokyo>
Re: How bad is that Jeopardy post? (Villy Kruse)
Locking really large file <jscottwilliams@excite.com>
Re: Looking For A Good Sockets Tutorial (Mark Jason Dominus)
measuring sizeof of STDIN <sean@tnq.com>
Re: measuring sizeof of STDIN <jdf@pobox.com>
need help going from UNIX to Windows <jeff_fletcher@pacbell.net>
Newbie: read & remove last line from a txt file. <DavePerkins@bigfoot.com>
Re: Newbie: read & remove last line from a txt file. <joe+usenet@sunstarsys.com>
Re: Newbie: read & remove last line from a txt file. <wyzelli@yahoo.com>
Performance question <pmckenna@writeme.com>
Re: Problems with ActiveState Perl, please help. <jdf@pobox.com>
Problems with hashes - help <MichaelAnthony@MailAndNews.com>
Re: Problems with hashes - help <jdf@pobox.com>
require statement on NT 4.0 <mdobos@tpg.com.au>
Re: require statement on NT 4.0 (Damian James)
Re: socket problem <jdf@pobox.com>
Using split to chop up a flat database file (Michael)
Re: Using split to chop up a flat database file <jdf@pobox.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 13 Feb 2001 01:35:47 -0500
From: Jonathan Feinberg <jdf@pobox.com>
Subject: [OT] Re: Looking for alternative to Google (was deja) newsgroup search
Message-Id: <u25zccos.fsf@pobox.com>
Keith Harrison <harriso2@pilot.msu.edu> writes:
> Google has taken over the newsgroup search site www.deja.com and changed
> the format to, in my opinion, an inferior one. Does anyone know of
> another site that's comparable to the old deja?
That is one hand I will not be biting any time soon. They're
resuscitating the dying body of Deja's Usenet archive, and they're
bringing back the old stuff that Deja took offline. Their web search
is (IMHO) the best by far, the quickest and most likely to return
relevant results. Therefore, I don't doubt that they will refine and
improve their Usenet archive.
I'd be more inclined to write and *thank* them than to spank them,
though I'm sure criticisms will be taken seriously, especially if
expressed in a contructive tone.
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
http://pobox.com/~jdf
------------------------------
Date: Tue, 13 Feb 2001 03:29:37 GMT
From: "nowayandnohow" <nowayandnohow@hotmail.com>
Subject: cgi and NT installing and testing
Message-Id: <BS1i6.8340$R45.2586372@typhoon2.ba-dsg.net>
I am sure that all of you are tired of these questions, I have been around
and all guides are either to high level for me or just about the apache
server or unix servers.
I downloaded the cgi.pm package and performed the makefile.pm.
now this makes a file called "makefile"
now what ? there is plenty of help and recourses for unix users, but very
slim for NT.
My questions are as follows:
I have performed what the manual told me:
> cd CGI.pm-2.73
> copy CGI.pm C:\Perl\lib
> mkdir C:\Perl\lib\CGI
> copy CGI\*.pm C:\Perl\lib\CGI
Now what ?
I am a major newbie to perl, and all the guides start rambling on about how
to add stuff to databases and other advanced stuff. I just want to know how
I check if cgi is working on my IIS server.
could someone please have the heart and help me with this.
Is all I have to do is copy the cgi files to where they are suppose to be?
is there something else i need to do ? i have activestate perl running fine
on this machine.
How do i test if perl is running ?
i put a simple perlscript in the root of my webserver:
print "WHat's your name? ";
$name = <STDIN>;
$name =~s/[\n\r]//g;
print "Hello $name!\n";
and put http://localhost/the_name_of_the_filbe.cgi?my_name in the url field.
but all it did was to show me the text the document contained.
have a heart and take some time and guide me through this.
// Jo
------------------------------
Date: Mon, 12 Feb 2001 20:22:08 -0600
From: Cameron Dorey <camerond@mail.uca.edu>
Subject: Re: cgi script sending mail
Message-Id: <3A889A50.7FA3C090@mail.uca.edu>
Kannan Narayanan wrote:
>
> I am writing a CGI script in Perl.
>
> When the user sumits a form from the web browser the CGI script should
> collect all the information put in the form and send that info in
> a mail.
>
> Is it possible to do that in Perl?
Sure.
>
> Does anybody done similar stuff or have pointers to related info?
The easiest way would be to use the modules:
CGI.pm (included in the standard distribution)
Mail::Sender.pm or Mail::Sendmail.pm (you can get them both at CPAN)
They have good documentation and examples included. You should be able
to bang out a script to do what you want quickly. I could not explain
how to do what you want to do any better than the authors could, so I'll
leave it to them.
Cameron
--
Cameron Dorey
Associate Professor of Chemistry
University of Central Arkansas
Phone: 501-450-5938
camerond@mail.uca.edu
------------------------------
Date: Tue, 13 Feb 2001 07:17:10 GMT
From: tony@svanstrom.com (Tony L. Svanstrom)
Subject: Re: Finding multiply of prime factors
Message-Id: <1eord41.14n7ydyxxc0aN%tony@svanstrom.com>
Jonas Nilsson <jonni@ifm.liu.se> wrote:
> Heres a nice quick one that does it recursively.
>
> sub factorize {
> return(2,factorize($_[0]/2)) if (($_[0]%2)==0);
> my $limit=int(sqrt($_[0]));
> my $i=3;
> while ($i<=$limit) {
> if ($_[0]%$i==0) {return($i,factorize($_[0]/$i))};
> $i+=2;
> }
> return $_[0];
> }
>
> $a=int rand 1e8;
> print "$a = ",join(" x ",factorize($a));
7409230211 = 3 x 3 x 823247801.222222
Since when's "823247801.222222" a prime?
/Tony
PS don't quote jeopardy-style... =)
--
/\___/\ Who would you like to read your messages today? /\___/\
\_@ @_/ Protect your privacy: <http://www.pgpi.com/> \_@ @_/
--oOO-(_)-OOo---------------------------------------------oOO-(_)-OOo--
on the verge of frenzy - i think my mask of sanity is about to slip
---ôôô---ôôô-----------------------------------------------ôôô---ôôô---
\O/ \O/ ©99-00 <http://www.svanstrom.com/?ref=news> \O/ \O/
------------------------------
Date: Tue, 13 Feb 2001 07:29:44 GMT
From: Paul <pmckenna@writeme.com>
Subject: Global Variables
Message-Id: <3A88E0C3.62DEE999@writeme.com>
I have a set of several different scripts and modules which all function
together. I would like to create a single module which could house the
global variables used by the scripts. For instance, all of the scripts
need to access a certain named file. I would like to have this file
implemented as a variable in all the various scripts and actually
defined in a single place. I also don't want it to be redefined anywhere
but in the master location. What is the best way of going about this?
How do I make sure that my chosen master definition overides all other
possible definitions. Thanks
Paul
------------------------------
Date: Mon, 12 Feb 2001 21:53:39 -0600
From: "Steve Tuckner" <sat@multitech.com>
Subject: Hashes and references driving me nuts
Message-Id: <ad2i6.1195$jy5.385916@news.uswest.net>
Can someone please explain why this code:
-----------------------------------------------------------
$record1 = { "type" => "integer" };
$record2{ type } = "float";
$sym_table{ record1 } = $record1;
$sym_table{ record2 } = $record2;
print "record 1:";
while (($attr, $attrval) = each %record1) {
print "$attr = $attrval ";
}
print "\n";
print "record type = $record1{type}\n";
$rp = $sym_table{ "record1" };
print "type attrib for record 1 = ", $rp->{type}, "\n";
print "record 2:";
while (($attr, $attrval) = each %record2) {
print "$attr = $attrval ";
}
print "\n";
print "record type = $record2{type}\n";
$rp = $sym_table{ "record2" };
print "type attrib for record 2 = ", $rp->{type}, "\n";
-----------------------------------------------------------
Generates this output???
-----------------------------------------------------------
record 1:
record type =
type attrib for record 1 = integer
record 2:type = float
record type = float
type attrib for record 2 =
-----------------------------------------------------------
------------------------------
Date: 12 Feb 2001 23:28:31 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Hashes and references driving me nuts
Message-Id: <m3elx3jjf4.fsf@mumonkan.sunstarsys.com>
"Steve Tuckner" <sat@multitech.com> writes:
> Can someone please explain why this code:
> -----------------------------------------------------------
> $record1 = { "type" => "integer" };
record1 is a scalar reference to the anonymous hash created by
the curlies {}. It has one key/value pair. It should have
been declared with my:
my $record1 = { type => "integer" }; # hash ref
> $record2{ type } = "float";
record2 is an ordinary hash. It a key named type with value
"float". It also should have been declared with my:
my %record2;
$record2{type} = "float";
or you could have auto-vivified a hash like this
my $record2; # scalar, soon to become a hash ref
$record2->{type} = "float";
However, I'll assume you wanted record2 to be an actual hash
for what follows.
> $sym_table{ record1 } = $record1;
> $sym_table{ record2 } = $record2;
^^^^^^^^^
That is an error. Had you enabled strictures and warnings,
perl would have caught that for you. You probably want
something like
my %sym_table;
$sym_table{ record1 } = $record1;
$sym_table{ record2 } = \%record2; # assigns ref for %record2
> print "record 1:";
> while (($attr, $attrval) = each %record1) {
^^^^^^^^
That is an error. $record1 is a scalar that references
a hash, so you want
while (my ($attr, $attrval) = each %{$record1} ) {
> print "$attr = $attrval ";
> }
> print "\n";
>
> print "record type = $record1{type}\n";
^^^^^^^^^^^^^^
Another error. You need either
print "record type = " . $record1->{type} . "\n";
or
print "record type = $$record1{type}\n";
The rest looks fine.
In the future, always enable warnings and strictures
by starting your program with
#!/usr/bin/perl -w
use strict;
That will help prevent future loss of toes.
HTH
--
Joe Schaefer "Of course," Horton answered. "Of course I will stick. I'll
stick by you small folks through thin and through thick!"
-- Dr. Seuss
------------------------------
Date: Tue, 13 Feb 2001 14:15:39 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: Hashes and references driving me nuts
Message-Id: <MP2i6.36$nh7.3762@vic.nntp.telstra.net>
"Steve Tuckner" <sat@multitech.com> wrote in message
news:ad2i6.1195$jy5.385916@news.uswest.net...
> Can someone please explain why this code:
Because that is what it is coded to do? :)
> -----------------------------------------------------------
> $record1 = { "type" => "integer" };
Are you trying to create a hash here?
maybe you meant:
%record1 = ( "type" => "integer" );
> $record2{ type } = "float";
>
> $sym_table{ record1 } = $record1;
here $record1 (a scalar) is undefined, so the value of the hash
%sym_table with key 'record1' will also be undefined.
> $sym_table{ record2 } = $record2;
ditto
>
> print "record 1:";
> while (($attr, $attrval) = each %record1) {
> print "$attr = $attrval ";
> }
If you make the change as above this prints what I think you are
expecting.
> print "\n";
>
> print "record type = $record1{type}\n";
>
> $rp = $sym_table{ "record1" };
> print "type attrib for record 1 = ", $rp->{type}, "\n";
Since $sym_table{"record1"} is undefined from when you assigned an
undefined scalar to it above, $rp is also undefined.
>
> print "record 2:";
> while (($attr, $attrval) = each %record2) {
> print "$attr = $attrval ";
> }
> print "\n";
>
> print "record type = $record2{type}\n";
>
> $rp = $sym_table{ "record2" };
> print "type attrib for record 2 = ", $rp->{type}, "\n";
ditto
Hope that helps some.
Wyzelli
--
push@x,$_ for(a..z);push@x,' ';
@z='092018192600131419070417261504171126070002100417'=~/(..)/g;
foreach $y(@z){$_.=$x[$y]}y/jp/JP/;print;
------------------------------
Date: 13 Feb 2001 07:04:58 GMT
From: damian@qimr.edu.au (Damian James)
Subject: Re: Hashes and references driving me nuts
Message-Id: <slrn98hn4c.lhi.damian@puma.qimr.edu.au>
Thus spake Steve Tuckner on Mon, 12 Feb 2001 21:53:39 -0600:
>Can someone please explain why this code:
>-----------------------------------------------------------
What's missing from the beginning is:
#!/path/to/perl -w
use strict;
You wouldn't be having these problems if you were working under the
discipline that strict enforfces, and with the information in the
warnings.
>$record1 = { "type" => "integer" };
$record1 is a scalar containing a reference to an anonymous hash.
>$record2{ type } = "float";
%record2 is a hash.
>
>$sym_table{ record1 } = $record1;
Assigns the reference held in $record1 to the hash %sym_table.
>$sym_table{ record2 } = $record2;
>
$record2 would be a scalar, but is not defined. $sym_table{record2} now
'exists' but contains an undefined value.
>print "record 1:";
>while (($attr, $attrval) = each %record1) {
> print "$attr = $attrval ";
>}
There is no hash called %record1 defined. You probably want to say:
%{$record1}
to explicitly dereference $record1.
Note that it's often easier to say something like:
print "$_ = $record1->{$_}\n" for keys %{$record1};
>print "\n";
>
>print "record type = $record1{type}\n";
>
Again, you are trying to print a value from an undefined hash - saying:
$record1->{type}
is probalby what you want.
>$rp = $sym_table{ "record1" };
>print "type attrib for record 1 = ", $rp->{type}, "\n";
>
This assigns the reference that is also in the scalar $record1 and in the
value for $sym_table{record1} to $rp. You then correctly dereference it.
>print "record 2:";
>while (($attr, $attrval) = each %record2) {
> print "$attr = $attrval ";
>}
This ought to work, though as I said above, it's easier as:
print "$_ = $record2{$_}\n" for keys %record1;
>print "\n";
>
>print "record type = $record2{type}\n";
This is also correct.
>
>$rp = $sym_table{ "record2" };
>print "type attrib for record 2 = ", $rp->{type}, "\n";
$rp is now undefined, since you set an undefined value to
$sym_table{record2} above. You then try to dereference an undefined value,
with predictable results.
The moral of the story? Always work with -w and use strict. This would have
prevented ALL the above errors. Note that your code won't even compile
under use strict.
HTH
Cheers,
Damian
--
$;=ord$%,$:=$;-ord q,.,,$_=q 13346:3366:3276:3326:3386:546:566:966:3396:3376:1.
q 73386:546:;96:3326:3336:3386:3266:3236:3366:546::26:3236:3366:32:6:546:32667.
q,:;96:;;6:3296:3236:3366:326:56,,s,.,;ord($&)-$:-$;;;;;,eg,s,$;,;chr$&-$:;,eg,
eval eval; #requires 5.6.0 ## my first attempt at one of these...
------------------------------
Date: Tue, 13 Feb 2001 14:16:27 +1300
From: "Peter Sundstrom" <peter.sundstrom-eds@eds.com>
Subject: Re: Help Running Perl Scripts from a web-page
Message-Id: <96a1tg$1e8$1@hermes.nz.eds.com>
"Falc2199" <falc2199@aol.comNOJUNK> wrote in message
news:20010212194031.17694.00000748@ng-cm1.aol.com...
> Here is a simple script that I wrote in Perl. It works fine when I run it
from
> the Perl Interpreter on my machine, but when I upload it to the net it
doesn't.
>
> #!\usr\bin\perl
> print "Content-type: text/html\n\n";
> print "\n\n";
>
> print "Hello World";
>
> I uploaded the file into the cgi-bin given to me by my web-host, but
everytime
> I go to the file either by typing the exact loc into my browser or
thorough
> another HTML form, it gives me a 500 Internal Server error.
>
> Here is a link to the problem script...
>
> <A HREF = "http://odin.prohosting.com/falc/cgi-bin/test1.cgi"> Problem
Script
> </A>
Not really a Perl question, but you need to replace
#!\usr\bin\perl
with
#!/usr/bin/perl
------------------------------
Date: 13 Feb 2001 04:00:11 GMT
From: hudson@swcp.com (Tramm Hudson)
Subject: How bad is that Jeopardy post?
Message-Id: <96abgb$p36$1@sloth.swcp.com>
Keywords: jeopardy posting, netiquette, etiquette, isohedron, bogoscore, mail filter
Ever wondered exactly how bad was that post asking how to parse
HTML with a regular expression? Did you ever yearn for a ranking
scale that would allow to you kill posts based on the absurdity of
the arguments?
Well, I can't help with that. Too much natural language processing
for me. But I have found that a good first approximation can be
achieved with just a textual analysis of the message. Things like
Jeopardy ("top posting"), excessive quoting, no sig dash, ratio of
quoted text to original.
For a while I used this in conjunction with procmail to flag incoming
mail that was probably not worth reading. Unfortunately too many of
my cow-orkers practice these henious crimes, so I have had to discontinue
it.
So, here is the short program to rank posts on the Bogoscore scale.
A properly written and formatted post ranks 0. At the high end,
a bad MUA with non-plain text encoding, no subject, no sig, quoted sig,
and no original lines ranks 18. I'm sure there are worse posts, but
they haven't been sent my way yet.
Share and enjoy! Comments are welcome.
#!/usr/bin/perl -w
use strict;
use Mail::Header;
use Mail::Send;
use Mail::Util qw/ mailaddress /;
use Getopt::Long;
my $cvs_id = '$Id: bogoscore,v 1.14 2001/02/13 02:07:29 hudson Exp $';
my $verbose = 0;
my $force = 0;
my $check = 0;
my $score = 0;
my $threshold = 4;
my $usage = <<"";
$0: Usage:
-v | --verbose Enables verbosity
-c | --check Just checks for bogosity
-f | --force Forces mail to be sent
-t | --threshold = t Requires t points before sending mail
-V | --version Prints the version and exits
-h | --help Prints this usage information
GetOptions(
'version|V' => sub { print "$cvs_id\n"; exit },
'verbose|v+' => \$verbose,
'check|c+' => \$check,
'force|f+' => \$force,
'threshold|s=i' => \$threshold,
'help|h|?' => sub { print $usage; exit },
) or die $usage;
# If check is selected, force must also be selected to cause the mail
# to be sent.
my $user = mailaddress();
my @reasons = qq{
This is an automated message in response to your recent mail to
$user
For advice on style, quoting and mail user agent configuration, please
see the following documents:
http://www.turbolabs.com/~hudson/rants/style.html
http://www.xs4all.nl/~wijnands/nnq/nquote.html
http://www.tuxedo.org/~esr/jargon/html/Email-Quotes.html
The reason that you received this automated message follow:
};
local $/ = '';
my @badmailers = qw/
Microsoft
Netscape
/;
my @badcontent = qw/
html
quoted-printable
multipart
/;
# Slurp in the headers
my $headers = new Mail::Header [split /\n/, scalar(<>)]
or die "Arrgh: $@\n";
# Store who sent it.
my $replyto = $headers->get( 'From' )
or die "$0: No return address. Oh well.\n";
chomp $replyto;
# Determine the mail client and if it is on the suck list
my $mailer = $headers->get( 'X-Mailer' )
|| $headers->get( 'User-Agent' )
|| 'Unknown MUA';
chomp $mailer;
if( grep { $mailer =~ /$_/ } @badmailers ) {
$score++;
push @reasons, <<"";
+ Your mail user agent tends to be used by less-cluefull users:
$mailer
}
# Check for content type
my $content = $headers->get( 'Content-Encoding' )
|| $headers->get( 'Content-Type' )
|| 'Unknown type';
chomp $content;
if( grep { $content =~ /$_/ } @badcontent ) {
$score+=3;
$content =~ s/;.*$//;
push @reasons, <<"";
+ You have encoded your mail in a non-plain text format:
$content
}
# Check for subject
my $subject = $headers->get( 'Subject' )
|| "No subject\n";
chomp $subject;
if( $subject eq '' or $subject =~ /[Nn]o subject/ or $subject =~ /your mail/ )
{
$score+=2;
push @reasons, <<"";
+ You did not include a meaningful subject. Why would anyone read your
mail without knowing what it was about?
}
# Now onto the body
local $/ = undef;
local $_ = <>;
# Do they not have a signature?
unless( /^-- $/m ) {
$score++;
push @reasons, <<"";
+ You do not have a valid signature line. The 'sig dash' line should separate
the body of the content from the message. It must consist of '-- ' by
itself on the line.
}
# Did they quote someone's signature?
if( /^>.*-- $/m or /^>.*---?$/m ) {
$score+=3;
push @reasons, <<"";
+ You have quoted someone else's signature. Please trim the unnecessary
text appropriately from your reply.
}
# Get rid of their signature, if there is one. Also trim blank lines
s/\n-- \n.*$//s;
s/\n\n//s;
# How much quoted versus how much new text?
my $oldcount = () = /^>/mg;
my $newcount = () = /^[^>]/mg;
if( $newcount <= 1 ) {
$score += 4;
push @reasons, <<"";
+ You included very little original content. So what did you have to say?
There were $newcount new lines, but you quoted $oldcount lines from
the previous mail.
} elsif( $oldcount > 2 * $newcount ) {
$score += 3;
push @reasons, <<"";
+ You included $oldcount lines of a previous message, but only
wrote $newcount lines. That indicates that you're not really
thinking about to what you are replying and just including the
while thing.
}
# Check for no quoted context
if( $oldcount == 0 and $headers->get( 'In-Reply-To' ) ) {
$score++;
push @reasons, <<"";
+ You did not include any context from the previous message. How
will anyone know to what you are replying?
}
# Did they include just some at the top and then include the entire
# post at the bottom?
#
# I don't like this code. Perhaps I should rewrite it.
#
my $unquoted = 1;
my @lines = split /\n/;
while( @lines ) {
local $_ = shift @lines;
last if /^>/;
}
# Preload it incase we ran out of lines
@lines = ( ">foo", "bar", "baz" ) unless @lines;
while( @lines ) {
local $_ = shift @lines;
last if /^[^>]/;
}
unless( @lines ) {
$score += 3;
print "found no lines after quoting\n";
push @reasons, <<"";
+ You wrote all of your content at the top of the message and then ignored
the original post. That is not conversational style and is considered
very rude by most every experienced user.
}
#### TODO:
# Did they include several lines over 72 characters?
#################
#
# Now print out the score and why, if they have many transgressions
#
if( $check ) {
print "Sending to: $replyto\n";
print "Subject: Bogoscore $score: Re $subject\n";
print "\n$_" for @reasons;
}
exit if $check and not $force;
exit if $score < $threshold and not $force;
my $msg = new Mail::Send(
Subject => "Bogoscore $score: Re $subject",
To => $replyto,
);
$msg->cc( $user );
$msg->set( 'X-Automated-Flame:' => 'Yes' );
my $fh = $msg->open;
print $fh "\n$_" for @reasons;
print $fh <<END_OF_MAIL;
------------------
If you have any questions about this program, please contact the
sender of this message. Include this version string in your mail:
$cvs_id
END_OF_MAIL
$fh->close;
print "Mail sent to '$replyto'\n";
__END__
--
o hudson@swcp.com hudson@turbolabs.com O___|
/|\ http://www.swcp.com/~hudson/ H 505.323.38.81 /\ \_
<< KC5RNF @ N5YYF.NM.AMPR.ORG W 505.986.60.75 \ \/\_\
0 U \_ |
------------------------------
Date: Mon, 12 Feb 2001 20:49:03 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: How bad is that Jeopardy post?
Message-Id: <3A88BCBF.F92318D4@stomp.stomp.tokyo>
Tramm Hudson wrote:
(various snippage)
> Did you ever yearn for a ranking scale that would
> allow to you kill posts based on the absurdity of
> the arguments?
If I were one of those who uses a killfile,
you would certainly reside in my killfile.
> my cow-orkers practice these henious crimes,
You are posting to the wrong newsgroup.
Try this group:
alt.bestility.for.idiots
Godzilla!
------------------------------
Date: 13 Feb 2001 07:57:58 GMT
From: vek@pharmnl.ohout.pharmapartners.nl (Villy Kruse)
Subject: Re: How bad is that Jeopardy post?
Message-Id: <slrn98hq7o.ns9.vek@pharmnl.ohout.pharmapartners.nl>
On 13 Feb 2001 04:00:11 GMT, Tramm Hudson <hudson@swcp.com> wrote:
>Ever wondered exactly how bad was that post asking how to parse
>HTML with a regular expression? Did you ever yearn for a ranking
>scale that would allow to you kill posts based on the absurdity of
>the arguments?
>
The problem is nore that the entire post that is responded to is
quoted in full, and the answer isn't given in context.
In the good old days you were not allowed by the software to post
message where there is more quoted text than new text.
Villy
------------------------------
Date: Mon, 12 Feb 2001 21:53:33 -0800
From: "Scott Williams" <jscottwilliams@excite.com>
Subject: Locking really large file
Message-Id: <96ai0g$nij$1@news.phone.com>
I'm trying to use flock to get an exclusive lock on a
large (7.8 gig) file. When using open() or sysopen(),
the command fails with:
> can't open "/u1/largefile": Value too large for
> defined data type
Is the "defined data type" actually the file handle?
Any way around this? I simply need to lock a bunch
of files temporarily so another process does not write
to them, and then unlock them.
Thanks.
-- Scott
------------------------------
Date: Tue, 13 Feb 2001 05:00:24 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: Looking For A Good Sockets Tutorial
Message-Id: <3a88bf68.1f26$1f9@news.op.net>
In article <3A888418.585FA531@yahoo.com>,
Jeffry A. Nokes <jeff_nokes@yahoo.com> wrote:
>Greetings,
>Anyone know a good link(s) or book(s) that have a very laymens tutorial
>on socket/network programming in Perl? I would really like to start
>with understanding the lower layers of what a socket connection is, and
>then get into the API.
http://www.bookpool.com/.x/z9r2y3mew0/sm/0201615711
--
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print
------------------------------
Date: Tue, 13 Feb 2001 06:21:45 GMT
From: "Sean" <sean@tnq.com>
Subject: measuring sizeof of STDIN
Message-Id: <Zn4i6.17625$lI2.19423@news1.rochd1.qld.optushome.com.au>
When I do something like:
cat test.msg | ./perltest.pl
I can manipulate the data using \*STDIN
What is available to me to also find out the size (in bytes) that is being
piped to the perl script?
Thanks
Sean
------------------------------
Date: 13 Feb 2001 02:04:01 -0500
From: Jonathan Feinberg <jdf@pobox.com>
Subject: Re: measuring sizeof of STDIN
Message-Id: <bss7cbdq.fsf@pobox.com>
"Sean" <sean@tnq.com> writes:
> What is available to me to also find out the size (in bytes) that is being
> piped to the perl script?
my $bytes = 0;
while (<STDIN>) {
$bytes += length;
}
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
http://pobox.com/~jdf
------------------------------
Date: Mon, 12 Feb 2001 21:55:56 -0600
From: "Jeff Fletcher" <jeff_fletcher@pacbell.net>
Subject: need help going from UNIX to Windows
Message-Id: <MZ3i6.216$NE2.218622@news.pacbell.net>
I thought I had the hang of Perl when I was using it on my Unix server. I'd
simply write the stuff up on a little text editor, then FTP it into my
cgi-local directory and run it. Piece of cake.
Now that I've switched to a web host that uses Windows, I'm lost. I'm told I
need to make my scripts work on Active Perl v. 5.6. I've spent most of the
day reading about this and I'm totally lost. Here are a few of my major
questions:
1. Most of my scripts are pretty simple, and work with either version of
Perl. In fact they work on my new server when called directly, but when they
are called from an SSI into an HTML page, I get some strange output like
this: HTTP/1.1 200 OK Date: Tue, 13 Feb 2001 05:43:21 GMT Server:
Microsoft-IIS/5.0 Content-type: text/html. Can anyone explain that?
2. This may sound silly, but I don't understand this command line stuff?
I've tried opening an MS-DOS window and typing the commands in there, but
that doesn't work. I've tried opening the perl.exe (recently downloaded)
window, and nothing I type in there seems to do anything. Until I figure
this out, it's a major stumbling block to my doing anything else.
Well, I guess that will be it for now. At least those answers can get me out
of the starting blocks here.
Thanks in advance to anyone who can help.
--------
Jeff Fletcher, Editor
sfbaygolf.com: The online guide to Bay Area golf
jeff@sfbaygolf.com
http://www.sfbaygolf.com
------------------------------
Date: Tue, 13 Feb 2001 02:28:09 -0000
From: "DaveP" <DavePerkins@bigfoot.com>
Subject: Newbie: read & remove last line from a txt file.
Message-Id: <96a62e$bga$1@newsg3.svr.pol.co.uk>
I'm having difficulty devising a simple algorithm that will open a text file
and read (+remove) the last line from the file. Each line is a known fixed
length.
Is there a snippet of code that would do this?
TIA
David
------------------------------
Date: 12 Feb 2001 22:12:36 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Newbie: read & remove last line from a txt file.
Message-Id: <m3k86vjmxn.fsf@mumonkan.sunstarsys.com>
"DaveP" <DavePerkins@bigfoot.com> writes:
> I'm having difficulty devising a simple algorithm that will open a text file
> and read (+remove) the last line from the file. Each line is a known fixed
> length.
>
> Is there a snippet of code that would do this?
Yes- see
% perldoc -q "delete a line"
% perldoc -f open
% perldoc -f readline
% perldoc -f seek
% perldoc -f tell
% perldoc -f truncate
% perldoc -f close
or do it as a one-liner (low score?)
% perl -pi -e 'eof..die$_' filename
This wouldn't be a HW problem now, would it?
Joe Schaefer
--
$.=$[|3*rand;$_=67014523;END{print@_};*UNIVERSAL::AUTOLOAD=sub{&A;pop->();++
$#;*A};$.++,*[=*]=*\=sub{$].=pop.(--$#%2?q: ::qq::)};*#=sub{split m, (?<=^.{2})
(.{$.}),x,shift};@#=qw[just another Perl hacker];*A=*AUTOLOAD=sub{split"::",$A;
&]};map{splice@#,$_,1,&#($#[$_])}3,1;$_="@{[@#[m$.$g]]}";s;P;,p;;eval;$\.="\n"
------------------------------
Date: Tue, 13 Feb 2001 12:54:20 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: Newbie: read & remove last line from a txt file.
Message-Id: <uD1i6.29$nh7.3642@vic.nntp.telstra.net>
"DaveP" <DavePerkins@bigfoot.com> wrote in message
news:96a62e$bga$1@newsg3.svr.pol.co.uk...
> I'm having difficulty devising a simple algorithm that will open a
text file
> and read (+remove) the last line from the file. Each line is a known
fixed
> length.
>
> Is there a snippet of code that would do this?
>
If it is a small file this is one way,
read all the lines into an array, remove the last item from the array,
write the array back to the file.
#!/usr/bin/perl -w
use strict;
open (IN, 'd:/perl/scripts/file.txt') or die "cant $!";
my @lines = <IN>;
close IN;
pop @lines;
open (OUT, '>d:/perl/scripts/newfile.txt') or die "wont $!";
print OUT @lines;
close OUT;
Wyzelli
--
#Modified from the original by Jim Menard
for(reverse(1..100)){$s=($_!=1)? 's':'';print"$_ bottle$s of beer on the
wall,\n";
print"$_ bottle$s of beer,\nTake one down, pass it around,\n";
$_--;$s=($_==1)?'':'s';print"$_ bottle$s of beer on the
wall\n\n";}print'*burp*';
------------------------------
Date: Tue, 13 Feb 2001 07:37:44 GMT
From: Paul <pmckenna@writeme.com>
Subject: Performance question
Message-Id: <3A88E2A3.FB93B497@writeme.com>
I need to parse a very long text file and remove about 25+ different
words as well as punctuation. Words like "a" "the" "of" and so forth.
What I have done is string together a series of ORs like
s/\bthe\b/\bof\b/............ This seems so awkward and I am sure is
very slow. Is there a more elegant and faster way to this kind of
substitution. Thanks
Paul
------------------------------
Date: 13 Feb 2001 01:45:20 -0500
From: Jonathan Feinberg <jdf@pobox.com>
Subject: Re: Problems with ActiveState Perl, please help.
Message-Id: <lmrbcc8v.fsf@pobox.com>
"henroc" <henroc@mindspring.com> writes:
> open (FILENAME, "file.txt"); doesn't open anything
You must ask Perl what is going wrong, by checking the success of the
open() call and reporting on any failures.
open(F, 'file.txt') || die "Can't open file.txt for read: $!\n";
See chapter 10 in _Learning Perl_ for more details about such things.
You should also read in perlfunc about open() and die(). HTH.
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
http://pobox.com/~jdf
------------------------------
Date: Tue, 13 Feb 2001 01:46:43 -0500
From: Michael Anthony <MichaelAnthony@MailAndNews.com>
Subject: Problems with hashes - help
Message-Id: <3A8B13FB@MailAndNews.com>
I want to read a file containing a set of keys and values
as a hash of information.
This file contains a set of named attributes that I intend
to use as a hash.
I want to use the file name
$filename
as the string which is the name of the hash.
And I want to use the various key names as the keys
for the hashes.
When I try to read this file and use the information,
it screws up.
I can parse the filename, and then init the hash with
%$filename = ();
But I can't seem to go the next step of loading the keys
and values into this hash.
Does anybody have a clue ?
Michael
Problems with hashes - help
------------------------------------------------------------
Get your FREE web-based e-mail and newsgroup access at:
http://MailAndNews.com
Create a new mailbox, or access your existing IMAP4 or
POP3 mailbox from anywhere with just a web browser.
------------------------------------------------------------
------------------------------
Date: 13 Feb 2001 02:08:37 -0500
From: Jonathan Feinberg <jdf@pobox.com>
Subject: Re: Problems with hashes - help
Message-Id: <7l2vcb62.fsf@pobox.com>
Michael Anthony <MichaelAnthony@MailAndNews.com> writes:
> I can parse the filename, and then init the hash with
> %$filename = ();
> But I can't seem to go the next step of loading the keys
> and values into this hash.
Most experienced Perl programmers will wince when they see you using a
symbolic reference, as you are doing above. Want you really want is a
hash whose keys are the file name, and whose values are references to
hashes. Like so:
my %files = ();
$files{$filename} = {}; # anonymous hash
$files{$filename}->{property} = $value;
$files{$filename}->{another_prop} = $different_value;
See the perl manuals named perlreftut, perlol, perldsc, and perlref.
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
http://pobox.com/~jdf
------------------------------
Date: Tue, 13 Feb 2001 14:06:55 +1030
From: "Mark Dobos" <mdobos@tpg.com.au>
Subject: require statement on NT 4.0
Message-Id: <3a88ab20@dnews.tpgi.com.au>
I'm running couple cgi scripts which require long list variables.
I have created separate file with variables.
I 'm loading file with statement require "variables.pl";
the app return error " Can't locate variables.pl in @INC (@INC contains:
C:\Perl\lib C:\Perl\site\lib .) at .... "
If I specify path with
BEGIN {
unshift (@INC, "d:/Projects/pmd/perl");
}
the app return error " variables.pl did not return a true value at .... "
Any thoughts appreciated,
Mark
------------------------------
Date: 13 Feb 2001 06:40:39 GMT
From: damian@qimr.edu.au (Damian James)
Subject: Re: require statement on NT 4.0
Message-Id: <slrn98hlmq.lhi.damian@puma.qimr.edu.au>
Thus spake Mark Dobos on Tue, 13 Feb 2001 14:06:55 +1030:
>I'm running couple cgi scripts which require long list variables.
>I have created separate file with variables.
>
>...
>If I specify path with
>BEGIN {
> unshift (@INC, "d:/Projects/pmd/perl");
>}
Better would be to say:
use lib "d:/Projects/pmd/perl";
> the app return error " variables.pl did not return a true value at .... "
>
See the documentation for require (by typing the following from the command
prompt):
perldoc -f require
A Perl module/library/required_thing_of_any_sort needs to return true. Just
putting a 1; at the end of the file accomplishes this. i
You might also want to see:
perldoc perlmod
HTH
Cheers,
Damian
--
$;=ord$%,$:=$;-ord q,.,,$_=q 13346:3366:3276:3326:3386:546:566:966:3396:3376:1.
q 73386:546:;96:3326:3336:3386:3266:3236:3366:546::26:3236:3366:32:6:546:32667.
q,:;96:;;6:3296:3236:3366:326:56,,s,.,;ord($&)-$:-$;;;;;,eg,s,$;,;chr$&-$:;,eg,
eval eval; #requires 5.6.0 ## my first attempt at one of these...
------------------------------
Date: 13 Feb 2001 01:42:01 -0500
From: Jonathan Feinberg <jdf@pobox.com>
Subject: Re: socket problem
Message-Id: <pugnccee.fsf@pobox.com>
Bin - Lu <b0l4549@cs.tamu.edu> writes:
> Anyone has a clue what the problem is?
Perl does. You must check the result of every system call (such as
socket()). If the call fails, Perl sets the variable $! to contain
the appropriate error message.
In the section on sockets in the _perlipc_ document, you'll find the
following lines in the sample code:
$iaddr = inet_aton($remote) || die "no host: $remote";
socket(SOCK, PF_INET, SOCK_STREAM, $proto) || die "socket: $!";
connect(SOCK, $paddr) || die "connect: $!";
close (SOCK) || die "close: $!";
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
http://pobox.com/~jdf
------------------------------
Date: Tue, 13 Feb 2001 02:11:15 GMT
From: mshavel@erols.com (Michael)
Subject: Using split to chop up a flat database file
Message-Id: <9046DCBF8mshavelerolscom@130.9.16.213>
Hi
I want to chop up a database file so that each record is one element in an
array.
Script and file are below. I am getting incorrect results. Results that
come back are as such:
___RESULTS____
Rec1: LAST
Rec2: : Starrr
FIRST:Ringo
SUBJECT:Beatles
LAST
Rec3: :McCartney
FIRST:Paul
SUBJECT:Beatles
LAST
Rec4: :Lennon
FIRST:John
SUBJECT:Beatles
LAST
____ORIGINAL FILE____
LAST: Starrr
FIRST:Ringo
SUBJECT:Beatles
LAST:McCartney
FIRST:Paul
SUBJECT:Beatles
LAST:Lennon
FIRST:John
SUBJECT:Beatles
LAST:Harrison
FIRST:George
SUBJECT:Beatles
_SCRIPT____
#!/usr/bin/perl -w
open(FILE,"testfile");
$/="LAST"; #split recs
@recs = <FILE>;
close(FILE);
$cnt=0;
print "Rec1: $recs[0]\n";
print "Rec2: $recs[1]\n";
print "Rec3: $recs[2]\n";
print "Rec4: $recs[3]\n";
I know I am doing something wrong but I don't see what it is.
Thanks very much for any suggestions
Mike
mshavel@erols.com
------------------------------
Date: 13 Feb 2001 02:00:18 -0500
From: Jonathan Feinberg <jdf@pobox.com>
Subject: Re: Using split to chop up a flat database file
Message-Id: <g0hjcbjx.fsf@pobox.com>
mshavel@erols.com (Michael) writes:
> ____ORIGINAL FILE____
> LAST: Starrr
> FIRST:Ringo
> SUBJECT:Beatles
> LAST:McCartney
[snip]
> $/="LAST"; #split recs
> @recs = <FILE>;
The diamond operator reads until the first occurence of $/ and puts
everything up to and including that $/ into the first element of the
list that gets assigned to @recs. Since there is nothing before the
first $/, the first element of @recs winds up being just $/. The next
element of @recs will be everything from the character immediately
following the last $/ up to and including the next $/.
What you probably want to do is more like
my $top = -1;
while (<FILE>) {
$top++ if /^LAST/;
$recs[$top] .= $_;
}
Although what you REALLY want to do, I'd think, is build a data
structure that gives you more access to the individual fields of each
record, right? Check out the perllol and perldsc documents, and see
if they give you any ideas.
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
http://pobox.com/~jdf
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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.
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 V10 Issue 279
**************************************