[23024] in Perl-Users-Digest
Perl-Users Digest, Issue: 5244 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Jul 20 11:05:59 2003
Date: Sun, 20 Jul 2003 08:05:12 -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 Sun, 20 Jul 2003 Volume: 10 Number: 5244
Today's topics:
Re: "use" remote modules? <l.tierney@btinternet.com>
Re: "use" remote modules? <REMOVEsdnCAPS@comcast.net>
Re: (no subject) (Joe Smith)
Basic "IO::Select" problem <dodgynewsgroups@ewildgoose.demon.co.uk>
Re: Changing module dynamically (Thomas M. Widmann)
Re: Code to put today's date into MM-DD-YY format <his_ron@yahoo.com>
Re: generalizing cgi handling <me@home.com>
Re: generalizing cgi handling <me@home.com>
Re: generalizing cgi handling <me@home.com>
Re: Getting the size of files from a list? (Joe Smith)
Re: IP Conversion..Sending to Subroutine.. <joecool118@nospam.hotmail.com>
Re: IP Conversion..Sending to Subroutine.. <krahnj@acm.org>
Re: JOIN problem ? (2nd attempt to post) <REMOVEsdnCAPS@comcast.net>
Re: JOIN problem ? (2nd attempt to post) <jurgenex@hotmail.com>
Matching URls <sheukels=cuthere=@yahoo.co.uk>
Read/Write IO on socket file descriptor (Patrick LeBoutillier)
Re: Read/Write IO on socket file descriptor <asu1@c-o-r-n-e-l-l.edu>
Re: s there a module to acess Micorsoft Access datafile <jwillmore@cyberia.com>
Re: sinfo script, xchat, slackware <asu1@c-o-r-n-e-l-l.edu>
Re: sinfo script, xchat, slackware <devdas@users.sourceforge.net>
Write a loop <his_ron@yahoo.com>
Re: Write a loop <jurgenex@hotmail.com>
Re: Write a loop <shawn@magma.ca>
Re: Write a loop <his_ron@yahoo.com>
Re: <bwalton@rochester.rr.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 20 Jul 2003 10:27:55 +0100
From: lawrence tierney <l.tierney@btinternet.com>
Subject: Re: "use" remote modules?
Message-Id: <bfdnas$772$1$8300dec7@news.demon.co.uk>
Eric J. Roode wrote:
> Change the "use" above to "require". The "use" is happening when the
> BEGIN block is compiled, before the "push" happens.
>
If I change the "use" to "require" inside the BEGIN block I get:
BEGIN{
push @INC,\&get_remote_module('remote_module.pm');
require remote_module;
}
Undefined subroutine &main::get_remote_module called at test.pl line 4.
BEGIN failed--compilation aborted at test.pl line 6.
So I then try moving the sub get_remote_module inside the BEGIN block to
allow the @INC push to see it in it's lexical scope and get:
BEGIN{
push @INC,\&get_remote_module('remote_module.pm');
require remote_module;
sub get_remote_module{
require LWP::Simple;
my $name='http://www.remotehost.org/cgi-bin/'.pop;
my $doc=LWP::Simple::get($name) or return;
open(my($fh),"<:scalar",\$doc) or die "urg!\n$!";
return $fh;
}
}
Not a CODE reference at test.pl line 5.
BEGIN failed--compilation aborted at test.pl line 13.
Which refers to the "require remote_module;" call.
this is the same result I get as when the push on @INC and require are not
in a BEGIN block. i.e
#! /usr/bin/perl -w
use strict;
push @INC,\&get_remote_module('remote_module.pm');
require remote_module;
my $password=password();
print qq/"$password"\n/;
sub get_remote_module{
require LWP::Simple;
my $name='http://www.remotehost.org/cgi-bin/'.pop;
my $doc=LWP::Simple::get($name) or return;
open(my($fh),"<:scalar",\$doc) or die "urg!\n$!";
return $fh;
}
#############
returns
Not a CODE reference at test.pl line 5.
BEGIN failed--compilation aborted at test.pl line 13.
Help? Can anybody show me an example that works?
------------------------------
Date: Sun, 20 Jul 2003 06:09:07 -0500
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: "use" remote modules?
Message-Id: <Xns93BE48AC5A6FEsdn.comcast@206.127.4.25>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
lawrence tierney <l.tierney@btinternet.com> wrote in
news:bfdnas$772$1$8300dec7@news.demon.co.uk:
> Eric J. Roode wrote:
>
>
>> Change the "use" above to "require". The "use" is happening when the
>> BEGIN block is compiled, before the "push" happens.
>>
>
> If I change the "use" to "require" inside the BEGIN block I get:
>
> BEGIN{
> push @INC,\&get_remote_module('remote_module.pm');
> require remote_module;
> }
>
> Undefined subroutine &main::get_remote_module called at test.pl line
> 4. BEGIN failed--compilation aborted at test.pl line 6.
>
> So I then try moving the sub get_remote_module inside the BEGIN block
> to allow the @INC push to see it in it's lexical scope and get:
>
> BEGIN{
> push @INC,\&get_remote_module('remote_module.pm');
> require remote_module;
> sub get_remote_module{
> require LWP::Simple;
> my $name='http://www.remotehost.org/cgi-bin/'.pop;
> my $doc=LWP::Simple::get($name) or return;
> open(my($fh),"<:scalar",\$doc) or die "urg!\n$!";
> return $fh;
> }
> }
>
> Not a CODE reference at test.pl line 5.
> BEGIN failed--compilation aborted at test.pl line 13.
Oops, yes, I should have noticed this the first time around. Sorry.
A code reference is a reference to a subroutine. It does *not* include
any arguments to the subroutine. Try that last one again, but with the
first line as:
push @INC, \&get_remote_module;
- --
Eric
$_ = reverse sort qw p ekca lre Js reh ts
p, $/.r, map $_.$", qw e p h tona e; print
-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>
iQA/AwUBPxp4M2PeouIeTNHoEQLLLgCeN5w9IUHCHIZGZSU9kIL86TJQZWkAniN8
tg7LbcwkXBGpCYuuttgswlQb
=Tw1H
-----END PGP SIGNATURE-----
------------------------------
Date: Sun, 20 Jul 2003 08:35:47 GMT
From: inwap@inwap.com (Joe Smith)
Subject: Re: (no subject)
Message-Id: <DvsSa.511$603.25445@iad-read.news.verio.net>
In article <tv%Ra.91979$TJ.5252351@twister.austin.rr.com>,
Ron <his_ron@yahoo.com> wrote:
>Tried this code get a server 500 error.
>Anyone know what's wrong with it?
You are missing an open parenthesis.
>if $DayName eq "Select a Day" or $RouteName eq "Select A Route") {
> dienice("Please use the back button on your browser to fill out the Day
>& Route fields.");
>}
--
See http://www.inwap.com/ for PDP-10 and "ReBoot" pages.
------------------------------
Date: Sun, 20 Jul 2003 11:47:14 GMT
From: "Ed W" <dodgynewsgroups@ewildgoose.demon.co.uk>
Subject: Basic "IO::Select" problem
Message-Id: <6jvSa.601747$ZC.89849@news.easynews.com>
I have been staring at this for a day now (durr), but I just can't see what
is wrong with this code: (apart from poor coding style, but it's a
snippet...)
It's running under windows XP with activestate perl 5.6.1. However, the
code below always returns an empty array from the select call? There is
definitely something to read from the filehandle, if I comment out the IF
statement, then I happily get the first 10 bytes read from my other perl
program
The bigger picture is that the other perl script is a long running program
which occasionally returns output to stdout. I want the wrapper program to
do non-blocking IO to read stdout from the child process, however, select
doesn't appear to be letting me know that there is stuff to read, and simply
doing sysread works, but then blocks as soon as there is nothing left to
read (it unblocks occasionally when more data arrives)
The even larger picture is that I was to log this stuff in a text box in TK,
but I haven't found the $window->fileevent stuff to work for either tcp
sockets, or filehandles, this seems to be a known issue with Win32 though?
In the meantime I just want something running in the idle loop in order to
get something working today and I will re-work it later in something better.
Thanks for any pointers
Ed W
use IO::File;
use IO::Select;
my $H = IO::File->new("multi-client16.pl |");
$H->blocking(0);
$s = IO::Select->new();
$s->add($H);
my @readable = $s->can_read(0);
if (@readable) {
# We never get here? Why?
$H->sysread($ARG, 10);
print $ARG;
}
------------------------------
Date: 20 Jul 2003 11:07:31 +0100
From: thomas@widmann.uklinux.net (Thomas M. Widmann)
Subject: Re: Changing module dynamically
Message-Id: <m3y8ytpl3w.fsf@widmann.uklinux.net>
JS Bangs <jaspax@u.washington.edu> writes:
> Thomas M. Widmann sikyal:
>
> > So, to sum up: I'd like a function, let's call it changelang,
> > which will do the following:
> >
> > - Take one argument, the language to change to ($lang).
> >
> > - If it hasn't been loaded, load Bibulus::Lang::$lang (or
> > whatever -- I don't care much about the name, so long as each
> > language is defined in its own file).
> >
> > - Change the symbol table look-up path, so that
> > Bibulus::Lang::$lang is searched first.
> >
> > - This should not affect the whole package, just the instance
> > (as if there was something called @{$self->ISA}).
>
> I'm not sure how much control you have over the architecture of the
> whole thing, but this is how I would implement such a system:
>
> First, have all of your text methods be defined in the base class
> Bibulus::Lang, but don't actually define any text there. Rather,
> define a global hash %text that has key => value pairs for the text,
> and simply import that hash from a module. Thus, your base class has
> this:
>
> [...]
>
> All of the Bibulus::Lang::lang subclasses then have the
> responsibility of populating %text with appropriate values. The
> package variable %text will have the "standard" values for each
> lang, while $self->{text} will have instance-specific values.
I considered something like that originally, but I gave it up when I
realised that the order of elements can be language-dependent. (E.g.,
"5th" and "edition" might come out in the opposite order in some
languages.)
One could of course populate the hash with closures, but I fear it
would get totally out of hand.
But thanks anyway for the proposal!
/Thomas
--
Thomas Widmann, MA member of the steering group for europa.*
Mavisbank Gardens, Glasgow, Scotland, EU
thomas@widmann.uklinux.net http://www.widmann.uklinux.net
------------------------------
Date: Sun, 20 Jul 2003 13:48:32 GMT
From: "Ron" <his_ron@yahoo.com>
Subject: Re: Code to put today's date into MM-DD-YY format
Message-Id: <Q4xSa.90354$hV.6381454@twister.austin.rr.com>
Thanks Matija,
That works great. Just one more little problem (My Fault) I need the year
in YYYY format?
How would I change this to get MM-DD-YYYY Day?
my($dd,$mm,$yy,$day) = (localtime)[3,4,5,6];
my $today = join '-', map sprintf("%02d", $_), ($mm+1,$dd,$yy%100);
$day = (qw/Sun Mon Tue Wed Thu Fri Sat/)[$day];
print "$today $day\n";
Thanks,
Ron
"Matija Papec" <mpapec@yahoo.com> wrote in message
news:58eihv4glq4j9shb0ilkr0ebreqcj2k0jv@4ax.com...
> X-Ftn-To: Ron
>
> "Ron" <his_ron@yahoo.com> wrote:
> >I am new to cgi I would like to place a check box on my form. When it is
> >checked & I run my custom Upload cgi script I would like this code to.
> >
> >1. Get the current date & day of the week.
> >2. Put it into this format MM-DD-YY Day
> >
> >I have no ideal where to start. Suggestions Please?
>
> my($dd,$mm,$yy,$day) = (localtime)[3,4,5,6];
> my $today = join '-', map sprintf("%02d", $_), ($mm+1,$dd,$yy%100);
> $day = (qw/Sun Mon Tue Wed Thu Fri Sat/)[$day];
> print "$today $day\n";
>
>
>
> --
> Matija
------------------------------
Date: Sun, 20 Jul 2003 09:20:27 -0700
From: Steve in NY <me@home.com>
Subject: Re: generalizing cgi handling
Message-Id: <68glhv8b70ji31nl07jr8mh2nr7akk71j3@4ax.com>
On Sat, 19 Jul 2003 23:02:07 -0400, Benjamin Goldberg <ben.goldberg@hotpop.com> wrote:
>How about the following:
>
> package cgi_handling;
> use base qw(Exporter);
> @EXPORT = qw(cgi_handling);
> sub cgi_handling {
> require CGI;
> return CGI::Vars();
> }
> 1;
> __END__
hmmmm.....!!
>Some people might find something like the following a bit more useful,
>though:
>
> package CGI::Vars;
> sub import {
> my ($self, @names) = @_;
> my $namespace = caller() . "::";
> require CGI;
> for my $name (@names) {
> my $value = CGI::query($name);
> *{$namespace.$name} = \$value;
> }
> };
> 1;
> __END__
>
>Then, they could do:
>
> use strict;
> use CGI::Vars qw(affilate_ID site_title domain
> logo general_theme keywords template bgcolor
> text_color links_color file_system);
> print $affiliate_ID; # etc..
That is exactly, exactly what I want to do...but I want to write it myself!!
Thanks for the reply
------------------------------
Date: Sun, 20 Jul 2003 09:36:51 -0700
From: Steve in NY <me@home.com>
Subject: Re: generalizing cgi handling
Message-Id: <fvglhv8un37ur52igl1k448ik608q6i65u@4ax.com>
Hi Jeff and thanks for your reply.
On Sat, 19 Jul 2003 21:34:17 -0400, Jeff 'japhy' Pinyan <pinyaj@rpi.edu> wrote:
>Eh, I don't think you want to learn it that way. The CGI.pm module, which
>is a STANDARD module, does it. Correctly. If you want to learn the right
>way to do it, study the code from the module, and use the module. Writing
>it on your own is NOT easy.
Well, I am pretty comfortable with http and the CGI.pm is something like
6,000 lines of code...so I think that is a good reason to advoid it.
>No, you don't want to have several variables. If your module creates a
>bunch of variables, what happens when the name of a form field clashes
>with a variable you're using for something else in your program? And
>isn't it easier to have a hash that stores your form fields, so you can
>access ALL of them at once, easily?
>
>Creating variables on the fly ("symbolic references") is a bad idea for a
>beginner, an intermediate, or an expert. There are very few occasions
>where it's a good idea, honestly.
Maybe the hash isn't such a bad idea. I have no idea what sybolic refs
are, so I will have to do some reading here.
I think you gave me some very good advice to read through the mods
and see how its done there.
And thank you for the tips on the code. I read through the whole message
and will think about your ideas.
Steve
------------------------------
Date: Sun, 20 Jul 2003 09:49:49 -0700
From: Steve in NY <me@home.com>
Subject: Re: generalizing cgi handling
Message-Id: <a1ilhv8732s730vebhqm1hp3mfifg1atl9@4ax.com>
Hi Eric, thank you for taking the time to reply to my post.
On Sat, 19 Jul 2003 19:59:18 -0500, "Eric J. Roode" <REMOVEsdnCAPS@comcast.net> wrote:
>Can I ask what is so bad about a hash? A hash keeps all your CGI
>parameters and their values bundled up in one neat place, and there's no
>chance that it'll interfere with any other variables your main program
>uses elsewhere.
Yes...I am starting to think a hash is just fine.
>If you really really want to do that (and hey, this is just a learning
>excercise so what the heck), you have to do something like the following.
>
> # at start of cgi_handling function
> my $caller_package = caller;
>
> # later, at the point where you currently assign $a{$key}
> {
> no strict 'refs';
> *{$caller_package . '::' . $key) = \$value;
> }
This is what I was thinking of, but it is over my head right now.
I need to read up on references and passing varibles as
objects.
>Since you're learning, would you like some constructive criticism?
And thanks for the constructive criticism!! When you are learning
and writing code, maybe the program works but you have no
idea why or what your mistakes are...so it really helps out a lot ;-)
Steve
------------------------------
Date: Sun, 20 Jul 2003 09:03:15 GMT
From: inwap@inwap.com (Joe Smith)
Subject: Re: Getting the size of files from a list?
Message-Id: <nVsSa.512$603.25445@iad-read.news.verio.net>
In article <a2b8188a.0307071035.30c2b396@posting.google.com>,
Math55 <magelord@t-online.de> wrote:
>hi, how must i change the code so it shows the sum of all
>childdirectories from a directory? for example:
You can use one of my old programs to do that.
unix% lsf -du -x -o files.lsf /
unix% head files.du
K-bytes dirs files directory
2756727 25 13 .
1092378 33 14 usr
1063652 5 0 utility
716172 23 8 utility/local
478649 33 0 var
394761 30 126 utility/local/lib
247475 6 3 usr/openwin
195077 3 21 var/log
194757 8 1 utility/gnu
Look for 'lsf' in http://www.inwap.com/mybin/ .
(I tried to e-mail that file to you but <magelord@t-online.de> bounced.)
-Joe
--
See http://www.inwap.com/ for PDP-10 and "ReBoot" pages.
------------------------------
Date: Sun, 20 Jul 2003 09:45:24 GMT
From: "Joe" <joecool118@nospam.hotmail.com>
Subject: Re: IP Conversion..Sending to Subroutine..
Message-Id: <UwtSa.596151$mA4.82988@news.easynews.com>
> On Sat, 19 Jul 2003, Joe Henderson wrote:
>
> >Or does ne1 have a better way...
>
> I don't really know what you're doing, or why you're doing it.
Normally this is a whole array of sorting ip's in a file..
.While reading a file of ip's i want to sort then by lowest
to highest then print.. However.. when i do not split them
the values are not correctly push to the sub's.. So.. I tried
to use "big::int" but that did not work.. Any Ideas?
>
> >my $ip = "10.10.1.1";
> >my @octet = split(/\./, $ip); #Like to remove this garbage.., Just send
the
> >my $dec = &decimal(@octet);
>
> Then why not send the whole string and have the function do the splitting?
>
> >my $dec1 = substr($dec, 0, 5); #Like to remove this garbage..
> >my $dec2 = substr($dec, 5, 5); #Like to remove this garbage..
>
> >my $ip = &ip($dec1, $dec2);
>
> Why do you want to split the value into two pieces, only to rejoin them
> later?!
>
> --
> Jeff Pinyan RPI Acacia Brother #734 2003 Rush
Chairman
> "And I vos head of Gestapo for ten | Michael Palin (as Heinrich
Bimmler)
> years. Ah! Five years! Nein! No! | in: The North Minehead
Bye-Election
> Oh. Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)
>
------------------------------
Date: Sun, 20 Jul 2003 11:04:19 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: IP Conversion..Sending to Subroutine..
Message-Id: <3F1A776A.8C8E0A43@acm.org>
Joe Henderson wrote:
>
> When i can to send the dec value of an ip add to a sub it doesn't work..
>
> Is there any othe way i can do this w/o substring it..?
>
> Or does ne1 have a better way...
Perhaps you want the inet_aton() and inet_ntoa() functions from the
Socket module.
perldoc Socket
John
--
use Perl;
program
fulfillment
------------------------------
Date: Sat, 19 Jul 2003 23:38:54 -0500
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: JOIN problem ? (2nd attempt to post)
Message-Id: <Xns93BE6860C542sdn.comcast@206.127.4.25>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
stuseven@hotmail.com (stu7) wrote in
news:d7dd90b0.0307191740.5f1bdb7c@posting.google.com:
> *** A) Usenet is here, among a very few other reasons, so people
> *** with legitimate questions can get answers from those who
> *** already have encountered these problems... your post had
> *** virtually nothing to do with my questions - which were, in
> *** fact, answered politely and correctly by two posters previous
> *** to your "style whine"_ value of your spam is ? (right... nothing).
What the hell is this? All I was doing what pointing out, in a
neighborly sort of way, that your post breaks many of the longstanding
conventions of Usenet, and what to do about that. Ignoring these
conventions is generally considered rude. I was trying to help you not
appear rude.
It would seem that you are bent on being rude anyhow.
> *** B) If using my quoting style fouls up your newsreader, then,
> *** I feel as though I have contributed something extra. Kindly
> *** dont bother spamming people on these newsgroups again.
Your quoting style does not in fact foul up my newsreader. I was
pointing out that your style will be a problem for many other
newsreaders. It wasn't a personal gripe.
> *** C) If you really feel a need to get your snaz signature and
> *** puffy whines plastered all over the net, why not start your own
> *** newsgroup... why not start it on your own computer... then you
> *** you could have TOTAL control, ey ? :)
"Puffy whines"? What, you think that the tips I gave to you are my own
personal preferences? "Netiquette" is the cumulative, cultural buildup
of social rules and conventions on Usenet over the decades. This is not
a pissing contest between my personal style and yours. You're in a
foreign country and you're spitting on the sidewalk, leaving toilet paper
on the floor, crossing the street against the light.
You apparently have no clue what "netiquette" is, nor do you apparently
care. Your smiley does not soften how you come across.
- --
Eric
$_ = reverse sort qw p ekca lre Js reh ts
p, $/.r, map $_.$", qw e p h tona e; print
-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>
iQA/AwUBPxocsWPeouIeTNHoEQI7EgCfZhTC7eCtYpPDY7OGO07Fg9rQShoAn2WA
S69qtUpd22Ge/lBLqHBRzxfs
=uoOU
-----END PGP SIGNATURE-----
------------------------------
Date: Sun, 20 Jul 2003 06:05:36 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: JOIN problem ? (2nd attempt to post)
Message-Id: <QiqSa.45671$kI5.43605@nwrddc02.gnilink.net>
stu7 wrote:
> *** No thanks to you Eric... not that usenet isn't plagued
> *** with meaningless posts already - and your's fits right in...
> *** however, to answer your "friendly post" -
[rest of top-posted, fullquoted, unreadable quoting style whining of
clueless learning-resistant ignorant snipped]
*PLONK*
jue
------------------------------
Date: Sun, 20 Jul 2003 16:35:04 +0200
From: "Seansan" <sheukels=cuthere=@yahoo.co.uk>
Subject: Matching URls
Message-Id: <3f1aa893$0$61643$e4fe514c@dreader3.news.xs4all.nl>
Hi,
Does anyone know of a link to or an example of a decent regexp that wil
recognize internet URLs? (It needs to match urls starting with http:// and
www.)
I am trying to replace a string like
"My Homepage is @ http://www.homepage.nl"
with
"My Homepage is @ <A HREF =
'http://www.homepage.nl'>http://www.homepage.nl</A>"
Thx, Seansan
------------------------------
Date: 20 Jul 2003 06:48:28 -0700
From: patrick_leboutillier@hotmail.com (Patrick LeBoutillier)
Subject: Read/Write IO on socket file descriptor
Message-Id: <154121e6.0307200548.415e0d21@posting.google.com>
Hi all,
I'm trying to perform read and write I/O on a socket file descriptor
received for another process via a Unix Domain Socket. In trying to
understand all this I came up with a small test script that is not
working for me:
use strict ;
use IO::Socket::INET ;
my $socket = new IO::Socket::INET(
PeerAddr => 'www.perl.com',
PeerPort => 80,
Proto => 'tcp',
) ;
my $rfd = fileno($socket) ;
my $rfh = new IO::Handle->fdopen($rfd, "r") ;
my $wfd = fileno($socket) ;
my $wfh = new IO::Handle->fdopen($wfd, "w") ;
print "$rfd $rfh $wfd $wfh\n" ;
print $wfh "GET / HTTP/1.0\n\n" ;
print "Sent GET...\n" ;
my $line = <$rfh> ;
print $line ;
Should this work? It seems as though printing to $wfh
does nothing, and then the <$rfh> is hanging.
If this is not the way to go about this, what else can I do
to perform read AND write I/O on a socket file descriptor?
I'm using Perl 5.6.1 on Linux RH 7.1
Thanks,
Patrick LeBoutillier
------------------------------
Date: 20 Jul 2003 14:26:22 GMT
From: "A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu>
Subject: Re: Read/Write IO on socket file descriptor
Message-Id: <Xns93BE6A3368CD7asu1cornelledu@132.236.56.8>
patrick_leboutillier@hotmail.com (Patrick LeBoutillier) wrote in
news:154121e6.0307200548.415e0d21@posting.google.com:
> Hi all,
>
> I'm trying to perform read and write I/O on a socket file descriptor
> received for another process via a Unix Domain Socket. In trying to
> understand all this I came up with a small test script that is not
> working for me:
I am no expert so please take what I say with a grain of salt.
> use strict ;
> use IO::Socket::INET ;
>
> my $socket = new IO::Socket::INET(
> PeerAddr => 'www.perl.com',
> PeerPort => 80,
> Proto => 'tcp',
> ) ;
>
> my $rfd = fileno($socket) ;
> my $rfh = new IO::Handle->fdopen($rfd, "r") ;
> my $wfd = fileno($socket) ;
> my $wfh = new IO::Handle->fdopen($wfd, "w") ;
$wfh->autoflush(1);
> print "$rfd $rfh $wfd $wfh\n" ;
> print $wfh "GET / HTTP/1.0\n\n" ;
> print "Sent GET...\n" ;
> my $line = <$rfh> ;
> print $line ;
Also, I am not sure why you are creating $rfh and $wfh. $socket can be read
from and written to using regular Perl syntax:
#! C:/Perl/bin/perl.exe
use strict;
use warnings;
use IO::Socket::INET;
my $socket = new IO::Socket::INET(
PeerAddr => 'www.perl.com',
PeerPort => 80,
Proto => 'tcp');
die "Cannot open connection: $!\n" unless $socket;
print $socket "GET / HTTP/1.0\n\n";
print "Sent GET...\n";
my $line = <$socket>;
close $socket;
print $line, "\n";
__END__
Sinan.
--
A. Sinan Unur
asu1@c-o-r-n-e-l-l.edu
Remove dashes for address
Spam bait: mailto:uce@ftc.gov
------------------------------
Date: Sun, 20 Jul 2003 05:17:27 GMT
From: James Willmore <jwillmore@cyberia.com>
Subject: Re: s there a module to acess Micorsoft Access datafiles?
Message-Id: <20030720011838.74e823ce.jwillmore@cyberia.com>
> > From a FreeBSD box to a Windows box using this method?
> > Have you tried this?
>
> No. I don't have a FreeBSD box. I can try it from a Linux box; but i
> thought I'd leave a little work for the OP to do. He will learn
> something from the exercise.
Linux - FreeBSD - all Unix - NOT Windows. Read the OP.
>
> > Does it work?
> >
>
> IIRC, works fine on this Win32 system, as I had set it up several
> times. It's working in a CGI environment (IndigoPerl) on this Win32
> system; so access from FreeBSD, if I had it, should work. It *does*
> work from other Win32, as well as Linux buxes on this network.
A CGI environment. In other words, you used a web server to connect
to the ODBC datasource? So, the drivers needed to access the ODBC
datasource were on the Windows box, right? And the connection to the
Windows box was through a web server, right? So, basiclly, it didn't
work FROM the non-Windows machine without the use of a web server.
Which is why I suggested useing DBI::Proxy - same concept, different
approach. Still need a server or drivers to run on one box or the
other to accomplish the task. Simply setting up a DSN on the Windows
box won't work without a server or having drivers on the foriegn
machine. Interesting approach, but not what the OP was after.
>
> > I'm thinking you may have missread the OP. He wants to connect TO
> > a WIN32 box FROM FreeBSD. Can not be done as you indicated. If
> > it has, please let me know.
> >
>
> No. I understand what the OP is seeking. AFAIK, a System DSN would
> work. Have you proved your claim that it "can not be done as ...
> indicated"? Why don't you try it with *your* FreeBSD system and I'll
> try it with Linux? I'll post the results of my tests.
>
I have. When I first started using Linux (and later FreeBSD and
SunOS and variants of Windows and MVS), I used the approach the
setting up a DSN on a Windows machine
would fit the bill. Not so. But hey, don't take my work for it.
Here's a blurb from the book "Programming the Perl DBI". In the
section for DBD::ODBC, it states:
"For Win32, the driver manager is included with the operating system.
For Unix and varients, the iODBC driver manager is included in the
iodbc directory. While iODBC acts as the driver manager (in italics),
you still have to find an actual driver for your platform and
database."
It goes on to mention, get this, ODBC drivers for Unix. One mentioned
is ... UnixODBC. I'm sure if you take the time to do some research on
your own, you'll see what I'm talking about.
I placed the OP below your review. The OP mentions mounting the
Windows partition, which tells me the person posting wanted to use the
file WITHOUT using a server.
I'm done with this thread. Have a nice day.
===START ORIGINAL POST====
I find myself with the eed to obtain some data stored in Microsoft
Access
format files from a perl script ruinning on a FreebSD box.
What's the best way to do this?
The files are actually on a Windows machien, but I can mount the
partiton
using Samba.
===END ORIGINAL POST====
------------------------------
Date: 20 Jul 2003 04:09:11 GMT
From: "A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu>
Subject: Re: sinfo script, xchat, slackware
Message-Id: <Xns93BE1906799Aasu1cornelledu@132.236.56.8>
NeoSadist <neosad1st@charter.net> wrote in
news:vhj39fa3id9ucd@corp.supernews.com:
> A. Sinan Unur wrote:
>>
>> Do you get an error "Undefined subroutine &main::cat called at c.pl"
>> for the line above? I think you need to use the backtick operator
>> here. Or, you could just open the file and read from it.
>
> No, I get no error, just that the output is not correct, as I said in
> my post.
Well, you are calling cat as if it is a Perl subroutine, not an external
command whose output you want to read. In any case, you would be better off
just opening /proc/meminfo and reading from it directly. However, if you do
insist on using the cat program, you should do:
my @resources = `cat /proc/meminfo`;
> This didn't work. I tried incorporating it into the script, and got
> weird results.
What does 'weird results' mean?
> See, it adds all info that it gains to a $final
> string. Let me again post the script, and the contents of the file it
> is reading for that subprogram:
I saw your code the first time.
> sub mem {
> if (@resources){
> } else {
> @resources = cat("/proc/meminfo");
> }
>
> $sysname = qx|uname -r|;
> if (substr($sysname,0,3) eq "2.4" || substr($sysname,0,3) eq
> "2.2"){
> @mem = split/\s+/,(grep{/Mem:/}@resources)[0];
> $memused = sprintf ("%.1f",($mem[2] - $mem[5] -
> $mem[6])/1030010); $memtotal = sprintf
> ("%.1f",($mem[1]/1030010)); $memper = sprintf
> ("%.f",($memused/$memtotal)*100);
I do not get it. My first question is, what is 1030010? Since you are
trying to get to MB from bytes, one would assume you would divide by
1024*1024 = 1048576.
It looks like you are trying to decode
> total: used: free: shared: buffers: cached:
> Mem: 1025478656 326803456 698675200 0 64053248 96509952
In this case, why is $memused not just equal to $mem[2]? Why do you need to
subtract $mem[5]+mem[6] from it?
> } elsif (substr($sysname,0,3) eq "2.5" || substr($sysname,0,3)
> eq "2.6") {
> @memt = split/\s+/,(grep{/MemTotal:/}@resources)[0];
> @memf = split/\s+/,(grep{/MemFree:/}@resources)[0];
> @memb = split/\s+/,(grep{/Buffers:/}@resources)[0];
> @memc = split/\s+/,(grep{/Cached:/}@resources)[0];
>
> $memused = sprintf ("%.1f",($memt[1] - $memf[1] -
> $memb[1] - $memc[1])/1024);
> $memtotal = sprintf ("%.1f",($memt[1]/1024));
> $memper = sprintf ("%.f",($memused/$memtotal)*100);
> }
> $final = ("$final$c1 Mem usage:$c2 $memused/$memtotal MB
> ($memper%) |");
> }
Where did $final come from? Do you actually have warnings and strict
enabled?
> ALTERNATELY, THE COMMAND IT CAN CALL TO GET SAME INFO IS "FREE", AND
> THE OUTPUT OF THAT PROGRAM IS LIKE THIS:
No need to shout.
Please post a small, self-contained program that shows the erroneous output
as well as the output you expect. That would help with figuring out the
problem.
Sinan
--
A. Sinan Unur
asu1@c-o-r-n-e-l-l.edu
Remove dashes for address
Spam bait: mailto:uce@ftc.gov
------------------------------
Date: 20 Jul 2003 09:20:53 GMT
From: Devdas Bhagat <devdas@users.sourceforge.net>
Subject: Re: sinfo script, xchat, slackware
Message-Id: <slrnbhknmi.ovr.devdas@evita.devdas.geek>
On Fri, 18 Jul 2003 23:10:42 -0600, NeoSadist <neosad1st@charter.net> poured
into the usenet group comp.lang.perl.misc:
> Sorry to post about this, but i think it's related to the way perl
> works.
> I have a problem with perl reading a file right when i make a call of
> the script inside xchat. It's the sinfo script. I verified that the
> output is wrong (i.e. read the file it's supposed to get the info from,
> "cat /proc/meminfo"). However, I don't know perl much, although i'm
> familiar with basic (so i'm not a complete moron lol).
I wrote a similar script to help me get some work done.
http://dvb.homelinux.org/~devdas/sysinfo.pl might be useful. Feel free to
modify.
Warning: it was written more for clarity than for performance.
Devdas Bhagat
------------------------------
Date: Sun, 20 Jul 2003 13:22:17 GMT
From: "Ron" <his_ron@yahoo.com>
Subject: Write a loop
Message-Id: <dIwSa.90353$hV.6375146@twister.austin.rr.com>
Would you show me how I can write this as a loop?
#Get the number of files uploaded
my $Num_Files = 0;
if ($size_file > 1) {
$Num_Files = 1;
}
if ($size_file2 > 1) {
$Num_Files = 2;
}
if ($size_file3 > 1) {
$Num_Files = 3;
}
if ($size_file4 > 1) {
$Num_Files = 4;
}
if ($size_file5 > 1) {
$Num_Files = 5;
}
if ($size_file6 > 1) {
$Num_Files = 6;
}
if ($size_file7 > 1) {
$Num_Files = 7;
}
if ($size_file8 > 1) {
$Num_Files = 8;
}
if ($size_file9 > 1) {
$Num_Files = 9;
}
Thanks,
Ron
------------------------------
Date: Sun, 20 Jul 2003 13:54:17 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Write a loop
Message-Id: <daxSa.47091$kI5.34330@nwrddc02.gnilink.net>
Ron wrote:
> Would you show me how I can write this as a loop?
>
> #Get the number of files uploaded
> my $Num_Files = 0;
> if ($size_file > 1) {
> $Num_Files = 1;
> }
> if ($size_file2 > 1) {
> $Num_Files = 2;
> }
> if ($size_file3 > 1) {
> $Num_Files = 3;
> }
> if ($size_file4 > 1) {
> $Num_Files = 4;
> }
> if ($size_file5 > 1) {
> $Num_Files = 5;
> }
> if ($size_file6 > 1) {
> $Num_Files = 6;
> }
> if ($size_file7 > 1) {
> $Num_Files = 7;
> }
> if ($size_file8 > 1) {
> $Num_Files = 8;
> }
> if ($size_file9 > 1) {
> $Num_Files = 9;
> }
Use a more suitable datastructe.
If you enumerate scalars like this then you should really use an array
instead (the other option would have been a hash).
Untested, just to give you an idea:
my @size_file = <<<Filled with whatever you want>>>;
for (1..9) {
if ($size_file[$_] >1) {$Num_Files = $_;}
jue
------------------------------
Date: Sun, 20 Jul 2003 10:20:19 -0400
From: Shawn Corey <shawn@magma.ca>
Subject: Re: Write a loop
Message-Id: <9imdnVPq4KwIOYeiXTWJhw@magma.ca>
Hi,
Store the file sizes in an array?
for( my $i = $Number_of_files; $i; $i -- ){
if( $size_file[ $i ] > 1 ){
$Num_Files = $i;
last;
}
}
Ron wrote:
> Would you show me how I can write this as a loop?
>
> #Get the number of files uploaded
> my $Num_Files = 0;
> if ($size_file > 1) {
> $Num_Files = 1;
> }
>
> if ($size_file2 > 1) {
> $Num_Files = 2;
> }
>
> if ($size_file3 > 1) {
> $Num_Files = 3;
> }
>
>
> if ($size_file4 > 1) {
> $Num_Files = 4;
> }
>
> if ($size_file5 > 1) {
> $Num_Files = 5;
> }
>
>
> if ($size_file6 > 1) {
> $Num_Files = 6;
> }
>
>
> if ($size_file7 > 1) {
> $Num_Files = 7;
> }
>
>
> if ($size_file8 > 1) {
> $Num_Files = 8;
> }
>
>
> if ($size_file9 > 1) {
> $Num_Files = 9;
> }
>
> Thanks,
> Ron
>
>
------------------------------
Date: Sun, 20 Jul 2003 14:28:18 GMT
From: "Ron" <his_ron@yahoo.com>
Subject: Re: Write a loop
Message-Id: <6GxSa.96194$TJ.5569430@twister.austin.rr.com>
Thanks Jürgen,
Tried this code but I get a server 500 error. Can I use zero for my
@size_file = 0 ?
my @size_file = <<<Filled with whatever you want>>>;
> for (1..9) {
> if ($size_file[$_] >1) {$Num_Files = $_;}
"Jürgen Exner" <jurgenex@hotmail.com> wrote in message
news:daxSa.47091$kI5.34330@nwrddc02.gnilink.net...
> Ron wrote:
> > Would you show me how I can write this as a loop?
> >
> > #Get the number of files uploaded
> > my $Num_Files = 0;
> > if ($size_file > 1) {
> > $Num_Files = 1;
> > }
> > if ($size_file2 > 1) {
> > $Num_Files = 2;
> > }
> > if ($size_file3 > 1) {
> > $Num_Files = 3;
> > }
> > if ($size_file4 > 1) {
> > $Num_Files = 4;
> > }
> > if ($size_file5 > 1) {
> > $Num_Files = 5;
> > }
> > if ($size_file6 > 1) {
> > $Num_Files = 6;
> > }
> > if ($size_file7 > 1) {
> > $Num_Files = 7;
> > }
> > if ($size_file8 > 1) {
> > $Num_Files = 8;
> > }
> > if ($size_file9 > 1) {
> > $Num_Files = 9;
> > }
>
> Use a more suitable datastructe.
> If you enumerate scalars like this then you should really use an array
> instead (the other option would have been a hash).
>
> Untested, just to give you an idea:
>
> my @size_file = <<<Filled with whatever you want>>>;
> for (1..9) {
> if ($size_file[$_] >1) {$Num_Files = $_;}
>
> jue
>
>
------------------------------
Date: Sat, 19 Jul 2003 01:59:56 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re:
Message-Id: <3F18A600.3040306@rochester.rr.com>
Ron wrote:
> Tried this code get a server 500 error.
>
> Anyone know what's wrong with it?
>
> if $DayName eq "Select a Day" or $RouteName eq "Select A Route") {
(---^
> dienice("Please use the back button on your browser to fill out the Day
> & Route fields.");
> }
...
> Ron
...
--
Bob Walton
------------------------------
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 5244
***************************************