[6296] in Perl-Users-Digest
Perl-Users Digest, Issue: 918 Volume: 7
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Feb 9 09:07:11 1997
Date: Sun, 9 Feb 97 06:00:22 -0800
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, 9 Feb 1997 Volume: 7 Number: 918
Today's topics:
Re: 4-arg select() and buffered I/O question (Andrew M. Langmead)
Re: [Q:] whitespace (Nathan V. Patwardhan)
Re: [Q:] whitespace (Tad McClellan)
Re: ANNOUNCEMENT: Perl documentation and FAQ discontinu (Eric Harley)
Re: apedding to a list... (Brian L. Matthews)
Help is anyone any good with sockets (Ruth Ann Davidson CS93)
How do I make a Perl program a .exe (Dave)
Re: How do I make a Perl program a .exe (Nathan V. Patwardhan)
Loops in perl (Thomas Patrick Bailey)
Re: Loops in perl (Mike Stok)
Re: need a simple script (Eric Harley)
Re: Need help - just starting perl (Dave)
Re: Need help - just starting perl (Dave)
Re: Need help - just starting perl <prozario@easyway.net>
Re: Need help - just starting perl <prozario@easyway.net>
Re: Need help - just starting perl (Tad McClellan)
Re: Tying hash of arrays to SDBM does not work: why? (Brian L. Matthews)
Re: Tying hash of arrays to SDBM does not work: why? <fawcett@nynexst.com>
Re: Using sockets to connect to daemon - code wanted. (Mike Stok)
Win32::ODBC for build 303 <tsw@pvo.com>
You were there:1981 (Was: Using exec-Why won't this wor (Ann O. Ying)
zero padding <peraphon@ctl77.nectec.or.th>
Re: zero padding <domo@tcp.ip.lu>
Digest Administrivia (Last modified: 8 Jan 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 9 Feb 1997 13:32:09 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: 4-arg select() and buffered I/O question
Message-Id: <E5C89M.519@world.std.com>
ric@isl.sri.com (Ric Steinberger) writes:
>The Camel book warns: "Mixing buffered I/O (like read or
><HANDLE>) with four-argument select is asking for trouble. Use
>sysread instead."
>Could someone explain exactly why? I have been using select()
>for sometime to tell me when I can read a socket or pipe handle.
>When select() indicates that the filehandle can be read without
>blocking, I have been using the while(defined($line = <HANDLE>))
>style to read it, with no [known] ill effects.
There are two cases where select and the buffered input operators fall
over each other.
1. An incomplete line is sent to the process. select() will then
return because there is input. The diamond operator will then block on
a second sysread() because it wants to combine as many sysread()s as
necessary to return a full line.
2. Two or more complete lines are sent to the process in one
syswrite() operation. select() will only report once that there is
data to sysread(). The <> operator will read all lines of input,
return the first and buffer the rest. select() will now return false
for data to be read, because there is no data waiting to be read from
the pipe, it is all in the filehandles buffers.
--
Andrew Langmead
------------------------------
Date: 9 Feb 1997 03:40:11 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: [Q:] whitespace
Message-Id: <5djgur$1fp@fridge-nf0.shore.net>
Nigel Byrnes (njb@cs.bham.ac.uk) wrote:
: I was wondering if anyone here could tell me how to strip out the
: whitespace out of a string like the one below:
Ahh, in need of documentation, eh? This question is asked frequently
and a quick search of www.dejanews.com confirms this. I would also
suggest that you look at http://www.perl.com/perl, which has been one
of the world's best kept secrets *until now*, paralleled only by, say,
the Helsinki Formula, or those "cooking stones" they adverstise on
the infomercials. :-)
: $string1 = " floor : {1,2,3,4,5};" or
: $string2 = "reset : 0;"
Hint: It involves s/// =~ and \s (the perl space notation) - if you read
some documentation, or just give it a try, I suspect that you'll succeed.
Good luck!
--
Nathan V. Patwardhan
nvp@shore.net
------------------------------
Date: Sun, 9 Feb 1997 00:22:02 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: [Q:] whitespace
Message-Id: <aeqjd5.ga2.ln@localhost>
Nigel Byrnes (njb@cs.bham.ac.uk) wrote:
: I was wondering if anyone here could tell me how to strip out the
: whitespace out of a string like the one below:
: $string1 = " floor : {1,2,3,4,5};" or
: $string2 = "reset : 0;"
: A property worth noting is that the whitespace occurs before the colon.
^^^^^^^^^^^^
Why is that worth noting?
Whitespace also occurs _after_ the colon.
Whitespace also also occurs at the beginning of the string (sometimes).
You asked to "strip out the whitespace". That's what this does:
s/ //g;
--
Tad McClellan SGML Consulting
Tag And Document Consulting Perl programming
tadmc@flash.net
------------------------------
Date: Sun, 09 Feb 1997 00:00:08 -0800
From: erich@powerwareintl.com (Eric Harley)
Subject: Re: ANNOUNCEMENT: Perl documentation and FAQ discontinued
Message-Id: <erich-0902970000080001@ppp-207-104-16-7.snrf01.pacbell.net>
In article <fm7gd5.rg.ln@localhost>, tadmc@flash.net (Tad McClellan) wrote:
> Charles DeRykus (ced@bcstec.ca.boeing.com) wrote:
> : In article <5de9vt$a5r@nova.dimensional.com>,
> : Michael Fuhr <mfuhr@dimensional.com> wrote:
> : >Tom Christiansen <tchrist@mox.perl.com> writes:
> : >
> : >>As of the next release of Perl, no documentation or examples will
> : >>be shipped, since no one reads them anyway. Furthermore, the FAQ
> : >>is also discontinued. Please remove copies of any of this documentation
> : >>wherever you may find it, since it's obvious from the postings in this
> : >>group that it has never done a bit of good.
> : >
> : >Excellent! I was getting really tired of telling people to RTFM; now
> : >I won't have to. Say, could we recall all the unread Camels and have a
> : >weenie-roast to celebrate?
>
> : Tom's a vegetarian I think.
>
> : I'll bet he'll agree to roast something though...
>
>
> A book burning for anything with three or less camels ;-)
>
>
Lets get that fire upto 451 !
------------------------------
Date: 9 Feb 1997 02:05:34 GMT
From: blm@chinook.halcyon.com (Brian L. Matthews)
Subject: Re: apedding to a list...
Message-Id: <5djbde$tm1$1@brokaw.wa.com>
In article <32FD0F49.167E@irc.chmcc.org>,
Phil Williams <williams@irc.chmcc.org> wrote:
|@junk = (@junk, $newjunk) if grep($newjunk, @junk) eq 0;
|Is there a better way?
Uh, yeah. First, to append to a list, use push:
push (@junk, $newjunk);
Second, the easiest way to only have things in a list once is to
use a hash:
$junk{$newjunk} = 1;
Then to get the list, just use keys %junk.
I suggest reading perlfunc and perldata. This is all explained pretty
well and in more detail therein.
Brian
--
Brian L. Matthews Illustration Works, Inc.
For top quality, stock commercial illustration, visit:
http://www.halcyon.com/artstock
------------------------------
Date: 9 Feb 1997 13:47:32 GMT
From: rdavidso@cs.strath.ac.uk (Ruth Ann Davidson CS93)
Subject: Help is anyone any good with sockets
Message-Id: <5dkkhk$dkf@dunlop.cs.strath.ac.uk>
I am trying to download a web page to a file through
a perl script, does anyone know how i can do this
Please Help i am at my wits end
Thanks
Ruth
email- rdavidso@cs.strath.ac.uk
------------------------------
Date: Sun, 09 Feb 1997 02:36:40 GMT
From: djk490s@nic.smsu.edu (Dave)
Subject: How do I make a Perl program a .exe
Message-Id: <32fd36fb.9842493@news.abilnet.com>
Let's say I write a simple script, call it renames.pl that runs on
Win95. I want to make it an executable, call it renames.exe. Is this
possible and how do I do it?
If anyone knows the answer to this, I would love to know! I really
want to know for a cgi that I have running on a NT server. I want to
make it executable to protect the source code from being read. I
don't want the source code available because I don't want people
looking for security holes. In anycase, I could even think of more
applications than this one for having my Perl programs turned into
.exe files.
Regards,
David K.
djk490s@nic.smsu.edu
------------------------------
Date: 9 Feb 1997 03:46:30 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: How do I make a Perl program a .exe
Message-Id: <5djham$1fp@fridge-nf0.shore.net>
Dave (djk490s@nic.smsu.edu) wrote:
: Let's say I write a simple script, call it renames.pl that runs on
: Win95. I want to make it an executable, call it renames.exe. Is this
: possible and how do I do it?
To my knowledge, the existing Perl compiler doesn't work on NT - I've
not heard any success stories.
Your Perl distribution probably comes with a file in the docs directory
called "perlembed," and/or "perlxs". Read them, follow their instructions,
and give it a try.
: If anyone knows the answer to this, I would love to know! I really
: want to know for a cgi that I have running on a NT server. I want to
: make it executable to protect the source code from being read. I
If your server is configured properly, people will *never* be able to see
the source code, because your script is sending everything to STDOUT.
: don't want the source code available because I don't want people
: looking for security holes.
Security holes are security holes. If your program is broken, a would-be
cracker will exploit its vulnerabilities, executable or not.
--
Nathan V. Patwardhan
nvp@shore.net
------------------------------
Date: 8 Feb 1997 23:19:24 GMT
From: baile934@harrier.csrv.uidaho.edu (Thomas Patrick Bailey)
Subject: Loops in perl
Message-Id: <5dj1ls$1p4$1@newshound.csrv.uidaho.edu>
I am fairly new to perl, but I have been doing ok in it. What I need to
know is how to do a simple loop.
A simple example would be very helpful.
thanks.
baile934@uidaho.edu
-patman
------------------------------
Date: 9 Feb 1997 13:44:27 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: Loops in perl
Message-Id: <5dkkbr$edp@news-central.tiac.net>
In article <5dj1ls$1p4$1@newshound.csrv.uidaho.edu>,
Thomas Patrick Bailey <baile934@harrier.csrv.uidaho.edu> wrote:
>I am fairly new to perl, but I have been doing ok in it. What I need to
>know is how to do a simple loop.
>
>A simple example would be very helpful.
Perl has loop constructs similar to those found in C with a few shell like
features. These include things like
for ($x = 0; $x < 10; $x++) {
print "$x\n";
}
foreach $x (0 .. 9) {
print "$x\n";
}
$x = 0;
while ($x < 10) { # or until ($x >= 10) { maybe...
print "$x\n";
$x++;
}
last, next and redo are loop controls which let you escape from a loop, go
to the start of the next iteration or redo the current iteration.
The perlsyn man page which is distributed with perl 5 covers perl's
looping constructs, as does Randal Schwartz's book Learning Perl and the
camel book (Programming Perl by Larry Wall, Tom Christiansen and Randal
Schwartz) both books are published by O'Reilly. All of these sources
cover it more thoroughly and correctly than this post, but I hope that
there's enough here to help you get started,
Mike
--
mike@stok.co.uk | The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/ | PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/ | 65 F3 3F 1D 27 22 B7 41
stok@psa.pencom.com | Pencom Systems Administration (work)
------------------------------
Date: Sun, 09 Feb 1997 00:08:16 -0800
From: erich@powerwareintl.com (Eric Harley)
Subject: Re: need a simple script
Message-Id: <erich-0902970008170001@ppp-207-104-16-7.snrf01.pacbell.net>
In article <5dga2t$3fa@news.xmission.com>, scotkris@aros.net (scott
mcgrew) wrote:
> could anyone tell me where to get a script that does the following.
>
> takes form input and writes it to a txt file.
>
> I want to update a java applet text ticker without going in and
> writing the new data in notebook, ftp'ing etc.
>
> it would be simpler to just go to a webpage and type it in.
> but I don't write cgi.
>
> anyone help?
>
> scott
> scotkris@aros.net
Okay here it is in perl4 with the cgi-lib.pl file (Gasp!)
require "cgi-lib.pl"; #No magic here!
&ReadParse; #Get those forms into an associative array
foreach $key (sort keys %in){ #You can take the sort out if it rubs you the
#wrong way
print "$in{$key}\n"; #You should edit this reflecting what format your
#going to use
}
Hope this helps!
------------------------------
Date: Sun, 09 Feb 1997 02:29:54 GMT
From: djk490s@nic.smsu.edu (Dave)
Subject: Re: Need help - just starting perl
Message-Id: <32fd3346.8893779@news.abilnet.com>
On Sat, 08 Feb 1997 07:31:37 -0800, Konrad Rokicki
<acidik@geocities.com> wrote:
>I'd like to learn Perl but I could someone help me out with my first
>script? I do some html editing and my files are all named .htm. So when
>I go to put them on the server I have to rename them all one by one. I'd
>like to write a script to rename all the .htm files in any directory to
>.html files. Here's what I have so far..
>
>#! /usr/local/bin/perl
># htm2html - Fast multifile rename
>
>$addl = "l";
>
>'ls *.htm > temp001';
>open (DATFILE, "temp001");
> while (<STDIN>) {
> if (/*.*/) {
># ^^^^^^^^^
># I'm really unsure here.. how do I extract each line from the txt file
># # and use it as a variable?
>
>$1 = $file;
>}
> foreach $file
> 'mv $file $file+$addl';
># ^^^^^^^^^^^
># I'm confused here too..
>
>These are the biggest problem sfor me..
>Don't waste your time on the small syntax errors.. I'll figure them out
>Thanks a LOT. Konrad.
Here is some code that will do the trick for you!
#!/usr/local/bin/perl
$path="/internet/temp";
opendir(DIR, $path) || die "Can't open the directory";
while ($file = readdir(DIR)) {
$new=$file;
if ($new =~ /(\.htm)$/) { #means if $new ends with .htm then:
rename("$path/$file","$path/$new");
}
}
close(DIR);
That's it! Have Fun. Here are some good URLs for learning Perl:
http://www-cgi.cs.cmu.edu/cgi-bin/perl-man
http://www.bluemarble.net/~scotty/Perl/index.html
http://agora.leeds.ac.uk/Perl/start.html
And one more thing. Matt's Script Archive. Matt is great. He offers
many of his Perl programs for free download, and gives the source
complete with instructions. He also documents his code very well, and
follows patterns smoothly. Here's his URL:
http://worldwidemart.com/scripts/
Have a good day. I hope I have helped a little.
Dave.
------------------------------
Date: Sun, 09 Feb 1997 02:43:38 GMT
From: djk490s@nic.smsu.edu (Dave)
Subject: Re: Need help - just starting perl
Message-Id: <32fd396f.10470062@news.abilnet.com>
On Sun, 09 Feb 1997 02:29:54 GMT, djk490s@nic.smsu.edu (Dave) wrote:
>On Sat, 08 Feb 1997 07:31:37 -0800, Konrad Rokicki
><acidik@geocities.com> wrote:
>
>>I'd like to learn Perl but I could someone help me out with my first
>>script? I do some html editing and my files are all named .htm. So when
>>I go to put them on the server I have to rename them all one by one. I'd
>>like to write a script to rename all the .htm files in any directory to
>>.html files. Here's what I have so far..
>>
>>#! /usr/local/bin/perl
>># htm2html - Fast multifile rename
>>
>>$addl = "l";
>>
>>'ls *.htm > temp001';
>>open (DATFILE, "temp001");
>> while (<STDIN>) {
>> if (/*.*/) {
>># ^^^^^^^^^
>># I'm really unsure here.. how do I extract each line from the txt file
>># # and use it as a variable?
>>
>>$1 = $file;
>>}
>> foreach $file
>> 'mv $file $file+$addl';
>># ^^^^^^^^^^^
>># I'm confused here too..
>>
>>These are the biggest problem sfor me..
>>Don't waste your time on the small syntax errors.. I'll figure them out
>>Thanks a LOT. Konrad.
>
>Here is some code that will do the trick for you!
>
>#!/usr/local/bin/perl
>$path="/internet/temp";
>opendir(DIR, $path) || die "Can't open the directory";
>while ($file = readdir(DIR)) {
> $new=$file;
> if ($new =~ /(\.htm)$/) { #means if $new ends with .htm then:
# whoops, forgot one important thing. This line:
$new .= "l"; #means add an l to the end of $new
> rename("$path/$file","$path/$new");
> }
>}
>close(DIR);
>
>That's it! Have Fun. Here are some good URLs for learning Perl:
>http://www-cgi.cs.cmu.edu/cgi-bin/perl-man
>http://www.bluemarble.net/~scotty/Perl/index.html
>http://agora.leeds.ac.uk/Perl/start.html
>
>And one more thing. Matt's Script Archive. Matt is great. He offers
>many of his Perl programs for free download, and gives the source
>complete with instructions. He also documents his code very well, and
>follows patterns smoothly. Here's his URL:
>
>http://worldwidemart.com/scripts/
>
>Have a good day. I hope I have helped a little.
>
>Dave.
------------------------------
Date: 9 Feb 1997 03:54:53 GMT
From: "Peter Rozario" <prozario@easyway.net>
Subject: Re: Need help - just starting perl
Message-Id: <01bc163c$64d28ba0$f6b2e8cd@prozario.easyway.net>
I'm not sure if I understand the question. Are you trying to
rename bunch of files from .htm extension to .html. If so,
why don't you use something like "rename *.htm *.html". This
will work on newer DOS ver and unix.
If you would rather use perl, it would look something like:
#!/usr/local/bin/perl
$addl = "l";
foreach $file (<*.htm>) # for all file with .htm extension in
# present dir
{
$filenew = $file . "l"; # the new file name
rename ("$file", "$filenew"); # rename
}
If you would rather process each file, line by line, use the
following. It loops through each .htm files in present directory.
It opens the first file, and then goes through each line, one
by one. Then it continues with next file.
foreach $file (<*.htm>) # for all file with .htm extension in
# present dir
{
open (MYFILE, $file); # open the file
while ($line = <$file>) # read one line at a time
{
# here $line will give you each line of the text file
# this is how you access each line of your files
}
close (MYFILE);
}
Konrad Rokicki <acidik@geocities.com> wrote in article
<32FC9C59.66E0@geocities.com>...
> I'd like to learn Perl but I could someone help me out with my first
> script? I do some html editing and my files are all named .htm. So when
> I go to put them on the server I have to rename them all one by one. I'd
> like to write a script to rename all the .htm files in any directory to
> .html files. Here's what I have so far..
>
> #! /usr/local/bin/perl
> # htm2html - Fast multifile rename
>
> $addl = "l";
>
> 'ls *.htm > temp001';
> open (DATFILE, "temp001");
> while (<STDIN>) {
> if (/*.*/) {
> # ^^^^^^^^^
> # I'm really unsure here.. how do I extract each line from the txt file
> # # and use it as a variable?
>
> $1 = $file;
> }
> foreach $file
> 'mv $file $file+$addl';
> # ^^^^^^^^^^^
> # I'm confused here too..
>
> These are the biggest problem sfor me..
> Don't waste your time on the small syntax errors.. I'll figure them out
> Thanks a LOT. Konrad.
>
------------------------------
Date: 9 Feb 1997 04:03:51 GMT
From: "Peter Rozario" <prozario@easyway.net>
Subject: Re: Need help - just starting perl
Message-Id: <01bc163d$a6717200$f6b2e8cd@prozario.easyway.net>
use something like:
$addl = "l";
foreach $file (<.\*.htm>) # for each file with .htm extension
# in current directory
{
$filenew = $file . $addl; # new filename
rename ("$file", "$filenew"); # rename
}
To access each files, line by line, use:
foreach $file (<.\*.htm>) # for each file with .htm extension
# in current directory
{
open (MYFILE, $file); # open a file
while $line (MYFILE) # read one line after another
{
# here $line will give you access to lines of the .htm files
}
close (MYFILE);
}
Konrad Rokicki <acidik@geocities.com> wrote in article
<32FC9C59.66E0@geocities.com>...
> I'd like to learn Perl but I could someone help me out with my first
> script? I do some html editing and my files are all named .htm. So when
> I go to put them on the server I have to rename them all one by one. I'd
> like to write a script to rename all the .htm files in any directory to
> .html files. Here's what I have so far..
>
> #! /usr/local/bin/perl
> # htm2html - Fast multifile rename
>
> $addl = "l";
>
> 'ls *.htm > temp001';
> open (DATFILE, "temp001");
> while (<STDIN>) {
> if (/*.*/) {
> # ^^^^^^^^^
> # I'm really unsure here.. how do I extract each line from the txt file
> # # and use it as a variable?
>
> $1 = $file;
> }
> foreach $file
> 'mv $file $file+$addl';
> # ^^^^^^^^^^^
> # I'm confused here too..
>
> These are the biggest problem sfor me..
> Don't waste your time on the small syntax errors.. I'll figure them out
> Thanks a LOT. Konrad.
>
------------------------------
Date: Sun, 9 Feb 1997 00:18:15 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Need help - just starting perl
Message-Id: <77qjd5.ga2.ln@localhost>
That would be a good exercise for learning perl.
However, if you just want to get them renamed, and you have
access to the Unix shell, then:
for file in *.htm
do
mv $file ${file}l
done
OR
perl -e 'while ($_=shift) {rename $_, "${_}l"}' *.htm
OR
-------------
#! /usr/bin/perl -w
# add_ell
#
# invoke: add_ell *.htm
while ($_=shift) {
rename $_, "${_}l";
}
-------------
Konrad Rokicki (acidik@geocities.com) wrote:
: I'd like to learn Perl but I could someone help me out with my first
: script? I do some html editing and my files are all named .htm. So when
: I go to put them on the server I have to rename them all one by one. I'd
: like to write a script to rename all the .htm files in any directory to
: ..html files. Here's what I have so far..
: #! /usr/local/bin/perl
: # htm2html - Fast multifile rename
: $addl = "l";
: 'ls *.htm > temp001';
: open (DATFILE, "temp001");
: while (<STDIN>) {
: if (/*.*/) {
: # ^^^^^^^^^
: # I'm really unsure here.. how do I extract each line from the txt file
: # # and use it as a variable?
: $1 = $file;
: }
: foreach $file
: 'mv $file $file+$addl';
: # ^^^^^^^^^^^
: # I'm confused here too..
: These are the biggest problem sfor me..
: Don't waste your time on the small syntax errors.. I'll figure them out
: Thanks a LOT. Konrad.
--
Tad McClellan SGML Consulting
Tag And Document Consulting Perl programming
tadmc@flash.net
------------------------------
Date: 9 Feb 1997 01:58:31 GMT
From: blm@chinook.halcyon.com (Brian L. Matthews)
Subject: Re: Tying hash of arrays to SDBM does not work: why?
Message-Id: <5djb07$sod$1@brokaw.wa.com>
In article <32FCE880.41C6@mips.biochem.mpg.de>,
Dmitrij Frishman <frishman@mips.biochem.mpg.de> wrote:
|I am trying to reproduce the SDBM example from the Camel book, p.493. It
|works for simple hashes, but does not work for a hash of arrays:
There's a couple of reasons this won't work without some help. First,
when you have a hash of arrays, what's really happening is that a
reference to the array is being stored in the hash, not the actual array
data itself. Second, a reference is sort of a pointer to the data, so
pulling it out of a file doesn't work.
There are a couple of modules that may help you. Look on CPAN for
FreezeThaw and Data::Dumper. They can flatten complex data structures
for storage and reconstruct them again when read back in.
Brian
--
Brian L. Matthews Illustration Works, Inc.
For top quality, stock commercial illustration, visit:
http://www.halcyon.com/artstock
------------------------------
Date: 08 Feb 1997 17:38:57 -0500
From: Tom Fawcett <fawcett@nynexst.com>
To: Dmitrij Frishman <frishman@mips.biochem.mpg.de>
Subject: Re: Tying hash of arrays to SDBM does not work: why?
Message-Id: <8jraiqexdq.fsf@nynexst.com>
Dmitrij Frishman <frishman@mips.biochem.mpg.de> writes:
> I am trying to reproduce the SDBM example from the Camel book, p.493. It
> works for simple hashes, but does not work for a hash of arrays:
>
> #!/usr/local/bin/perl
> use Fcntl;
> use SDBM_File;
> @Array = ( "one", "two", "three" );
> tie(%hash, SDBM_File, 'Op.dbmx', O_RDWR|O_CREAT, 0644);
> $hash{key} = [ @Array ];
> print $hash{key}[0]," ",$hash{key}[1]," ",$hash{key}[2],"\n";
> untie %hash;
>
>
> This script works properly if the tie and untie lines are commented out,
> i.e. for a normal hash in memory, but prints empty line if the tie amd
> untie lines are activated. Why does this happen?
SDBM (and every other DBM) files only work with hash values that are
strings. Their values will not store references properly, which is
what you're trying to do here.
There are several modules that get around this restriction.
Check out MLDBM in the CPAN:
MLDBM bdpO Transparently store multi-level data in DBM GSAR
> In general, is this approach usable for largish databases (e.g. 10000
> entries, 20 lines of 60 characters each)?
I use DB_File for databases about that large. If you know exactly how your
values are structured (20 lines by 60 chars) you don't really need MLDBM.
Just do something like:
@lines = unpack("A60"x20, $hash{$val});
-Tom
------------------------------
Date: 9 Feb 1997 13:22:18 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: Using sockets to connect to daemon - code wanted.
Message-Id: <5dkj2a$cq7@news-central.tiac.net>
In article <32FCB1B1.F96@aguecheek.demon.co.uk>,
kevin <kevin@aguecheek.demon.co.uk> wrote:
>I am having a little difficulty... rather, I am completely clueless
>about how to write a perl script for bi-directional communication over a
>socket. I realise this is elementary for most of you, but does anyone
>have/know where I can find some sample code (the socket clients in CPAN
>are read-only)...
If you have perl5 then the perlipc man page might be a place to look, or
the Sockets section of the Social Engineering chapter of the 2nd edition
of Programming Perl has client & server examples, or if you only have a
first edition of Programming Perl then the Interprocess Communication
section of the Real Perl Programs chapter has old client & server code.
Stealing the code from the man page and butchering it a bit you could save
this as server.pl and run it using
perl -T server.pl
Note that this is single threaded and uses <> to read from the socket.
This makes it quite easy for a rogue client to block the server. The man
page and the latest camel book describe how to make a forking server which
creates a new server process for each request, and the 4 argument select
can be used to sniff a socket to see if it can be read from without
blocking.
#!/usr/bin/perl -Tw
require 5.002;
use strict;
BEGIN { $ENV{PATH} = '/usr/ucb:/bin' }
use Socket;
use Carp;
sub logmsg { print "$0 $$: @_ at ", scalar localtime, "\n" }
my $port = shift || 2345;
my $proto = getprotobyname('tcp');
$port = $1 if $port =~ /(\d+)/; # untaint port number
socket(Server, PF_INET, SOCK_STREAM, $proto) || die "socket: $!";
setsockopt(Server, SOL_SOCKET, SO_REUSEADDR, pack("l", 1)) || die "setsockopt: $!";
bind(Server, sockaddr_in($port, INADDR_ANY)) || die "bind: $!";
listen(Server,SOMAXCONN) || die "listen: $!";
logmsg "server started on port $port";
my $paddr;
$SIG{CHLD} = \&REAPER;
for ( ; $paddr = accept(Client,Server); close Client) {
my($port,$iaddr) = sockaddr_in($paddr);
my $name = gethostbyaddr($iaddr,AF_INET);
logmsg "connection from $name [",
inet_ntoa($iaddr), "]
at port $port";
my $line = <Client>;
$line =~ s/[\r\n]*$//;
print Client "Hello there, $name, it's now ",
scalar localtime, " and you said '$line'\n";
}
__END__
Hope this helps,
Mike
--
mike@stok.co.uk | The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/ | PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/ | 65 F3 3F 1D 27 22 B7 41
stok@psa.pencom.com | Pencom Systems Administration (work)
------------------------------
Date: Sat, 08 Feb 1997 20:53:01 -0500
From: Thomas Winzig <tsw@pvo.com>
Subject: Win32::ODBC for build 303
Message-Id: <32FD2DFD.6D58@pvo.com>
Hello,
I've got build 303 of ActiveWare's Perl for Win32. I'm
trying to either find a version of Win32::ODBC recompiled
for build 303 (the latest I can find is for 302), or a
way to recompile it myself. I've got VC++ 4, but I can't
locate all of the Win32::ODBC headers that the odbc.cpp
source 'include's.
Any help/pointers would be greatly appreciated!! :-)
tia
-thomas
------------------------------
Date: Sat, 08 Feb 1997 23:12:59 -0800
From: annoying@<clip-this-out-if-replying>super.zippo.com (Ann O. Ying)
Subject: You were there:1981 (Was: Using exec-Why won't this work?)
Message-Id: <annoying-ya02408000R0802972312590001@snews.zippo.com>
In article <8c7mki7f4c.fsf@gadget.cscaper.com>, Randal Schwartz
<merlyn@stonehenge.com> wrote:
>Geez, these youngsters... back when I started playing with Usenet,
>every article stood a 5% chance of being lost on EACH HOP, and it
>could take days, even weeks to get from one host to another. Postings
>were actual *articles*, not just some little BBS-style questions.
>People *composed* them. rn(1) had to invoke a *separate text editor*,
>and it *took a while*.
>
Ah, the days when only an elite group of caffiene addicts shared their
thoughts on how Peter Gabriel sold out on his latest album in ten thousand
words or less...
*real* hackers reminisce about ARPAnet... :-)
------------------------------
Date: Sun, 9 Feb 1997 15:29:08 +0700
From: Peraphon Sophatsathit <peraphon@ctl77.nectec.or.th>
Subject: zero padding
Message-Id: <Pine.SUN.3.91.970209150441.7904A-100000@ctl77.nectec.or.th>
I am still fiddling with Perl and came across a string problem. Say I have:
$a = 1;
$b = "A";
I want '$a' to be zero padded to make it 9 (could be any size) character
long, then append it to '$b'. I blindly try:
$out = sprintf "%$b${a}";
and get 'A1' stored in '$out' rather than 'A000000001'. How do I go
about padding zeros to '$a' in order to make the number of leading zeros
plus the value of '$a' to be 9 (any) char long? That is, if '$a'
is equal to 234, the final result ($out) will be 'A000000234'.
Very much obliged,
Peraphon
------------------------------
Date: Sun, 09 Feb 1997 10:34:12 +0100
From: Dominic Dunlop <domo@tcp.ip.lu>
To: Peraphon Sophatsathit <peraphon@ctl77.nectec.or.th>
Subject: Re: zero padding
Message-Id: <32FD9A11.FA8@tcp.ip.lu>
Peraphon Sophatsathit wrote:
> I am still fiddling with Perl and came across a string problem. Say I have:
> $a = 1;
> $b = "A";
> I want '$a' to be zero padded to make it 9 (could be any size) character
> long, then append it to '$b'. I blindly try:
> $out = sprintf "%$b${a}";
> and get 'A1' stored in '$out' rather than 'A000000001'.
Try something similar to
perl -e '$a=1; $b="A"; printf "%s%09d\n", $b, $a'
To amplify, the answer's in your C environment's supplier's
documentation for the printf() family of functions: Perl's documentation
just points you at the supplier's documentation..
------------------------------
Date: 8 Jan 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Jan 97)
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.misc (and this Digest), send your
article to perl-users@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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
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 V7 Issue 918
*************************************