[22879] in Perl-Users-Digest
Perl-Users Digest, Issue: 5100 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jun 10 00:05:56 2003
Date: Mon, 9 Jun 2003 21:05:08 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 9 Jun 2003 Volume: 10 Number: 5100
Today's topics:
Re: an alias for multiple 'use's <ben.goldberg@hotpop.com>
Re: Building Threaded List of Newsgroup Headers <ben.goldberg@hotpop.com>
Can't use string ("Informix") as a HASH ref while "stri (Chavan Koya)
Re: Can't use string ("Informix") as a HASH ref while " (Tad McClellan)
Re: Cannot modify integer negation (-) in predecrement <michael.p.broida@boeing.com>
Re: Forcing perl into background <ian@WINDOZEdigiserv.net>
Re: How to I arrange for a socket connection to time ou <gmiller@NOTforSPAM.gregmiller.net>
Re: How to I arrange for a socket connection to time ou (John Brock)
Re: How to I arrange for a socket connection to time ou <ben.goldberg@hotpop.com>
Re: How to I arrange for a socket connection to time ou <ben.goldberg@hotpop.com>
Re: Perl CGI and Downloading Files - How? <flavell@mail.cern.ch>
Re: Perl CGI and Downloading Files - How? 10ghz@radiate.com
Re: Posting to an asp form with hidden fields (Malcolm Dew-Jones)
Probelm with PERL and Informix Can't use string ("Infor (Chavan Koya)
Re: Probelm with PERL and Informix Can't use string ("I (Tad McClellan)
Re: Quick question (Tad McClellan)
Re: SORT sort hash with alpha-numeric keys <ben.goldberg@hotpop.com>
Sorting and formatting (slash)
Re: Sorting and formatting <noreply@gunnar.cc>
Re: Strange errors with huge hash <ben.goldberg@hotpop.com>
Re: Strange errors with huge hash <ben.goldberg@hotpop.com>
Re: Strange errors with huge hash (Michael G.)
Re: Using ParseRecur from Date::Manip <kha@rogers.com>
Weird mod_perl and CGI::Application behavior <devnull@mail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 09 Jun 2003 20:27:22 -0400
From: Benjamin Goldberg <ben.goldberg@hotpop.com>
Subject: Re: an alias for multiple 'use's
Message-Id: <3EE525EA.EF10DE75@hotpop.com>
Nate Blaylock wrote:
>
> Hi all,
>
> Is it possible to do this?
>
> In just about every package & program I write, I use a bunch of the
> same stuff, some perl modules and some of my own:
>
> use Carp;
> use Storable;
> ...
>
> use MyStuff::Bob;
> use MyStuff::Joe;
> ...
>
> I would like to be able to shortcut all of that and do something like
> use a single package which would be equivalent to doing the long
> version above. E.g.,
>
> use MyStuff::BasicUses;
>
> I tried writing an import sub in MyStuff::BasicUses which makes the
> uses calls above, but that doesn't seem to work.
>
> Is there anything else I can try?
package MyStuff::BasicUses;
my @the_modules = qw(
Carp
Storable
MyStuff::Bob
MyStuff::Joe
);
eval join(";\n", (map "require $_", @the_modules), 1)
or die $@;
my @can_import = grep
UNIVERSAL::can($_, "import") || UNIVERSAL::can($_, "AUTOLOAD"),
@the_modules;
sub import {
my ($pack, $file, $line) = caller();
eval <<"IMPORTSTUFF" or die $@;
package $pack;
#line $line "\Q$file\E"
\$_->import for \@can_import;
1;
IMPORTSTUFF
}
1;
__END__
[untested]
--
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}
------------------------------
Date: Mon, 09 Jun 2003 23:08:38 -0400
From: Benjamin Goldberg <ben.goldberg@hotpop.com>
Subject: Re: Building Threaded List of Newsgroup Headers
Message-Id: <3EE54BB6.175A78CE@hotpop.com>
cp wrote:
[snip]
> foreach (sort keys %$msg ) {
> my( $id, $message, @moms ) = prep_message( $msg->{ $_ } );
> # @moms hold the references to previous messages
> if ( @moms ) {
> # if there are moms, we walk the message list
> my $child = $msg_list->{ shift @moms }{kids};
> while ( @moms ) {
> $child = $child-> { shift @moms }{kids}
> }
> $child->{ $id } = $message;
> }
> else {
> # We are the mom if there are no other mothers
> $msg_list->{ $id } = $message;
> }
> }
Unless *all* your messages that are referred to are still in existance
(they might not be, due to them expiring), there's a good chance that
$child at some point will become undef, and your program will die.
I would suggest that the inside of that if() block become:
my $child = \$msg_list->{ shift @moms }{kids};
while ( @moms ) {
$child = \$$child-> { shift @moms }{kids}
}
$$child->{ $id } = $message;
Or, possibly:
my $child = \$msg_list;
$child = \$$child->{$_}{kids} for @moms;
$$child->{$id} = $message;
Note that if you do it this way, the if() block can be removed, as
it's no longer serving any purpose.
--
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}
------------------------------
Date: 9 Jun 2003 16:09:31 -0700
From: chavankoya189@hotmail.com (Chavan Koya)
Subject: Can't use string ("Informix") as a HASH ref while "strict refs" in use at /opt/perl5/lib/site_perl/5.8.0/PA-RISC2.0-LP64/DBD/Informix.pm line 146.
Message-Id: <ef72e276.0306091509.6f0ce00b@posting.google.com>
Hi All,
I am getting a error message when i call a perl program from
a shell script. We have no problem with older version. but we are
upgrading and doing server consolidation (i.e right now there is one
production box this has old version of perl and we installed new
version on new production box )I no nothing about PERL. Please give me
some suggestions on this problem
Here is the message
some_variable=ct_return = Can't use string ("Informix") as a HASH ref
while "strict refs" in use at
/opt/perl5/lib/site_perl/5.8.0/PA-RISC2.0-LP64/DBD/Informix.pm line
146.
file_ld.sh: exit status = 255
Below is the line number
# Preset AutoCommit mode on $dbh.
$dbattr = { AutoCommit => 1 } if (!defined $dbattr);
#145
${$dbattr}{AutoCommit} = 1 if (!defined ${$dbattr}{AutoCommit});
#146
DBD::Informix::db::preset($dbh, $dbattr);
#147
This is the message and The OS is HP-UX 11.11 (64 bit ver).
Any suggestions comments or changes are greatly appreciated and thanks
in advance.
Chavan Koya
------------------------------
Date: Mon, 9 Jun 2003 19:08:17 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Can't use string ("Informix") as a HASH ref while "strict refs" in use at /opt/perl5/lib/site_perl/5.8.0/PA-RISC2.0-LP64/DBD/Informix.pm line 146.
Message-Id: <slrnbea8bh.hoe.tadmc@magna.augustmail.com>
Chavan Koya <chavankoya189@hotmail.com> wrote:
> we are
> upgrading and doing server consolidation
> I no nothing about PERL.
> Any suggestions comments or changes are greatly appreciated
Change who is responsible for porting the Perl programs to
someone who knows Perl.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 10 Jun 2003 00:37:03 GMT
From: "Michael P. Broida" <michael.p.broida@boeing.com>
Subject: Re: Cannot modify integer negation (-) in predecrement (--)
Message-Id: <3EE5282F.9366A6D2@boeing.com>
Go Perl wrote:
>
> I am using the following code for which i am getting the error
> mentioned in the subject
>
> #counting the number of lines in observed volume file
> open(FILE, "<$filename");
> $lines=@myarray = <FILE>
> close(FILE);
> I am using active state perl on win32. This code worked fine on my
> windows nt whereas on win xp its not working . I used the other ways
> to count lines using while loop and increment or suing syread buffer
> method. all these methods are giving me the same problem.
> Any solutions please.
Others have addressed the problem contained IN your post.
I'm just curious what kinda connection THAT problem has with
the one stated in the Subject line of your post. Your example
doesn't do ANY kind of "integer negation" or "predecrement".
So, what's the connection?
Mike
------------------------------
Date: Mon, 09 Jun 2003 23:17:37 GMT
From: "Ian.H [dS]" <ian@WINDOZEdigiserv.net>
Subject: Re: Forcing perl into background
Message-Id: <l95aev4pur9qprbahruleveho01r0fulo1@4ax.com>
Keywords: Remove WINDOZE to reply
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
Whilst lounging around on Mon, 09 Jun 2003 22:34:07 +0100, Graham
Drabble <graham.drabble@lineone.net> amazingly managed to produce the
following with their Etch-A-Sketch:
> On 09 Jun 2003 "Ian.H [dS]" <ian@WINDOZEdigiserv.net> wrote in
> news:hct9ev0lvqqh6hgbldsh1i8clgectadidf@4ax.com:
>
> > [tk@morris:~]$ wperl
> > bash: wperl: command not found
> >
> >
> >
> > wperl is a windoze only binary.
>
> Ah sorry about that, didn't realise.
No probs.
FWIW, your answer is a perfectly working solution for a windoze box
(my MRTG runs using wperl for example).. but you know that already =)
On Unix, 99% of the time, I just append the & char and it performs
the same task as wperl =)
Regards,
Ian
-----BEGIN xxx SIGNATURE-----
Version: PGP 8.0
iQA/AwUBPuUVjGfqtj251CDhEQItCwCbBuCNNN/xfQuwA/uMaEXY9HrLLWwAoKzb
F4w8k383B7L6lVi7nz7k7LmS
=gD43
-----END PGP SIGNATURE-----
--
Ian.H [Design & Development]
digiServ Network - Web solutions
www.digiserv.net | irc.digiserv.net | forum.digiserv.net
Programming, Web design, development & hosting.
------------------------------
Date: Mon, 09 Jun 2003 23:26:08 GMT
From: Greg Miller <gmiller@NOTforSPAM.gregmiller.net>
Subject: Re: How to I arrange for a socket connection to time out?
Message-Id: <sk5aev8v88b5qk13qdvh4js32feva94q6r@4ax.com>
On 9 Jun 2003 11:29:05 -0400, jbrock@panix.com (John Brock) wrote:
>So to get back to my question, what is the proper way to code a
>client in Perl so that it will time out a socket connection if the
>server does not respond quickly enough?
IO::Select is one way. I've never had a problem using read()
and using select() at the same time, but I have run into several cases
where a < > screwed up everything else, so now I never use < > on
sockets. Just do as you said and read one character at a time, it may
look inefficient, but that's basically all it's doing underneath.
Another method is to use non-blocking IO and continue to do a
read() and a sleep() in a loop. This is less efficient, but works.
Greg Miller (gmiller at gregmiller dot net)
http://www.gregmiller.net
http://www.net-chess.com
------------------------------
Date: 9 Jun 2003 19:47:12 -0400
From: jbrock@panix.com (John Brock)
Subject: Re: How to I arrange for a socket connection to time out?
Message-Id: <bc36a0$cuq$1@panix1.panix.com>
In article <sk5aev8v88b5qk13qdvh4js32feva94q6r@4ax.com>,
Greg Miller <gmiller@NOTforSPAM.gregmiller.net> wrote:
>On 9 Jun 2003 11:29:05 -0400, jbrock@panix.com (John Brock) wrote:
>>So to get back to my question, what is the proper way to code a
>>client in Perl so that it will time out a socket connection if the
>>server does not respond quickly enough?
> IO::Select is one way. I've never had a problem using read()
>and using select() at the same time, but I have run into several cases
>where a < > screwed up everything else, so now I never use < > on
>sockets. Just do as you said and read one character at a time, it may
>look inefficient, but that's basically all it's doing underneath.
> Another method is to use non-blocking IO and continue to do a
>read() and a sleep() in a loop. This is less efficient, but works.
I think it was the <>. I replaced it with sysread() in a loop and
it worked fine, even though I was using read() elsewhere. I was
also using send() to write to the server, and to be consistent I
tried replacing it with syswrite(), but this was very flaky, working
sometimes and other times not.
What I ended up doing was using the send() and recv() methods of
IO::Socket for all socket communication, and using the can_read()
method of IO:Select to set timeouts. This seems to work, but of
course I need to do more testing.
Actually, on further investigation, read() doesn't work for the
one-character-at-a-time reads (can_read() hangs), although it works
fine for longer block reads and using sysread() for single byte
reads. This is clearly too deep for me; I'm just glad I found
a solution that does work.
I have to admit I am not at all clear on the differences between
recv/send and read/print and sysread/syswrite when dealing with
socket filehandles. Since I couldn't get syswrite to work at all,
and since recv/send seem to be socket-specific, I feel like I've
done the right thing, but I wonder if anyone could clarify what
the differences are?
Also, is there any reason to unbuffer the socket filehandle (using
the $| variable)? Does this even make sense?
--
John Brock
jbrock@panix.com
------------------------------
Date: Mon, 09 Jun 2003 22:19:53 -0400
From: Benjamin Goldberg <ben.goldberg@hotpop.com>
Subject: Re: How to I arrange for a socket connection to time out?
Message-Id: <3EE54049.10640E3E@hotpop.com>
John Brock wrote:
[snip]
> Unfortunately it didn't work. Actually it would work once or twice
> and then hang on the can_read() call, long before the server was
> done sending. I did some more investigating, and I noticed this
> ominous sentence in my Programming Perl book:
>
> One should probably not attempt to mix buffered I/O (like
> read or <HANDLE>) with select, except as permitted by POSIX,
> and even then only on truly POSIX systems. Use sysread
> instead.
>
> Well, I am definitely using read() and the angle bracket operator
> to read from the socket. So, is that my problem,
Yes, definitely.
> I can try to use sysread() instead of read(),
Remember that sysread doesn't always get as many bytes as you ask for.
I would suggest:
our $buffer;
1 while length($buffer) < $desired and
sysread( $handle, $buffer, 1024, length $buffer);
my $block = substr( $buffer, 0, $desired, "" );
> but
> what do I use to replace <HANDLE> (or actually the getline() method
> of IO::Handle), which reads until it hits an end-of-line character?
our $buffer;
1 while ($eol = index( $buffer, Socket::CRLF() )) < 0
and sysread( $handle, $buffer, 1024, length $buffer );
my $line = substr( $handle, 0, $eol, "" );
Now, insert calls to select/IO::Select just before the sysread()s.
> Do I have to go into a loop and read one character at a time using
> sysread until I hit "\n"?
Heck no! Ask for large blocks of data, and do the buffering yourself.
And most importantly (this is what mixing read()/<> with select() fails
to do) make sure that you check whether or not your own buffer for the
handle already has the data you want, before you call select().
PS: I would wrap these functions inside a module, something like:
package IO::Socket::Buffered;
use base qw(IO::Socket::INET);
use strict;
sub get_info($) {
my $handle = shift;
my $handle_data = *{$handle}{HASH};
\$$handle_data{io_socket_buffered_buffer},
$$handle_data{io_socket_buffered_timeout};
}
sub configure {
my ($handle, @args) = @_;
my ($bufref) = get_info($handle);
$$bufref = "";
$handle->SUPER::configure(@args);
}
sub eof {
my $handle = shift;
my ($bufref, $timeout) = get_info $handle;
return 0 if length $$bufref;
my $vec = "";
vec( $vec, $handle, 1 ) = 1;
($timeout, my $n) = select( $vec, "", "", $timeout );
defined($n) and $n >= 0 or return;
if( $n == 0 ) {
require Errno;
$! = Errno::EAGAIN();
return;
}
my $n = sysread( $handle, $$bufref, 1024, length $buffer );
defined($n) or return;
$n ? 0 : 1;
}
sub getc {
my $handle = shift;
my $char = $handle->eof;
return unless $handle->read($char, 1);
$char;
}
sub read {
my ($handle, undef, $desired, $offset) = @_;
my ($bufref, $timeout) = get_info $handle;
my $vec = "";
vec( $vec, $handle, 1 ) = 1;
while( length($$bufref) < $desired ) {
($timeout, my $n) = select( $vec, "", "", $timeout );
defined($n) and $n >= 0 or return;
if( $n == 0 ) {
require Errno;
$! = Errno::EAGAIN();
return;
}
my $req = length($$bufref) - $desired;
$req = 1024 if $req < 1024;
my $n = sysread( $handle, $$bufref, $req, length $buffer );
defined($n) or return;
return if !$n and !length $$bufref;
$n or $desired = length $$bufref;
}
$offset = 0 unless defined $offset;
substr( $_[1], $offset ) = substr( $$bufref, 0, $desired );
substr( $$bufref, 0, $desired ) = "";
$desired;
}
sub getline {
my $handle = shift;
if( ref $/ ) {
$handle->read( (my $block), 0+$$/ );
return $block;
} elsif( not defined $/ ) {
die "Read til EOF unimplemented\n";
} elsif( not length $/ ) {
die "Paragraph read unimplemented\n";
}
my ($bufref, $timeout) = get_info $handle;
my ($vec, $n) = "";
vec( $vec, $handle, 1 ) = 1;
my $eol_idx;
until( $eol_idx = index( $$bufref, $/ ) > 0 ) {
($timeout, my $n) = select( $vec, "", "", $timeout );
defined($n) and $n >= 0 or return;
if( $n == 0 ) {
require Errno;
$! = Errno::EAGAIN();
return;
}
my $n = sysread( $handle, $$bufref, 1024, length $buffer );
defined($n) or return;
unless( $n ) {
return unless length $$bufref; # eof
my $line = $$bufref;
$$bufref = "";
return $line;
}
}
my $line = substr( $$bufref, 0, $eol_idx );
substr( $$bufref, 0, $eol_idx ) = "";
$line;
}
sub getlines {
die "Read until EOF unimplemented\n";
}
sub ungetc {
my ($handle, $char) = @_;
my ($bufref) = get_info $handle;
substr( $$bufref, 0, 0 ) = chr $char;
}
1;
__END__
[untested]
Now replace:
my $handle = IO::Socket::INET->new(...) or die $@;
With:
my $handle = IO::Socket::Buffered->new(...) or die $@;
And replace all uses of <> with $handle->getline(), and all uses of
read() with $handle->read().
> That doesn't look very efficient!
That's why we don't do things that way.
> And should I even be using IO::Select at all?
Yes, absolutely. Well, either that or select() itself.
> Maybe I've missed a better way to do what I'm trying to do.
>
> So to get back to my question, what is the proper way to code a
> client in Perl so that it will time out a socket connection if the
> server does not respond quickly enough?
Use select/IO::Select and sysread(). Possibly wrapped in a module.
--
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}
------------------------------
Date: Mon, 09 Jun 2003 22:39:20 -0400
From: Benjamin Goldberg <ben.goldberg@hotpop.com>
Subject: Re: How to I arrange for a socket connection to time out?
Message-Id: <3EE544D8.75A12AEC@hotpop.com>
John Brock wrote:
>
> In article <sk5aev8v88b5qk13qdvh4js32feva94q6r@4ax.com>,
> Greg Miller <gmiller@NOTforSPAM.gregmiller.net> wrote:
> >On 9 Jun 2003 11:29:05 -0400, jbrock@panix.com (John Brock) wrote:
>
> >>So to get back to my question, what is the proper way to code a
> >>client in Perl so that it will time out a socket connection if the
> >>server does not respond quickly enough?
>
> > IO::Select is one way. I've never had a problem using read()
> >and using select() at the same time, but I have run into several cases
> >where a < > screwed up everything else, so now I never use < > on
> >sockets. Just do as you said and read one character at a time, it may
> >look inefficient, but that's basically all it's doing underneath.
> > Another method is to use non-blocking IO and continue to do a
> >read() and a sleep() in a loop. This is less efficient, but works.
>
> I think it was the <>. I replaced it with sysread() in a loop and
> it worked fine, even though I was using read() elsewhere.
Using read() or <> in combination with select() is almost, but not
quite, guaranteed to result in deadlock.
Using read() or <> in combination with sysread() is almost, but not
quite, guaranteed to result in getting some of your data in the wrong
order.
If it all *appears* to work, then that's just a matter of luck -- give it
some time, and your program will eventually screw up.
All it will take is the right combination of delays, at the right points,
for the client to deadlock or process data in the wrong order.
> I was also using send() to write to the server, and to be consistent
> I tried replacing it with syswrite(), but this was very flaky, working
> sometimes and other times not.
Always, yes, always, check the return values of system calls.
Syswrite will not always send all of your data. Check it's return
value, amd if you sent less than you wrote, try again.
(Of course, given that the chances of deadlock during *writing* are
very slim, due to the nature of how the OS buffers it for you, I
generally don't worry about this -- I just use print(), with autoflush
turned on.)
> What I ended up doing was using the send() and recv() methods of
> IO::Socket for all socket communication, and using the can_read()
> method of IO:Select to set timeouts. This seems to work, but of
> course I need to do more testing.
Yes, that should work fine. recv() is about the same as sysread(),
except that it also tells you who the data is from (which you likely
know already, since this is a tcp socket, not a udp socket).
> Actually, on further investigation, read() doesn't work for the
> one-character-at-a-time reads
Sure it does -- but when you request one character, it reads a whole
block of characters. One of these is returned to you, and the extras
go into a buffer inside the handle.
> (can_read() hangs),
Sure -- it's waiting for data, when there isn't any more (the reason
there isn't any more, is that you've already read it (with read()), and
it's sitting inside of that buffer inside the handle).
> although it works fine for longer block reads and using sysread() for
> single byte reads.
That's just luck that it "works fine".
> This is clearly too deep for me; I'm just glad I found a solution
> that does work.
>
> I have to admit I am not at all clear on the differences between
> recv/send and read/print and sysread/syswrite when dealing with
> socket filehandles.
recv() is like sysread(), except that it also tells you the address
of who you're getting data from.
send() is like syswrite(), except that it also lets you give the address
of who to send to. (I think).
read() is like sysread(), except that instead of giving you the data
directly, it reads blocks if data into an internal buffer, and then
copies the bytes out of that buffer to you. (For large amounts of
data, it tries to avoid doing this).
print() is like syswrite(), except that instead of going directly to
the socket, it goes into an internal buffer (seperate from the buffer
used for input), then (eventually) sends the bytes from that buffer
to the socket. "Eventually" is after every print(), if $| is true,
or after every ??? bytes of data if $| is false (see perldoc IO::Handle,
specifically the bit about setvbuf() ... also, see the C manual page
for setvbuf).
> Since I couldn't get syswrite to work at all, and since recv/send
> seem to be socket-specific, I feel like I've done the right thing,
> but I wonder if anyone could clarify what the differences are?
>
> Also, is there any reason to unbuffer the socket filehandle (using
> the $| variable)? Does this even make sense?
The $| variable doesn't "unbuffer" the socket -- instead, it causes
every print() to be automatically followed by a flush. It has no other
effect whatsoever.
--
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}
------------------------------
Date: Mon, 9 Jun 2003 23:52:07 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Perl CGI and Downloading Files - How?
Message-Id: <Pine.LNX.4.53.0306092340020.23639@lxplus002.cern.ch>
On Mon, Jun 9, 10ghz@radiate.com inscribed on the eternal scroll:
> On Mon, 9 Jun 2003 20:45:34 +0200, "Alan J. Flavell" <flavell@mail.cern.ch>
> wrote:
[...]
> >Yes. But define "located"? Do you actually understand your question?
> > I'd suggest a group
> >somewhere in the comp.infosystems.www.... hierarchy would be more
> >apt, until you've got a question that's specific to Perl.
>
> No, wrong answer.
I still don't see anything wrong with those two answers.
> The correct response to my question
> should have been:
> "put the zip somewhere in the filesystem where it's
> not accessible via http, and use Perl to open
> this file and to send its contents to the
> browser with the appropriate content-type header."
And then the resource is "located" at the URL of the appropriate
CGI script invocation, in WWW terms.
The WWW cares nothing for where the server keeps its resources: it
might be on a database, on a remote filesystem, it might be created
dynamically by teams of penguins pecking holes in jacquard cards.
What the WWW cares is: what its URL is.
You have described a means of (expensively) assigning URLs to your
resources, and thus assigning them (expensively) their "location" on
the WWW.
> I was just thinking in terms of providing a link when I should
> have been thinking about my script actually sending the file.
You still haven't provided any reason for this profligate waste of
resources, however.
> http://groups.google.com/groups?q=Perl+hide+files+download&hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=386335db%240%24229%40nntp1.ba.best.com&rnum=5
But since the whole point of your script appears to be a way of
exposing the files' contents, you still haven't offered any reason for
trying to hide them.
There are far more efficient ways of applying access controls, if
that's what you wanted to do, than to have a CGI script laboriously
copying their contents.
And this still isn't a question about Perl, specifically.
> Entia non sunt multiplicanda praeter necessitatem.
nil carborundum :-}
------------------------------
Date: Tue, 10 Jun 2003 01:17:49 GMT
From: 10ghz@radiate.com
Subject: Re: Perl CGI and Downloading Files - How?
Message-Id: <2acaev0r0h1u1een6mjoiec44nfqf92l6m@4ax.com>
On Mon, 9 Jun 2003 23:52:07 +0200, "Alan J. Flavell" <flavell@mail.cern.ch>
wrote:
> You still haven't provided any reason for this profligate waste of
> resources, however.
I just didn't want to confuse anyone with erroneous information.
I want Users of my software to get file updates only through the Perl script and
no other way. This way the script can automatically check their versions, give
tips, tell them special information, and perform tracking. There are many
reasons for them to have to go through the script to get file updates.
>There are far more efficient ways of applying access controls, if
>that's what you wanted to do, than to have a CGI script laboriously
>copying their contents.
Which brings us back to my original question: "Using Perl, what is the best way
to distribute a file while applying access controls so the User has to use the
Perl script to get those files". Perhaps I've stated it better here. If you
know of more efficient ways I'd enjoy hearing about them, especially if you have
some Perl examples. Thanks!
> You have described a means of (expensively) assigning URLs to your
> resources, and thus assigning them (expensively) their "location" on
> the WWW.
Hmm... Now that is interesting. Why is it "Expensive"?
>And this still isn't a question about Perl, specifically.
Did you understand the part where I mentioned "Using Perl"?
Doesn't asking for Perl code examples make it a Perl specific question?
I'm writing the program in Perl and so was hoping for some Perl examples or some
Perl advice or perhaps a reference to Perl Man pages I may have overlooked.
Notice how many times I have mentioned Perl here. I would say my question is
very Perlish. Perhaps you have some Perl code to share as well as sophistry?
;-)
"You are very strange person Yossarian!" - General Dreedle.
------------------------------
Date: 4 Jun 2003 14:13:31 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: Posting to an asp form with hidden fields
Message-Id: <3ede60fb@news.victoria.tc.ca>
Alan Hogue (ahogue@law.berkeley.edu) wrote:
: Hello,
: I've searched all over and can't find something that quite answers my
: question. My appologies if I'm mistaken.
: I'm using LWP::UserAgent and HTTP::Request::Common to post to a search
: form. The form is an asp page with three hidden fields and some
: javascript that takes the values from three of the non-hidden fields,
: processes the values, and then inserts these values into the hidden
: fields.
Use somthing like Proxomitron.exe (http://www.proxomitron.org/) to examine
the complete post when sent from a regular browser.
That will help you understand what the javascript is doing, and also see
all the other headers, such as cookies, that may also be being set.
------------------------------
Date: 9 Jun 2003 16:07:18 -0700
From: chavankoya189@hotmail.com (Chavan Koya)
Subject: Probelm with PERL and Informix Can't use string ("Informix") as a HASH ref
Message-Id: <ef72e276.0306091507.6976ff83@posting.google.com>
Hi All,
I am getting a error message when i call a perl program from
a shell script. We have no problem with older version. but we are
upgrading and doing server consolidation (i.e right now there is one
production box this has old version of perl and we installed new
version on new production box )I no nothing about PERL. Please give me
some suggestions on this problem
Here is the message
some_variable=ct_return = Can't use string ("Informix") as a HASH ref
while "strict refs" in use at
/opt/perl5/lib/site_perl/5.8.0/PA-RISC2.0-LP64/DBD/Informix.pm line
146.
file_ld.sh: exit status = 255
Below is the line number
# Preset AutoCommit mode on $dbh.
$dbattr = { AutoCommit => 1 } if (!defined $dbattr); #
145
${$dbattr}{AutoCommit} = 1 if (!defined ${$dbattr}{AutoCommit}); #
line # 146
DBD::Informix::db::preset($dbh, $dbattr); #
147
This is the message and The OS is HP-UX 11.11 (64 bit ver).
Any suggestions comments or changes are greatly appreciated and thanks
in advance.
Chavan Koya
------------------------------
Date: Mon, 9 Jun 2003 19:07:07 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Probelm with PERL and Informix Can't use string ("Informix") as a HASH ref
Message-Id: <slrnbea89b.hoe.tadmc@magna.augustmail.com>
Chavan Koya <chavankoya189@hotmail.com> wrote:
> Please give me
> some suggestions on this problem
Post the question only one time.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 9 Jun 2003 17:12:16 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Quick question
Message-Id: <slrnbea1i0.hip.tadmc@magna.augustmail.com>
Avatar <ksu1wd@mit.edu> wrote:
> $search=~/(.*)blah/;
> I know that .* gets placed into $1.
Only if the match *succeeded*.
> $search2=~/(.*)blah/;
> Does that overwrite the orginal $1, append onto it, or cause an error?
What happened when you tried it?
Show us the complete code where you tried it, then ask questions
about that code, and we will then be able to answer them.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 09 Jun 2003 22:51:57 -0400
From: Benjamin Goldberg <ben.goldberg@hotpop.com>
Subject: Re: SORT sort hash with alpha-numeric keys
Message-Id: <3EE547CD.4AA8E640@hotpop.com>
Joe Hasting wrote:
>
> I've been through the FAQs and mauals, but cannot find info on sort
> using alphanumeric.
>
> Let's use this has table:
> %hash = ( "L8" => "Left 8", "L9" => "Left 9", "L80" => "Left 80",
> "L90" => "Left 90", "R8" => "Right 8", "R9" => "Right 9", "R80" =>
> "Right 80", "R90" => "Right 90") ;
>
> NOTE: these are coordinates, I would like to be able to use L08 & L09
> for example, but cannot.
>
> I want the sort output to be (sorting of hash keys or hash values
> would be fine):
> L8 Left 8
> L9 Left 9
> L80 Left 80
> L90 Left 90
> R8 Right 8
> R9 Right 9
> R80 Right 80
> R90 Right 90
my @sorted_keys = sort {
my ($a_alpha, $a_numer) = $a =~ /^(\w+)(\d+)\z/ or die;
my ($b_alpha, $b_numer) = $b =~ /^(\w+)(\d+)\z/ or die;
$a_alpha cmp $b_alpha or $a_numer <=> $b_numer;
} keys %hash;
Or, with a GRT:
my @sorted_keys =
map join("", unpack("AN", $_)),
sort
map /^(\w)(\d+)\z/ ? pack("AN", $1, $2 ) : die,
keys %hash;
Or, with an ST:
my @sorted_keys =
map $_[0],
sort { $a->[1] cmp $b->[1] or $a->[2] <=> $b->[2] }
map /^(\w+)(\d+)\z/ ? [ $_, $1, $2 ] : die,
keys %hash;
[all untested]
Note that if you used keys like "L08" and "L09" (or more than one
alphabetic character in front) then the GRT would have to be slightly
modified.
--
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}
------------------------------
Date: 9 Jun 2003 18:55:33 -0700
From: satishi@gwu.edu (slash)
Subject: Sorting and formatting
Message-Id: <30fe9f1e.0306091755.c7056ee@posting.google.com>
Hi,
I am new to Perl and still learning the ropes of the language. I need
some help with the following Schwartzian Transform code I have:
@data = <>;
timethese(100, {schwartzsort => q{ @sorted = map {
$_->[0]
} sort {
#$a->[0] cmp $b->[0] ||
$a->[1] cmp $b->[1] ||
$a->[3] cmp $b->[3]
}
map {
[$_, split /\./]
} @data
}
});
print for @sorted;
my input is a file of the following format generated using
Text::Table:
* * * united
united * united states
states united states patent
patent states patent april
april patent april 16
16 april 16 2002
2002 16 2002 method
method 2002 method apparatus
apparatus method apparatus performing
performing apparatus performing variable
variable performing variable size
.
.
.
more words in the file...
Following is the output I have from the above sorting:
* * * united
16 april 16 2002
16 april 16 2002
16 april 16 2002
2002 16 2002 method
2002 16 2002 modeling
2002 16 2002 modeling
2002 4 2002 adaptive
2002 4 2002 fourier
2002 4 2002 general
2002 4 2002 method
2002 april 2002 abstract
2002 april 2002 indexing
2002 april 2002 spectrum
2002 et 2002 embedded
2002 et 2002 unique
2002 june 2002 electronic
2002 june 2002 general
2002 june 2002 processing
2002 june 2002 system
2002 patent 2002 system
4 equal 4 each
4 equal 4 on
4 june 4 2002
4 june 4 2002
4 june 4 2002
4 june 4 2002
4 patent 4 method
a having a d
a second a d
a signal a d
abstract 2002 abstract physical
abstract architectures abstract digital
abstract cells abstract device
abstract coding abstract method
abstract control abstract electronic
abstract filter abstract signal
abstract fluids abstract invention
As you can see first and the third columns are same, whereas second
and fourth columns represent occurrences of words associated with each
word in first and third columns. In other words, all occurrences of
the string "*" are "*" and "united".
What I would like to do is to be able to represent the output in the
following way:
* *
* united
Is this possible? Can I take this a step further and store it as:
* *, united
as if it were a list of words associated with "*".
Any suggestions or help would be tremendously appreciated.
Thanks,
Slash
------------------------------
Date: Tue, 10 Jun 2003 04:42:28 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Sorting and formatting
Message-Id: <bc3gj1$ef3be$1@ID-184292.news.dfncis.de>
slash wrote:
> [$_, split /\./]
----------------------------------------------------^^
Are the fields separated by periods? I see no periods in the input
data you posted.
> Following is the output I have from the above sorting:
> * * * united
> 16 april 16 2002
> 16 april 16 2002
<snip>
> As you can see first and the third columns are same, whereas second
> and fourth columns represent occurrences of words associated with each
> word in first and third columns. In other words, all occurrences of
> the string "*" are "*" and "united".
>
> What I would like to do is to be able to represent the output in the
> following way:
>
> * *
> * united
>
> Is this possible?
I have no idea, because I don't understand what you mean.
I would suggest that you post a complete, executable program that
illustrates the problem, and that you try to expand on what it does
and what you would like it to do.
/ Gunnar
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Mon, 09 Jun 2003 20:02:02 -0400
From: Benjamin Goldberg <ben.goldberg@hotpop.com>
Subject: Re: Strange errors with huge hash
Message-Id: <3EE51FFA.34EA8B95@hotpop.com>
emcee wrote:
[snip]
> Bareword found where operator expected at (eval 4) line 1205, near
> "RUN"
> (Do you need to predeclare s?)
> Bad name after INF' at (eval 4) line 1205, <HASH> line 4850.
>
> But there is obviously nothing wrong with line 1205,
Would you mind showing us the contents of the 1205th line of the fourth
string-eval of your program is?
(NOT the 1205th line of your program itself, of course, since if it were
*that*, it would say, "at foo.pl line 1205" or somesuch.)
> and not only that, the only occurrence of RUN and INF in the file is
> is nearly 1000 lines higher up in the file.
--
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}
------------------------------
Date: Mon, 09 Jun 2003 20:04:30 -0400
From: Benjamin Goldberg <ben.goldberg@hotpop.com>
Subject: Re: Strange errors with huge hash
Message-Id: <3EE5208E.FD9F94CB@hotpop.com>
Tad McClellan wrote:
>
> emcee <res1uzbe@verizon.net> wrote:
>
> > I wrote a module
>
> That wheel has already been invented.
>
> > that recurses
>
> perldoc -q recurse
>
> "How do I print out or copy a recursive data structure?"
Good thing he's not dealing with a recursive data structure, then, eh?
He's dealing with a plain data structure (containing other data
structures), and using recursion to traverse it.
> > and creates the code to create the hash to create it,
>
> Huh?
ITHM "and creates a string which, when eval()ed, will produce the hash
which was passed to the function."
--
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}
------------------------------
Date: Tue, 10 Jun 2003 00:40:39 GMT
From: uhuh@nono.net (Michael G.)
Subject: Re: Strange errors with huge hash
Message-Id: <3ee527d9.5664445@news.charter.net>
On Sun, 8 Jun 2003 15:10:34 +0200, "Alan J. Flavell"
<flavell@mail.cern.ch> wrote:
>On Sat, Jun 7, Michael G. inscribed on the eternal scroll:
>
>> "Cargo cult code" is pretty clear to me, but what do you mean by
>> "Matt-factor?" Enquiring minds want to know...
>
>I think this web page puts it more diplomatically than I could myself:
>
>http://nms-cgi.sourceforge.net/
Ah, that explains it. I have run into his scripts once or twice...
------------------------------
Date: Tue, 10 Jun 2003 03:31:00 GMT
From: Kien Ha <kha@rogers.com>
Subject: Re: Using ParseRecur from Date::Manip
Message-Id: <3EE550F5.86D4D890@rogers.com>
Gupit wrote:
>
> I am having a hard time trying to get ParseRecur to work.
> I want to get all dates corresponding to a certain weekday starting
> from a given start date; e.g. all mondays since 4/1/03. I have tried a
> lot of different combinations of the recur string but nothing seems to
> work (it returns an empty string).
Something similar to Example #7 in the manpage:
use Date::Manip;
print map UnixDate($_, "%a %b %d, %Y\n"),
ParseRecur("0:0:1*1:0:0:0", "4/1/03", "4/1/03", "today");
--
Kien
------------------------------
Date: Mon, 09 Jun 2003 19:34:58 -0400
From: Petar Bog <devnull@mail.com>
Subject: Weird mod_perl and CGI::Application behavior
Message-Id: <bc35jb$is9$1@bob.news.rcn.net>
Hi,
has anyone experienced a script runnning under Apache::Registry (using
CGI::Application) *randomly* dumping it's output to stderr instead of
stdout? I was able to relate this oddity to a
<code>
close stderr;
open(stderr, ">>/tmp/stderr.log");
</code>
in the cgi. The bahevior dsappears if I remove the offending 2 lines.
Any ideas? Apache 1.3.27 with mod_perl 1.27 and CGI::Application 3.1
Cheers!
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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.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 5100
***************************************