[18761] in Perl-Users-Digest
Perl-Users Digest, Issue: 929 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri May 18 06:05:47 2001
Date: Fri, 18 May 2001 03: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)
Message-Id: <990180308-v10-i929@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 18 May 2001 Volume: 10 Number: 929
Today's topics:
@chars the same as ($#chars) ? <rcook@pcug.org.au>
Re: @chars the same as ($#chars) ? (Rafael Garcia-Suarez)
Re: @chars the same as ($#chars) ? (Anno Siegel)
Re: [OT] Software Engineering at 14 (was: Re: Beginner' <reply-via@my-web-site.com>
Re: Beginner's Language? <illya@rosen-bote.de>
Re: Calling an undefined variable <bart.lateur@skynet.be>
Re: check if file exists with different extensions <nospam@peng.nl>
Re: Closure: which variable does it refer to? (Logan Shaw)
Re: Filehandling, opening & Reopnening <c_clarkson@hotmail.com>
Has this already been done? <davsoming@lineone.net>
HELP with pl/perl and postgres... (Bruno Boettcher)
modem/serialport experts? (Phil)
module for umlauts <ubl@schaffhausen.de>
Re: module for umlauts (Rafael Garcia-Suarez)
Re: Nettiquete (Re: Help with File Upload -CGI.pm) <bart.lateur@skynet.be>
non-blocking "print" on a client socket ?? <cico@icomag.de>
Re: tie, FETCH and list context (Dave Murray-Rust)
Re: transform html to xhtml <matt@sergeant.org>
Re: URGENT: CGI program wanted! <hafner-usenet@ze.tu-muenchen.de>
Re: use an expanding set of modules (Dave Murray-Rust)
Re: What's wrong with my scope? (J.C.Posey)
Re: Writing to Unix passwd (Villy Kruse)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 18 May 2001 19:32:54 +1000
From: Owen Cook <rcook@pcug.org.au>
Subject: @chars the same as ($#chars) ?
Message-Id: <g8g9gt0utcu0137kav9afq2f80idotplr2@4ax.com>
In the little program below, lines 6 and 7 appear to be equivalent.
How come ($#chars) is the same as @chars , or alternatively, what should I be
reading to clarify this point.
TIA
Owen
-----------------------------------------------------------
#!/usr/bin/perl -w
$password = "qwertyuiop";
@chars = ('a' .. 'z', 'A' .. 'Z', 0 .. 9, '.', '/');
$salt = $chars[rand @chars] . $chars[rand @chars]; # Line 6
#$salt = $chars[rand($#chars)] . $chars[rand($#chars)]; # Line 7
$encrypted = crypt($password, $salt);
print "$encrypted\n";
------------------------------
Date: 18 May 2001 09:36:04 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: @chars the same as ($#chars) ?
Message-Id: <slrn9g9rah.va8.rgarciasuarez@rafael.kazibao.net>
Owen Cook wrote in comp.lang.perl.misc:
} In the little program below, lines 6 and 7 appear to be equivalent.
} How come ($#chars) is the same as @chars , or alternatively, what should I be
} reading to clarify this point.
[snip]
They're not equivalent. $#chars is the number of elements in @char minus
one (i.e. the last index in array @chars). @chars, evaluated in scalar
context, returns the number of elements in @chars. So, $#chars + 1 ==
scalar @chars.
To get a random element of @chars, you should use $chars[rand @chars].
--
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
------------------------------
Date: 18 May 2001 09:44:02 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: @chars the same as ($#chars) ?
Message-Id: <9e2qt2$2c9$1@mamenchi.zrz.TU-Berlin.DE>
According to Owen Cook <rcook@pcug.org.au>:
> In the little program below, lines 6 and 7 appear to be equivalent.
Don't jump to conclusions. The equivalence of programs that depend
on random numbers is hard to assess.
> How come ($#chars) is the same as @chars , or alternatively, what should I be
> reading to clarify this point.
You should read about array variables in perlvar.
@chars in scalar context is the number of elements in the array.
$#chars is the index to the last element of the array. There's
a difference of (usually) 1.
[most of code snipped]
> $salt = $chars[rand @chars] . $chars[rand @chars]; # Line 6
> #$salt = $chars[rand($#chars)] . $chars[rand($#chars)]; # Line 7
Anno
------------------------------
Date: Fri, 18 May 2001 11:50:59 +0200
From: "Biep @ http://www.biep.org/" <reply-via@my-web-site.com>
Subject: Re: [OT] Software Engineering at 14 (was: Re: Beginner's Language?)
Message-Id: <9e2r9n$pni9$1@ID-63952.news.dfncis.de>
"Peter Schuller" <peter.schuller@infidyne.com> wrote in message
news:9e1mab$hr6$1@hecate.umd.edu...
> I actually don't have anything against history in the general sense. Just
> the history tought in school. I want choice. WWII? Give it to me. WWI?
The
> same. The history of the human species? Sure. And so on. Swedish kings?
> No, and I shouldn't be foreced to study it. Especially not more than
once.
But how can you ever understand the intricacies of the positions and
actions of the various groups in Sweden (or anywhere) during, say, WWII,
without a thorough knowledge of preceding history?
WWII on itself is not history, that is a story. It becomes history when
you see it in the context of how thought patterns have grown the way they
have, how someone's behaviour follows from the atmosphere they grew up in,
and why that atmosphere was as it was..
Now if you had an incompetent teacher, that is sad, but it doesn't relate
to this discussion.
--
Biep
Reply via http://www.biep.org
------------------------------
Date: Thu, 17 May 2001 14:43:56 +0200
From: "illya" <illya@rosen-bote.de>
Subject: Re: Beginner's Language?
Message-Id: <9e0gr9$n2q$05$1@news.t-online.com>
Yes, for more easier lerning test:
http://www.perl-maker.com
Greetings
illi
Biep @ http://www.biep.org/ <reply-via@my-web-site.com> schrieb in im
Newsbeitrag: 9e01ge$aqom$1@ID-63952.news.dfncis.de...
> "Lex Spoon" <lex@cc.gatech.edu> wrote in message
> news:m3ae4dyyck.fsf@chaos.resnet.gatech.edu...
> > If the learner is happy averaging lists of numbers
> > and generating sentences and things like that,
> > then Scheme is a wonderful place to start,
> > but many beginners would be happier playing with graphical objects..
>
> .. and for them (PLT) Scheme is a wonderful place to start.
>
> --
> Biep
> Reply via http://www.biep.org
>
>
>
>
------------------------------
Date: Fri, 18 May 2001 08:19:54 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Calling an undefined variable
Message-Id: <rim9gtsr3g4uqkm5kglnp6cgtpl1ght1b9@4ax.com>
KapTin KiRk wrote:
>
>#in the 5 files#
>$searchfor = $Genre;
>
>
>#in the module#
> while (($key, $value) = each %dbmdata) {
> ($Title, $PreviewURL, $ReviewURL, $Rating, $Release, $Genre) =
>split(/$DELIM/, $value);
> if ($searchfor =~ /$ID/) {
>print some stuff
>} }
>
>... but as you can see, the value of $Genre doesn't get defined until the
>database is open. How on earth would I go about getting this to work as
>intended?
I think what you want is to be able to specify which field you want to
look in. Why don't you simply number them?
#in the 5 files#
$searchfor = 5;
#in the module#
while (($key, $value) = each %dbmdata) {
my @field = split(/$DELIM/, $value);
if ($field[$searchfor] =~ /$ID/) {
print some stuff
} }
If you find the numeric literals to be a PITA, then maybe define a hash
of constants:
my @name = qw(Title PreviewURL ReviewURL Rating Release Genre);
my %column = map { $name[$_] => $_ } 0 .. $#name;
$searchfor = $column{Genre};
--
Bart.
------------------------------
Date: Fri, 18 May 2001 08:28:25 GMT
From: "Lex" <nospam@peng.nl>
Subject: Re: check if file exists with different extensions
Message-Id: <J25N6.147601$Uo2.3891632@zwoll1.home.nl>
"Philip Newton" <pne-news-20001517@newton.digitalspace.net> wrote in message
news:88u7gtg0h2v4f3k2png8mi2bs0odhqac68@4ax.com...
>
> If you're going to use the /i switch, why do you include both jpg and
> JPG, both gif and GIF, etc.?
>
Thanks for pointing that out Philip,
I never studied perl, I'm just trying to get done what I'd like 'my' scripts
to do with the help of a few books, I wish I had a few weeks to properly sit
down and study.
Maybe some day...
Thanks!
Lex
------------------------------
Date: 18 May 2001 02:47:25 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Closure: which variable does it refer to?
Message-Id: <9e2k2d$l0g$1@charity.cs.utexas.edu>
In article <9e25gh$cst@netnews.hinet.net>,
John Lin <johnlin@chttl.com.tw> wrote:
>Dear all,
>
>Guess the results of the following programs.
>
>my($print,$index);
>$print = sub { print $index };
>$index = 1;
>$print->();
>
>The result is 1 as I can expect. But
>
>my($print,$index);
>for $index (1..3) {
> $print = sub { print $index };
>}
>$index = 1;
>$print->();
>
>The result is... 3 (not 1 as I expected)!!!
What does this code print?
@x = 1 .. 5;
foreach $x (@x)
{
$x++;
}
print join (" ", @x), "\n";
Answer: It prints "2 3 4 5 6".
Why? Because when you do a foreach loop over an array, the loop
variable doesn't get a copy of each array element. Instead, it becomes
essentially an alias for the array element. That's why things like
this (which are more idiomatic) work nicely:
@lines = <SOMEFILE>;
foreach (@lines) { chomp; }
chomp is chomping $_, and when it does, this affects the arrays. This
behavior extends to not just $_ but also to any foreach loop variable.
There is one explanation that may make sense at first but which can't
be right. That explanation is the one you might think of when reading
this text (from "perldoc perlsyn"):
The `foreach' loop iterates over a normal list value and
sets the variable VAR to be each element of the list in
turn. If the variable is preceded with the keyword `my',
then it is lexically scoped, and is therefore visible only
within the loop. Otherwise, the variable is implicitly
local to the loop and regains its former value upon exiting
the loop. If the variable was previously declared with
`my', it uses that variable instead of the global one, but
it's still localized to the loop.
You might think that a different $x is being created, and that is
the one that's bound into the closure. But if I understand local
variables in Perl properly, that's not the case, because making
something local just saves the value (as on a stack) and restores the
value later. That means it wouldn't really be a separate variable.
So, instead we have to go with the other explanation. What your loop
is doing is creating a closure (well, three of them, but two of them
are not referred to and presumably garbage collected), and the value
that is being bound into the closure is not the loop variable but an
element of the array that you've created, i.e. the array "1..3".
As a test for that theory, I wrote this code:
my $x;
@x = 1 .. 3;
foreach $x (@x)
{
$print = sub { print $x; };
}
$x[$#x] = 42;
$print->();
print "\n";
And sure enough, it prints "42". So, the way to change the value in
the closure is to change the array, so the closure must be bound to an
array element (via being bound to something that was an alias for the
array element).
I'm kind of curious whether this is something anyone intended to happen
or not. Mixing closures with the special behavior of foreach loop
variables is something that may not have come up before. (Or maybe it
has.)
I'm particularly interested in knowing what happens with garbage
collection. For instance, if I write this:
{
my $x;
my @x = 1 .. 3;
foreach $x (@x)
{
$foo = sub { $x; };
}
}
Then after the outer block, @x is no longer in scope, but it is
referred to by the closure. But does perl know this? Does perl take
into account the possibility that a closure can refer not to a whole
(first-class) variable but just to a value within an array? And, since
only one value of the array is needed, is the whole thing kept around
just to ensure that one value remains available? (It would be a more
dramatic question if I'd written "@x = 1 .. 100_000_000;".)
I have to confess I don't know a lot about garbage collection in Perl.
I don't really know whether it's the variables or the values themselves
that are garbage collected, and I don't know if individual elements of
an array can be garbage collected separately or not. I can imagine
code, though, in which handling closures plus variable aliasing into
arrays would have to be a special case, and I can imagine someone might
not have thought of that special case. (But, I can imagine it other
ways too.)
my $x; @x = split (//, "Thanks for the inspiration");
foreach $x (@x)
{ my $y = $c; $c = $c ? sub { print $x; $y->(); } : sub { print $x; }; }
@x[0..$#x] = reverse split (//, "Just another Perl hacker,\n"); $c->();
- Logan
--
my your his her our their _its_
I'm you're he's she's we're they're _it's_
------------------------------
Date: Fri, 18 May 2001 03:56:42 -0500
From: "Charles K. Clarkson" <c_clarkson@hotmail.com>
Subject: Re: Filehandling, opening & Reopnening
Message-Id: <156BD16BB76D4DB0.8F82FA4F231419BC.E01DC93FB5AF9657@lp.airnews.net>
Mika Morell <mika.morell@se.abb.com> wrote:
: Hi.
:
: This is kind of anewbie question, first time for perl. I need to reread
: the same file 18 times, is there a way to not having to open and close
: it 18 times. With this layout of the script it only reads the file once.
: And if I move the opening/closing of LOGFILE inside the for loop
: it takes forever. The important part of the script looks like this:
:
: open (LOGFILE,"$tmplog") || die "YOu killed kenny!!! YOu Bastard\n";
Putting double quotes (") around only a variable is not a good
habit to develop "$tmplog" is equivalent to $tmplog. See perlfaq4
' What's wrong with always quoting "$vars''? '
: for ($i = 1 ; $i <=$total; $i++) {
I assume that $nuffra is always $i - 1 and that @hosts holds the
basenames of 18 files. 'foreach my nuffra ( 0 .. taotal -1 ) {' seems
to make more sense. Or:
foreach my $host (@hosts) {
open (OUTFILE, ">>$outpath/$host.log.txt");
while (<LOGFILE>){
if (/ $host /) {
: open (OUTFILE,">>$outpath/$hosts[$nuffra].log.txt");
: while (<LOGFILE>){
: if (/\ $hosts[$nuffra]\ /) {
'/\ ' is escaping a space, which is unecesary. so
/\ $hosts[$nuffra]\ / should be equivalent to / $hosts[$nuffra] /.
: print OUTFILE ("$_");
Putting double quotes (") around only a variable is not a good
habit to develop "$_" is equivalent to $_.
: }
: }
: close OUTFILE|| die " Someone is bakin brownies\n";
: $nuffra++;
: }
:
Assuming I guessed right about the structure of @hosts:
Perldelta for 5.6.0 shows an alternate method for open:
open my $fh, 'in.txt' or die . . .;
When $fh goes out of scope and there are no references to it
the file closes. So it's easy to write a sub to open all those
host files at once. This one returns a hash with only the files
that opened successfully:
sub open_hosts ($\@) {
my $outpath = shift;
my $host_array_ref = shift;
my %file_handles;
foreach my $host (@$host_array_ref) {
my $out_file = "$outpath/$host.log.txt";
# if you leave this statement as is
# any files that don't open will be
# excluded from the returned hash
open my $out, ">>$out_file" or next;
# comment the line above and uncomment this
# line to die if a file can't be opened
#open my $out, ">>$out_file" or die "Cannot open $out_file $!";
$file_handles{$host} = $out;
}
return %file_handles;
}
Now we can iterate over the log file just once:
{
open my $log, $tmplog or die "YOu killed kenny!!! YOu Bastard\n";
my %file_handles = open_hosts $outpath, @hosts;
while (<$log>){
# by looping over 'keys %file_handles' instead of @hosts
# we avoid writing to files that didn't open
foreach my $host (keys %file_handles) {
print { $file_handles{$host} } $_ if /\b$host\b/;
}
}
} # As $log and %file_handles go out of scope all files are closed
We could avoid the foreach with:
my $search = join '|', keys %file_handles;
while (<$log>){
print { $file_handles{$1} } $_ if /\b($search)\b/;
}
But that obscures the code a bit and I think it's slower.
HTH,
Charles K. Clarkson
------------------------------
Date: Fri, 18 May 2001 10:43:46 +0100
From: "David Soming" <davsoming@lineone.net>
Subject: Has this already been done?
Message-Id: <tg9rbb8fl45bc1@corp.supernews.co.uk>
Im new to perl so have a laugh at my expense if you will but...
Just an idea for creating a unique 12 digit ID Using the date and time :)
If such a module exists already based on this concept please ignore.
Today's date 18:05:01
Time 10:41:21
concatenation= "180501104121" =Unique 12 digit ID
If its a crap idea, well OK.
If there is a module which is better, (in the sense of output being easily
readable-and readily understood, meaningful) or gives similar output then I
don't wish to reinvent the wheel right?
But could this be used say as a date stamp to verify an file upload or
acknowledgement.
Any suggestions on manipulating these variables or sample code I can play
around with?
Thanks for your thoughts and possible sarcasm too! lol.
David Soming
------------------------------
Date: 18 May 2001 11:10:23 GMT
From: bboett@erm6.u-strasbg.fr (Bruno Boettcher)
Subject: HELP with pl/perl and postgres...
Message-Id: <9e2vuv$ab$1@news.u-strasbg.fr>
hello!
i am having some trouble with the procedural languages bound to the
postgresDB... since now i was mainly using the pl/psql language, but
since this language is unable to use dynamic table names for its
DB-queries, i was looking to use more the pl/perl module....
now the documentation of that thing is really scarse....
basicly it says you can do nearly all you can do in a normal perl env...
but it doesn't say if there are some facilities to access the DB
somehow...
now in my pl/psql functions i make further DB interactions (selects,
inserts, updates etc...) does someone has some pl/perl code that
continues interaction with the DB making select calls from which i could
inspirate myself?
--
bboett at erm1 dot u-strasbg dot fr
http://erm6.u-strasbg.fr/~bboett
==============================================================
Unsolicited commercial email is NOT welcome at this email address
------------------------------
Date: 18 May 2001 09:25:59 GMT
From: eclipsephil@aol.comnospam (Phil)
Subject: modem/serialport experts?
Message-Id: <20010518052559.29895.00000263@ng-bh1.aol.com>
I am using mandrake linux a us robotics sportster voice 33.6 fax modem, perl
5.6.0 and device::SerialPort v.0.10
I can initialise my call out and perform the first operation fine. However
when I or the other end drop the line I seem to have problems with wierd
characters in the buffer. ie if I do something like this simplified version
(note I'm not worried about parameters just for this question)
do {
setup modem;
write_modem;
waitfor;
down_line;
} (while $running);
I get characters like below (the =(n) is the ascii number of the char)
NL = (10) e = (101) ˙ = (255)
or
NUL = (0) " = (34) ˙ = (255)
Interestingly enough I am using 7 bit ascii so I should only be seeing
characters upto ascii 127 as this is the highest number you can transmit in one
7bit byte. This leads me to beleive that the ascii 255 comes from the modem
which I beleive represents the line going down. However I can trap that but I
keep getting a few sets of several characters before I can get an empty buffer.
The code I have used to down the line is below. My question is how can I
reset the modem so when I start up again the buffers are completely clear.
sub modem_write {
my $string = shift;
aborter ("write modem:no string to send") if (! (defined $string) );
my $len_string = length($string);
my $sent_bytes;
eval { $sent_bytes=$modem_obj->write($string) };
if ($@) {
$dbg->$dbg_method ("write failed with $! ");
return;
} elsif (! (defined $sent_bytes) ) {
$dbg->$dbg_method("send 0 bytes");
return;
} elsif ($sent_bytes != $len_string ) {
$dbg->$dbg_method("send $sent_bytes but record is
$len_string");
return;
}
return 1;
} # modem_write
sub downline {
$dbg->$dbg_method("Downline the phone");
modem_write("$dle.$eot\r\n");
modem_write("+++");
sleep(3);
modem_write('ATZ\r\n\n'); # note sure about this one
sleep(3);
$modem_status = 'Offline';
eval { $modem_obj->close; };
undef $modem_obj;
} # end of downline
Thanks in advance
Phil
Live the Journey!
For each destination is but a doorway to another!
------------------------------
Date: Fri, 18 May 2001 10:27:36 +0100
From: Malte Ubl <ubl@schaffhausen.de>
Subject: module for umlauts
Message-Id: <3B04EB08.A56CE305@schaffhausen.de>
Hi,
does anybody know a module to convert umlauts to their html entities
like this ä => ä. I've been doing this using simple regular expressions
for a long time but the problem is that the umlaut can be in different encodings,
so the problem is not that trivial, especially if you dont know the encoding
in advance.
Looks like a perfect job for a module but I didnt find one on CPAN. Does anybody
here know of a module or some other elegant way of doing this?
Thanx,
->malte
------------------------------
Date: 18 May 2001 08:34:40 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: module for umlauts
Message-Id: <slrn9g9nnd.v29.rgarciasuarez@rafael.kazibao.net>
Malte Ubl wrote in comp.lang.perl.misc:
} Hi,
}
} does anybody know a module to convert umlauts to their html entities
} like this ä => ä. I've been doing this using simple regular expressions
} for a long time but the problem is that the umlaut can be in different encodings,
} so the problem is not that trivial, especially if you dont know the encoding
} in advance.
}
} Looks like a perfect job for a module but I didnt find one on CPAN. Does anybody
} here know of a module or some other elegant way of doing this?
What's the problem with HTML::Entities ?
--
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
------------------------------
Date: Fri, 18 May 2001 08:35:58 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Nettiquete (Re: Help with File Upload -CGI.pm)
Message-Id: <92n9gt4cml040ef40t45pg7683qp6qig42@4ax.com>
Benjamin Goldberg wrote:
>4) Why are you using what is essentially a global variable for your
>filehandle? It's not exactly *harmful* here, but good programming style
>is to use local variables whenever possible, and global variables as
>infrequently as possible.
>To fix this, replace:
> open (OUTFILE, ">$SAVE_DIR/$filename");
>With:
> my $outfile = gensym;
> open( $outfile, ">", "$SAVE_DIR/$filename" ) or die;
>Don't forget to put "use Symbol;" at the top of your program, and to
>replace instances of OUTFILE with $outfile. You probably don't *really*
>need to put a value in $outfile before the open, as open should do that
>for you, but it's better style.
Do you like obfuscation, or what? :-)
Instead of using such abstract notions as Symbol.pm and gensym(), why
nort make this readable, and use a module written for this and related
purposes:
use FileHandle;
my $fh = new FileHandle;
open $fh, ">", "$SAVE_DIR/$filename"
or die "Can't write to file: $!";
From 5.6 on, you can even drop the reference to the module, and simply
do:
open my $fh, ">", "$SAVE_DIR/$filename"
or die "Can't write to file: $!";
Perl knows you want to use this undefined variable as a filehandle, and
stuffs a new one in there while it opens the file.
Printing to the file is as easy as
print $fh "Hello, world!\n";
DON'T put a comma after the $fh.
--
Bart.
------------------------------
Date: Fri, 18 May 2001 05:16:21 +0200
From: Heiko Brey <cico@icomag.de>
Subject: non-blocking "print" on a client socket ??
Message-Id: <3B049405.C86B191@icomag.de>
Hi,
I have written a little server (my first try in socket programming)
and I'd like to build an interesting application with this.
I want to connect a webcam to this server and serve the picture data
to MANY people but I only want to transfer the Picturedata ONCE from
the camera. The server should broadcast the picturedata to all
connecting client sockets.
I got now something that nearly works (but seems to be far from beeing
nice code! :-) )
There also might be a problem:
From time to time one of the connected client sockets (and I don't know
why) seems to block the server itself then also blocks and no other
client gets picturedata anymore!
Now my question:
Is there a possibility to make the "print" on the client socket
something like "non-blocking" ? Or does anyone have a better
solution for this ? I attached the "server" code at the bottom
of this message. Any help will be welcome! Maybe someone knows
about some docs ?! :-)
Thank you! Heiko
P.S. This code is based on the multiplexing server at:
http://www.cs.uno.edu/~golden/teach.html
=============== CODE ==========================================
#!/usr/bin/perl
use Socket;
use LWP::Simple;
sub readline {
my $filehandle = $_[0];
my $c='';
my $retstr='';
my $endoffile=0;
while ($c ne "\n" && ! $endoffile) {
if (sysread($filehandle, $c, 1) > 0) {
$retstr = $retstr . $c;
}
else {
$endoffile=1;
}
}
return $retstr;
}
($port) = @ARGV;
$port = 2345 unless $port;
($name, $aliases, $protocol) = getprotobyname('tcp');
if ($port !~ /^\d+$/) {
($name, $aliases, $port) = getservbyport($port, 'tcp');
}
print "Listening on port $port...\n";
socket(S,AF_INET,SOCK_STREAM,$proto) || die "socket : $!";
$sockaddr = 'S n a4 x8';
$this = pack($sockaddr, AF_INET, $port, "\0\0\0\0");
bind(S, $this) || die "bind : $!";
listen(S, 2500) || die "listen: $!";
select(S);
$| = 1;
select(STDOUT);
$con = 0;
while (1) {
$rin = $win = $ein = '';
vec($rin, fileno(S), 1) = 1;
foreach (@sockets) {
if ($_ ne "") {
vec($rin, fileno($_), 1) = 1;
}
}
print "Waiting...\n";
($numready, $timeleft) = select($rout=$rin, undef, undef, undef);
print "Someone's knocking!!\n";
$content =
get("http://192.168.2.5/cgi-bin/jpg/image.cgi?resolution=320x240");
$file_size = length($content);
if (vec($rout, fileno(S), 1)) {
print "New connection.\n";
$con++;
$sockets[$con - 1] = "NS".$con;
($addr = accept($sockets[$con - 1], S)) || die $!;
select($sockets[$con - 1]);
$|=1;
select(STDOUT);
($af,$port, $inetaddr) = unpack($sockaddr, $addr);
@inetaddr = unpack('C4', $inetaddr);
} else {
$sockcount = 0;
foreach (@sockets) {
$sockcount++;
$thesocket = $_;
if (vec($rout, fileno($thesocket), 1)){
$data = &readline($thesocket);
if (! length($data)) {
print "Bye to client on socket $thesocket.\n";
close($thesocket);
$sockets[$sockcount-1] = "";
}
else {
print "Received from client $sockcount: $data",
length($content);
if ( !length($content) ) {
close($thesocket);
print " : Laenge NULL!\n";
} else {
print $thesocket "--myboundary\nContent-Type:
image/jpeg\nContent-length: ",$file_size,"\n\n";
print $thesocket $content, "\n\n";
print " : Laenge nicht NULL\n";
}
}
}
}
}
}
------------------------------
Date: Fri, 18 May 2001 08:51:31 +0100
From: dave@mo-seph.com (Dave Murray-Rust)
Subject: Re: tie, FETCH and list context
Message-Id: <slrn9g9l43.ign.dave@flop.localnet>
On 16 May 2001 17:03:04 -0400, Joe Schaefer <joe+usenet@sunstarsys.com> wrote:
>dave@mo-seph.com (Dave Murray-Rust) writes:
>
>[... about tied hashes ...]
>
>> So a) Is it FETCH always in scalar context?
>
>Pretty much- and it makes sense to do so. Otherwise stuff like
>each() and values() could fail to work as documented.
Understand. Is this documented anywhere?
>
>Why are you parsing the CGI parameters yourself? Apache::Request [1]
>will do this for you, and calling
Because I'm stupid? ;)
> my $apr = Apache::Request -> new;
>
> my @vals = $apr -> param('checkbox_key');
>
>does exactly what you seem to want. Note that this is the same as
Yes, this is exactly what I want. I don't quite know how I failed to
find it - I was just feeling a bit deluged by the number of apache
modules; it looked like I could spend the next couple of months
checking out different ways to do things.
>[1] sorry for shilling a package that I work on, but IMO towing the
> CGI.pm party line isn't so wonderful in a mod_perl environment.
Yeah, it seemed wrong to me too, although I wasn't quite sure why.
> Besides, we're trying to get a new release together and more beta
> testers are needed. Any volunteers? :-)
Is this for the AxKit bundle? (That's where I found the
Apache::Request) If so, it looks (on a quick reading) like it does a
large chunk of what I want. I'll have to see how much I can use on a
project already half done.
Thanks for the help,
Dave
------------------------------
Date: Thu, 17 May 2001 23:55:34 +0100
From: Matt Sergeant <matt@sergeant.org>
Subject: Re: transform html to xhtml
Message-Id: <3B0456E6.DF53A82D@sergeant.org>
"Marco Tölle" wrote:
>
> Hi !
>
> Can anyone tell me how to transform HTML to XHTML using Perl ?
> Is there a module ?
Yes. XML::PYX ships with a pyxhtml script that uses HTML::TreeBuilder.
So you can do:
% pyxhtml file.html | pyxw > file.xhtml
--
<Matt/>
/|| ** Founder and CTO ** ** http://axkit.com/ **
//|| ** AxKit.com Ltd ** ** XML Application Serving **
// || ** http://axkit.org ** ** XSLT, XPathScript, XSP **
// \\| // ** mod_perl news and resources: http://take23.org **
\\//
//\\
// \\
------------------------------
Date: 18 May 2001 11:19:08 +0200
From: Walter Hafner <hafner-usenet@ze.tu-muenchen.de>
Subject: Re: URGENT: CGI program wanted!
Message-Id: <srjpud7ypyr.fsf@w3proj1.ze.tu-muenchen.de>
Uri Guttman <uri@sysarch.com> writes:
> >>>>> "WH" == Walter Hafner <hafner-usenet@ze.tu-muenchen.de> writes:
>
> WH> Uri Guttman <uri@sysarch.com> writes:
> >> that web site is off limits. you just marked yourself as a disciple of
> >> the matt wright school of bad perl programming.
>
> WH> Care to give an explanation of your statement?
>
> go to groups.google.com and search for his name in this group. his
> scripts were written when he was in high school, are notorious for their
> low quality, bugs and security holes, etc. so anyone recommending them
> obviously does not know about decent perl and so their opinions on other
> perl matters take on a decidedly lower ranking.
>
> clear enough? matt's code stinks. anyone who associates themselves with
> his code takes on that skunky scent.
Sorry, but I don't get this.
Just because a bad coder (just for argument - I don't know him and his
code) starts a site, you can't condemn the whole site.
Say, a bad coder starts an operating system. Mostly by buying all he
needs and reassembling it. Over the years the operating system gets used
more and more and more and more applications are developed. Some of the
applications are good, some are very good, while the underlying
technology is still bad. You surely won't say that every programmer who
does applications based on this bad code is a bad coder himself. And no,
I don't think this is a Dilbert type analogy. :-)
In the meantime there are roughly 2000 Perl scripts available on
cgi-resources. I tried a few of them and found the majority quite
useful. E.g., I wouldn't program my own umptieth greeting card program
but use an existing one. And instead of searching the whole web myself
I'd try the largest CGI index I know about.
Note: I don't have any script from that site in production right now,
but I surely would if there was the need and the script did the job
right.
If that makes me a bad coder in your opinion, well ...
-Walter
------------------------------
Date: Fri, 18 May 2001 08:00:52 GMT
From: dave@mo-seph.com (Dave Murray-Rust)
Subject: Re: use an expanding set of modules
Message-Id: <slrn9g9llj.io0.dave@flop.localnet>
On 15 May 2001 17:43:48 GMT, Anno Siegel
<anno4000@lublin.zrz.tu-berlin.de> wrote:
>
>Perligata! A horror trip in stereo, where Perl and Latin scream left
>and right under torture. I love it! In small doses.
Wow! I've never seen anything quite like this. Does anyone use it, ors
it "just" fun? It seems like such a nice idea to have statements not
rely on token order. Makes me wish I knew latin ;)
------------------------------
Date: 18 May 2001 09:13:35 +0100
From: jcp@myrtle.ukc.ac.uk (J.C.Posey)
Subject: Re: What's wrong with my scope?
Message-Id: <jko1ypn2hxs.fsf@myrtle.ukc.ac.uk>
[apologies if this was sent twice]
mjd@plover.com (Mark Jason Dominus) writes:
> In article <jkovgn01aed.fsf@myrtle.ukc.ac.uk>,
> J.C.Posey <jcp@myrtle.ukc.ac.uk> wrote:
> >> > $urls{$fields[1]} += [$fields[2], $fields[3], $fields[4], $fields[5]];
> >
> >Okay, I was under the impression to create a hash with an array you did:
> >
> > my $hash{"a_key"} = ["a value", "another", $my_var];
>
> You can. (Except for the 'my' here, which is wrong.)
>
> But += means to do addition of numbers. An array is not a number.
Thanks Mark. I must have been brain dead yesterday. It wasn't until last
night that I realized I must not have made myself clear enough--apologies
to Anno as well.
What I was hoping to accomplish was to TOTAL fields across records for each
unique key (which in this case is a url), so that each time the same url
was located, it would add all four fields to their respective total. I
thought this would be a quick way to do it...but is obviously flawed.
> Have you read the reference tutorial at
> http://perl.plover.com/FAQs/References.html
> ? You might find it helpful.
I have browsed it before, but will give it another good reading now. Thanks.
Jake
------------------------------
Date: 18 May 2001 08:03:18 GMT
From: vek@pharmnl.ohout.pharmapartners.nl (Villy Kruse)
Subject: Re: Writing to Unix passwd
Message-Id: <slrn9g9lq5.ou6.vek@pharmnl.ohout.pharmapartners.nl>
On 18 May 2001 01:42:17 GMT, Alan Barclay <gorilla@elaine.furryape.com> wrote:
>
>encrypt(1) is a bi-directional encryption scheme based upon The Enigma
>Machine.
>
Though that the name of that program was crypt(1).
Villy
------------------------------
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 929
**************************************