[16604] in Perl-Users-Digest
Perl-Users Digest, Issue: 4016 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Aug 14 21:10:37 2000
Date: Mon, 14 Aug 2000 18:10:17 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <966301816-v9-i4016@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Mon, 14 Aug 2000 Volume: 9 Number: 4016
Today's topics:
Re: print problem (Logan Shaw)
Re: print problem (Logan Shaw)
Re: print problem <lr@hpl.hp.com>
Re: print problem (Logan Shaw)
Re: Procmail vs Perl. (Alex Graf)
push (@INC dschl@my-deja.com
Re: push (@INC <red_orc@my-deja.com>
Re: push (@INC <red_orc@my-deja.com>
Re: push (@INC <matthew.keeneNOmaSPAM@colesmyer.com.au.invalid>
Re: rand() not random at all <x@x.com>
redirect location frames help <jjb13@NOSPAMaxe.humboldt.edu>
sample terminal game for newbie <spetey@umich.edu>
Socket hang, any ideas??? krpotter@co.douglas.or.us
Subroutine being redefined in module <glchyNOglSPAM@email.com.invalid>
Updating flat text file problem <musicfan@punitiveart.com>
Re: what the heck is C<$_> ?? (Decklin Foster)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 14 Aug 2000 17:14:49 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: print problem
Message-Id: <8n9r0p$3tc$1@provolone.cs.utexas.edu>
In article <MPG.1401e3ff7539a7c98ac76@nntp.hpl.hp.com>,
Larry Rosler <lr@hpl.hp.com> wrote:
>In article <8n9d9e$307$1@provolone.cs.utexas.edu> on 14 Aug 2000
>13:20:30 -0500, Logan Shaw <logan@cs.utexas.edu> says...
>>
>> # save the read position, move to the write position.
>> $readpos = tell (FOO);
>> seek (FOO, $writepos, 0);
>>
>> syswrite (FOO, $char, 1);
>>
>> # save the write position, move to the read position.
>> $writepos = tell (FOO);
>> seek (FOO, $readpos, 0);
>
>The seeks undo the effects of buffering and facilitate the alternations
>between input and output. The number of characters written should be
>the same as the number read, or hell is likely to break loose.
s/the same as/less than or equal to/;
Or, even better, $writepos plus the length of whatever you're writing
should be less than $readpos whenever syswrite() is called.
It wouldn't even be difficult to write a module that allows one to
easily sequentially modify a file like this. If the caller tries to
write forward of the current read position, the module could simply
buffer the data that won't yet fit and write as much as possible on the
subsequent calls to the write method or in the destructor if
necessary.
You can even safely mix these writes with normal stdio buffered
reads[1]: since you're reading the file in sequential order, the only
part of the buffered data that the reads will pay attention to is the
part you aren't yet writing to.
Gosh, I think I've got an idea for a module. I don't know if anyone
would necessarily ever use it, but it'd be fun to write. (And just
think -- once this module is written, you can easily do bubblesorts on
100 GB files with fixed length records. Yippie!)
Now, the only question I have is whether anyone has any idea how I can
truncate an already-open file at the current position. The only way I
can think of right now is to remember the current position, close the
file, open the file again in the correct mode, seek to that position,
seek backward one byte, read that byte, seek back one byte again,
re-write the byte over itself, and then close the file. (Oh yeah, and
also handle the special case of the file being empty.)
Needless to say, that doesn't sound too great to me. I already looked
at the open() documentation, and it seems that re-open()ing a file
(like "open(BAR, '<&FOO')") won't change the mode that it's open in.
That makes sense, since you're really just doing some sort of dup().
There doesn't seem to be a truncate() either.
- Logan
[1] As long it doesn't hurt stdio's buffered reads if you do a
seek() and then put put the file pointer back where it orignally
was. Which it shouldn't, since tell() and seek() are ultimately
system calls, so stdio doesn't know that they're happening.
------------------------------
Date: 14 Aug 2000 17:20:19 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: print problem
Message-Id: <8n9rb3$3uh$1@provolone.cs.utexas.edu>
In article <slrn8pghr1.tj3.abigail@alexandra.foad.org>,
Abigail <abigail@foad.org> wrote:
>Logan Shaw (logan@cs.utexas.edu) wrote on MMDXL September MCMXCIII in
><URL:news:8n9d9e$307$1@provolone.cs.utexas.edu>:
>-: In article <slrn8pgcc8.tj3.abigail@alexandra.foad.org>,
>-: Abigail <abigail@foad.org> wrote:
>-:
>-: >it still is generally a very bad idea.
>-:
>-: It can still be useful
>
>Well, yes. I didn't idly write "generally".
Fair enough. I was just trying to demonstrate that, while it isn't
done very often, that doesn't mean that it can't be done or even that
it is particularly difficult to do.
Also, I was being contrarian, I admit it.
> Furthermore, the example you
>give uses sysread (reading one char at the time) and seek, not buffered
>IO with <>, as the discussed program.
Yes, but that's just because it makes it easier to write the loop I
wrote -- syswrite can't do a partial write if you're only trying to
write one character. :-) Anyway, as I mentioned in another article,
there's no reason you can't mix buffered reads with unbuffered writes
if you're always writing to a region of the file that's closer to the
beginning than where you're reading from. But even that's not quite
the same as what the original poster was trying to do.
- Logan
------------------------------
Date: Mon, 14 Aug 2000 15:46:12 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: print problem
Message-Id: <MPG.1402169193d962b198ac79@nntp.hpl.hp.com>
In article <8n9r0p$3tc$1@provolone.cs.utexas.edu> on 14 Aug 2000
17:14:49 -0500, Logan Shaw <logan@cs.utexas.edu> says...
...
> Now, the only question I have is whether anyone has any idea how I can
> truncate an already-open file at the current position. The only way I
> can think of right now is to remember the current position, close the
> file, open the file again in the correct mode, seek to that position,
> seek backward one byte, read that byte, seek back one byte again,
> re-write the byte over itself, and then close the file. (Oh yeah, and
> also handle the special case of the file being empty.)
Ugh.
> Needless to say, that doesn't sound too great to me. I already looked
> at the open() documentation, and it seems that re-open()ing a file
> (like "open(BAR, '<&FOO')") won't change the mode that it's open in.
> That makes sense, since you're really just doing some sort of dup().
> There doesn't seem to be a truncate() either.
Really? Then why does
perldoc -f truncate
tell me all about it?
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 14 Aug 2000 18:01:15 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: print problem
Message-Id: <8n9tnr$45t$1@provolone.cs.utexas.edu>
In article <MPG.1402169193d962b198ac79@nntp.hpl.hp.com>,
Larry Rosler <lr@hpl.hp.com> wrote:
>In article <8n9r0p$3tc$1@provolone.cs.utexas.edu> on 14 Aug 2000
>17:14:49 -0500, Logan Shaw <logan@cs.utexas.edu> says...
>Really? Then why does
>
> perldoc -f truncate
>
>tell me all about it?
Doh. I must've typed "perldoc -q truncate" or something by mistake,
because I swear I looked twice to make sure it didn't exist.
- Logan
------------------------------
Date: Mon, 14 Aug 2000 22:13:45 GMT
From: alex.graf@.....ec.gc.ca (Alex Graf)
Subject: Re: Procmail vs Perl.
Message-Id: <39986ea1.264167013@morgoth.sfu.ca>
I think Mail::Header groks rfc822 messages
On Tue, 15 Aug 2000 00:00:23 +0200, tony@svanstrom.com (Tony L.
Svanstrom) wrote:
>I've now started working on a Perl-based solution; so far I've only got
>a few lines that split up the headers and separate them from the body,
------------------------------
Date: Mon, 14 Aug 2000 21:58:07 GMT
From: dschl@my-deja.com
Subject: push (@INC
Message-Id: <8n9q1c$kqu$1@nnrp1.deja.com>
Why doesn't push(@INC,...) work?
My source file contains these lines:
BEGIN{
push(@INC, '/var/ns-home/cgi-bin');
use qqemail;
}
When run, I get the error:
Can't locate qqemail.pm in @INC (@INC contains:
/usr/local/lib/perl5/5.00503/sun
4-solaris /usr/local/lib/perl5/5.00503
/usr/local/lib/perl5/site_perl/5.005/sun4
-solaris /usr/local/lib/perl5/site_perl/5.005 .) at
/var/ns-home/cgi-bin/tools/IsAppRecd.pl line 25.
BEGIN failed--compilation aborted at
/var/ns-home/cgi-bin/tools/IsAppRecd.pl line 25.
Obviously the "push" failed. What's up?
-Dave
DGS Consulting
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Mon, 14 Aug 2000 22:13:18 GMT
From: Rodney Engdahl <red_orc@my-deja.com>
Subject: Re: push (@INC
Message-Id: <8n9qtq$lch$1@nnrp1.deja.com>
In article <8n9q1c$kqu$1@nnrp1.deja.com>,
dschl@my-deja.com wrote:
> Why doesn't push(@INC,...) work?
>
> My source file contains these lines:
>
> BEGIN{
> push(@INC, '/var/ns-home/cgi-bin');
^^^ this happens at "run" time, after the BEGIN block has executed. ^^^
> use qqemail;
^^^ this effectively happens in the BEGIN block ^^^
> }
>
> When run, I get the error:
> Can't locate qqemail.pm in @INC (@INC contains:
> /usr/local/lib/perl5/5.00503/sun
> 4-solaris /usr/local/lib/perl5/5.00503
> /usr/local/lib/perl5/site_perl/5.005/sun4
> -solaris /usr/local/lib/perl5/site_perl/5.005 .) at
> /var/ns-home/cgi-bin/tools/IsAppRecd.pl line 25.
> BEGIN failed--compilation aborted at
> /var/ns-home/cgi-bin/tools/IsAppRecd.pl line 25.
>
> Obviously the "push" failed. What's up?
>
by the time you pushed onto @INC, your 'use' had already been operated
on.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Mon, 14 Aug 2000 22:16:24 GMT
From: Rodney Engdahl <red_orc@my-deja.com>
Subject: Re: push (@INC
Message-Id: <8n9r3k$lmc$1@nnrp1.deja.com>
In article <8n9qtq$lch$1@nnrp1.deja.com>,
Rodney Engdahl <red_orc@my-deja.com> wrote:
> In article <8n9q1c$kqu$1@nnrp1.deja.com>,
> dschl@my-deja.com wrote:
> > Why doesn't push(@INC,...) work?
> >
> > My source file contains these lines:
> >
> > BEGIN{
> > push(@INC, '/var/ns-home/cgi-bin');
>
> ^^^ this happens at "run" time, after the BEGIN block has executed.
^^^
oops, like an idiot, i didn't even see the BEGIN around the whole block.
ick! I hate that. Please ignore the less than totally factual attempt
at an explanation. 5 full demerits, and back to the shadows to lurk
some more until I learn some more.
>
> > use qqemail;
>
> ^^^ this effectively happens in the BEGIN block ^^^
>
> > }
> >
> > When run, I get the error:
> > Can't locate qqemail.pm in @INC (@INC contains:
> > /usr/local/lib/perl5/5.00503/sun
> > 4-solaris /usr/local/lib/perl5/5.00503
> > /usr/local/lib/perl5/site_perl/5.005/sun4
> > -solaris /usr/local/lib/perl5/site_perl/5.005 .) at
> > /var/ns-home/cgi-bin/tools/IsAppRecd.pl line 25.
> > BEGIN failed--compilation aborted at
> > /var/ns-home/cgi-bin/tools/IsAppRecd.pl line 25.
> >
> > Obviously the "push" failed. What's up?
> >
>
> by the time you pushed onto @INC, your 'use' had already been operated
> on.
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>
--
Some drink at the fountain of knowledge...others just gargle.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Mon, 14 Aug 2000 16:32:30 -0700
From: Matthew Keene <matthew.keeneNOmaSPAM@colesmyer.com.au.invalid>
Subject: Re: push (@INC
Message-Id: <12b3449d.f39b1ad3@usw-ex0105-034.remarq.com>
Wouldn't you be better off using the use lib pragma ?
use lib '/var/ns-home/cgi-bin' ;
use qqemail ;
There's a whole section on manipulating @INC in the docs, type
perldoc lib to see it.
-----------------------------------------------------------
Got questions? Get answers over the phone at Keen.com.
Up to 100 minutes free!
http://www.keen.com
------------------------------
Date: Mon, 14 Aug 2000 23:16:07 GMT
From: x <x@x.com>
Subject: Re: rand() not random at all
Message-Id: <bqzMNiwZtefN=NRfZ1yRVxN+v5jD@4ax.com>
Hi,
srand( time ^ ($$ + ($$ << 15)) );
Regards.
On Mon, 14 Aug 2000 15:17:13 +0300, Jonne Viljanen
<Jonne.Viljanen@helsinki.fi> wrote:
>I'm trying to get a simple random number to specify a filename, but
>whenever the script is run, I always get the same "random" number
>(AUG3VRM6) as an output. What could be wrong?
------------------------------
Date: Mon, 14 Aug 2000 15:23:34 -0700
From: "Torch" <jjb13@NOSPAMaxe.humboldt.edu>
Subject: redirect location frames help
Message-Id: <8n9sq7$1a9n$1@hades.csu.net>
Ok I'm new at perl so don't hate me. I searched remarq and could not find an
answer to this question.
I'm trying to redirect to a page using
print "Location: URL\n\n";
The problem I'm having is: I'm trying to run a script from a frame. When it
goes to that URL it puts it in that frame. how do I get it on _top? I can't
not put it in a frame either.
Thank you
--
Torch
Remove NOSPAM to reply
------------------------------
Date: Mon, 14 Aug 2000 18:14:30 -0400
From: Steve Petersen <spetey@umich.edu>
Subject: sample terminal game for newbie
Message-Id: <39986F46.B9B9E5DF@umich.edu>
Hey folks,
I'm hoping to learn Perl and work up a terminal game at the same time.
I've been through the llama book and I'd like to try a real program.
Can anyone recommend a good GPL'd terminal game in Perl (along the lines
of the BSD "mille" version of mille bourne, say) to get me started?
Thanks,
Steve
------------------------------
Date: Mon, 14 Aug 2000 23:05:42 GMT
From: krpotter@co.douglas.or.us
Subject: Socket hang, any ideas???
Message-Id: <8n9u02$nvr$1@nnrp1.deja.com>
Hello,
Any help/thoughts on this issue would be greatly appreciated....!!
I have a unix socket server program (AIX) that waits for socket
connections from various clients (other AIX boxes), receives data from
them, processes it, and then waits for the next connection. For years
this has been working fine, but now I have added a socket connection
from a Windows NT box using perl, and I'm encountering problems.
For some reason, my host server program becomes hung (usually in the
middle of the night!). It appears to be sitting on the "select"
statement, waiting for a new connection to come in, but any new
connections simply get rejected when they try to communicate with it.
If I cancel the hostserver, and restart, i get the "address already in
use error". I've tried adding a SO_REUSEADDR at the host, but this
still does not let him bind after the failure.
Anyway, here is the perl code that is now being used on the windows/nt
box to connect to the server. It was created from one of the samples
in the cookbook, or from a perl sample. Since the problem just started
with the advent of this connection, there must be something in here
that is interjecting the problem:
##################################
# Setup
##################################
$port = 3333;
$them = 'myhost.mydomain.com';
chop($us = `hostname`);
$sockaddr = 'S n a4 x8';
$AF_INET = 2;
$SOCK_STREAM = 1;
$proto = 6;
##################################
# Resolve IP Addresses
##################################
($name,$aliases,$type,$len,$thisaddr) = gethostbyname($us);
($name,$aliases,$type,$len,$thataddr) = gethostbyname($them);
##################################
# Build TCP/IP Socket Structure
##################################
$this = pack($sockaddr, $AF_INET, 0,$thisaddr);
$that = pack($sockaddr, $AF_INET, $port, $thataddr);
################################################
# Socket, Bind, Connect, Send, Close
################################################
if (! socket(S, $AF_INET, $SOCK_STREAM, $proto))
{
print "ERROR 1\n";
goto RETURN;
}
if (! bind(S, $this))
{
print "ERROR 2\n";
goto RETURN;
}
if (! connect(S,$that))
{
print "ERROR 3\n";
goto RETURN;
}
if (send(S, $msg, 0) < 1) {
print "ERROR4\n";
goto RETURN;
}
close(S);
Thanks for any help or ideas to try!!!
-Kevin-
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Mon, 14 Aug 2000 15:28:12 -0700
From: G <glchyNOglSPAM@email.com.invalid>
Subject: Subroutine being redefined in module
Message-Id: <0553dbc2.25edbb70@usw-ex0107-055.remarq.com>
Hi,
Im getting "Subroutine signoff_html redefined at Validation.pm
line 173" when i do a # perl -wc Validation.pm but the syntax is
OK. Using Perl version 5.005_03 built for i386-linux.
Using diagnostics, i get:
(W) You redefined a subroutine. To suppress this warning,
say
{
local $^W = 0;
eval "sub name { ... }";
}
Just wondering what did that mean and also whether it was ok to
ignore that message....
Thanks,
GC.
-----------------------------------------------------------
Got questions? Get answers over the phone at Keen.com.
Up to 100 minutes free!
http://www.keen.com
------------------------------
Date: Mon, 14 Aug 2000 16:59:46 -0700
From: musicfan <musicfan@punitiveart.com>
Subject: Updating flat text file problem
Message-Id: <1h1hps08vdg1sjjd143sh1glh3hjmuofk8@4ax.com>
I'm trying to update a text file and having some troubles with it.
The error I get in the debugger is:
invalid type in pack: '1' at line 22
This is the code:
#!/usr/bin/perl
############
#edit the line: print "Location: http://localhost/default.asp\n\n";
#to change the location user is sent to
############
$people_log = '/Inetpub/Scripts/people.db';
$txt_file = "/Inetpub/wwwroot/default.asp";
$typedef = 'L A12 A16';
$sizeof = length(pack($typedef, ()));
$newclick = '1';
#update db
#need to rewrite: grab username from form, find that username and
change the 0 to 1 in Field3
open (UPDATE, "+<$people_log")
or die "can't update people.db: $!";
seek(UPDATE, $FORM{'username'}, SEEK_SET)
or die "seek failed: $!";
read(UPDATE, $buffer, $sizeof) == $sizeof
or die "read failed: $!";
($username, $password, $clickthrough) = unpack($typedef, $buffer);
$clickthrough = 1;
$buffer = pack($username, $password, $clickthrough);
seek(UPDATE, -$sizeof, SEEK_CUR) # backup one record
or die "seek failed: $!";
print UPDATE $record;
close(UPDATE)
or die "close failed: $!";
{
#redir once updated
print "Location: http://localhost/default.asp\n\n";
}
exit;
sub open_error
{
local ($errorname) = @_;
print "Content-Type: text/html\n\n";
exit;
}
------------------------------
Date: Mon, 14 Aug 2000 23:18:55 GMT
From: decklin+usenet@red-bean.com (Decklin Foster)
Subject: Re: what the heck is C<$_> ??
Message-Id: <z7%l5.19517$f_5.91278@news1.rdc1.ct.home.com>
John Stanley <stanley@skyking.OCE.ORST.EDU> writes:
> It's called "pod". It's "Yet Another Markup Language". People who want
> to impress you with their knowledge of perl will use such "markup" in
> their postings to this group, just to make reading what they have to say
> much harder than it has to be. They tend to leave out the necessary
> parts that would allow you to actually pass the message through the
> parser and see what the message is, however.
>
> And they are usually the same ones who object vociferously to the
> appearance of HTML in any posting.
*plonk*
--
There is no TRUTH. There is no REALITY. There is no CONSISTENCY. There
are no ABSOLUTE STATEMENTS. I'm very probably wrong. -- BSD fortune(6)
------------------------------
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 V9 Issue 4016
**************************************