[23604] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 5811 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Nov 16 03:05:46 2003

Date: Sun, 16 Nov 2003 00:05:06 -0800 (PST)
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, 16 Nov 2003     Volume: 10 Number: 5811

Today's topics:
    Re: access win32 from unix? <mikee@mikee.ath.cx>
    Re: access win32 from unix? <jwillmore@remove.adelphia.net>
    Re: access win32 from unix? <wwonko@rdwarf.com>
    Re: accuracy problem <jurgenex@hotmail.com>
    Re: accuracy problem <jurgenex@hotmail.com>
    Re: accuracy problem <REMOVEsdnCAPS@comcast.net>
    Re: ack! problem <ewilhelm@somethinglike.sbcglobalDOTnet>
    Re: arrange form data in same order as on form <usenet@morrow.me.uk>
    Re: arrange form data in same order as on form <noreply@gunnar.cc>
    Re: binmode and the diamond operator <grazz@pobox.com>
    Re: Chomp doesn't work for me <mikeflan@earthlink.net>
    Re: Chomp doesn't work for me <mikeflan@earthlink.net>
    Re: Chomp doesn't work for me <usenet@morrow.me.uk>
    Re: Chomp doesn't work for me <mikeflan@earthlink.net>
    Re: Chomp doesn't work for me <REMOVEsdnCAPS@comcast.net>
        dbmopen question Default@User011011101101.net
    Re: Echo '*' chars instead of what's typed <usenet@morrow.me.uk>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Sun, 16 Nov 2003 02:13:47 -0000
From: Mike <mikee@mikee.ath.cx>
Subject: Re: access win32 from unix?
Message-Id: <vrdnarfc62qq6a@corp.supernews.com>

In article Gregory Toomey wrote:
> It was a dark and stormy night, and Mike managed to scribble:
> 
>> In article Toomey wrote:
>>> It was a dark and stormy night, and Mike managed to scribble:
>>> 
>>>> Given the need to monitor win32 (win2k and winxp) boxes from unix,
>>>> and given that there are modules to access win32 performance
>>>> and other data, and given that this data can be accessed accross
>>>> the network, is there a way using perl to access this data
>>>> from unix (i.e. a unix box asks a windows box how much disk
>>>> space remains, etc)?
>>>> 
>>>> Mike
>>> 
>>> You can run most of the CPAN modules on Win2k/winxp.
>>> 
>>> I was at a linux workshop yesterday & the sysdamin of a large retailer
>>> had http://cygwin.com/ installed on every windows PC. Cygwin has most of
>>> the unix tools available under windows & allows him to do all sorts of
>>> remote admin.
>>> 
>>> gtoomey
>>> 
>> 
>> What I'm searching for is a way to query a windows registery,
>> or the performance stats, or the services from unix across
>> the network. I'm not searching for cygwin or if I can run
>> a CPAN module on win32 itself.
>> 
>> Mike
> 
> I would presume standard unix commands like 'df' are available with cygwin to show disk space. The output from df is easily parseable.
> 
> gtoomey

I don't want to use cygwin. I want to issue a command on the
unix server that sends a request to the windows box asking
it it's disk space, it's event log entries, etc. I am searching
for something I can use from unix to directly query the
os facilities on windows.

Mike


------------------------------

Date: Sun, 16 Nov 2003 03:35:12 GMT
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: access win32 from unix?
Message-Id: <20031115223512.195c9083.jwillmore@remove.adelphia.net>

On Sun, 16 Nov 2003 02:13:47 -0000
Mike <mikee@mikee.ath.cx> wrote:
<snip>
> I don't want to use cygwin. I want to issue a command on the
> unix server that sends a request to the windows box asking
> it it's disk space, it's event log entries, etc. I am searching
> for something I can use from unix to directly query the
> os facilities on windows.

You could set up a client/server situation.  Run the client on the
boxes you want to monitor; run the server from the "master" box.  Have
the server contact the clients on a regular basis.

There are a few modules you could look over to aid in the task.  Start
with the various Net::* modules.

If you want something "pre-made", check out some of the open source
sites like http://freshmeat.net

HTH and have fun :-)

-- 
Jim

Copyright notice: all code written by the author in this post is
 released under the GPL. http://www.gnu.org/licenses/gpl.txt 
for more information.

a fortune quote ...
A copy of the universe is not what is required of art; one of the
damned things is ample.   -- Rebecca West 


------------------------------

Date: Sun, 16 Nov 2003 05:47:34 +0000 (UTC)
From: Louis Erickson <wwonko@rdwarf.com>
Subject: Re: access win32 from unix?
Message-Id: <bp731m$jst$1@holly.rdwarf.com>

James Willmore <jwillmore@remove.adelphia.net> wrote:
: On Sun, 16 Nov 2003 02:13:47 -0000
: Mike <mikee@mikee.ath.cx> wrote:
: <snip>
:> I don't want to use cygwin. I want to issue a command on the
:> unix server that sends a request to the windows box asking
:> it it's disk space, it's event log entries, etc. I am searching
:> for something I can use from unix to directly query the
:> os facilities on windows.

You might be able to get some of that information (disc space, CPU
usage, some performance data) from SNMP, but you have to install the
SNMP stuff on all the Windows boxes and configure it all.  And, please
don't use the default passwords.

: You could set up a client/server situation.  Run the client on the
: boxes you want to monitor; run the server from the "master" box.  Have
: the server contact the clients on a regular basis.

: There are a few modules you could look over to aid in the task.  Start
: with the various Net::* modules.

If you install cygwin on them, and ssh, you can use SSH on your server
to drive commands around on the remote boxes.  You can issue any command
line you want, which can definitely get all that data.

As a note, getting the Performance data from Perl is a huge pain.  I still
haven't been able to decode all of it correctly.

-- 
Louis Erickson - wwonko@rdwarf.com - http://www.rdwarf.com/~wwonko/

Call on God, but row away from the rocks.  -- Indian proverb


------------------------------

Date: Sun, 16 Nov 2003 02:54:58 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: accuracy problem
Message-Id: <6GBtb.62273$E9.11675@nwrddc01.gnilink.net>

Eric Wilhelm wrote:
> On Sat, 15 Nov 2003 16:28:34 -0600, Jürgen Exner wrote:
>
>>> Any way to fix this?
>>
>> Yes.
>> Is is mentioned in any computer numerics class thou shalt never
>> compare so-called real numbers (which are more aptly called floating
>> point numbers) for equality. Instead check if they are within an
>> epsilon range of each other.
>
> Thanks, but I have no intention of comparing them directly.  The
> problem is that they will not be within the required epsilon range of
> each other if the coordinates are not calculated with 128-bit
> precision.

You mean you require 38 (in words: thirtyeight!) digits of precision?
Are you doing some kind of astronomical navigation or so?

Well, ok, in that case you may want to re-read the fifth paragraph in
"perldoc -q 999"
Apparently you missed the advice given there when you read it the first
time.

> I have long been aware of the advice to round numbers before trying
> to do a comparison, etc, etc,

Ok, sorry, that wasn't clear from your first posting.
Again, please see "perldoc -q 999".

jue




------------------------------

Date: Sun, 16 Nov 2003 02:59:45 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: accuracy problem
Message-Id: <BKBtb.62306$E9.36688@nwrddc01.gnilink.net>

Eric Wilhelm wrote:
> On Sat, 15 Nov 2003 18:12:55 -0600, Eric J. Roode wrote:
>> The simple truth is, you cannot reliably use == or != with
>> floating-point numbers.  You must do some sort of "is this close
>> enough" comparison on your own.  You have to decide what constitutes
>> "close enough".
>
> I have just realized that maybe I have what I was asking for:
>
> 0.375000000000000002 != 0.375 comes from the 5.8.0 custom build
> 0.375000000000004 != 0.375 comes from the 5.6.1 which has been
> installed
>
> I guess the 'long double' is only 80 bits (somehow I cooked up the
> idea that it was 128), but it is longer than the 64 bits that I was
> apparently using before.
>
> Now I have to setup a new installation with all of the libraries that
> were being used (this problem came up in the middle of a lot of
> abstract and complicated functions) and see if it solves the issue
> with the downstream software.

Well, if the difference betwen those 64 bits and the 80 bits gets the
epsilon within the desired range: fine I guess.
But it's not the right solution. What about if someone runs your program on
a different computer and you get contradicting results?

Why not use Math::BigFloat as recommended in the FAQ?

jue




------------------------------

Date: Sat, 15 Nov 2003 23:15:39 -0600
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: accuracy problem
Message-Id: <Xns94352C69F741sdn.comcast@216.196.97.136>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

Eric Wilhelm <ewilhelm@somethinglike.sbcglobalDOTnet> wrote in
news:pan.2003.11.15.18.26.33.801363.1618@somethinglike.sbcglobalDOTnet: 

> On Sat, 15 Nov 2003 18:12:55 -0600, Eric J. Roode wrote:
> 
>> Rounding is not a solution?  Not even, say, rounding to the 12th
>> decimal place?  Surely nothing you're doing can require that level of
>> precision. 
>> 
>> 
> The issue is getting the calculations to resolve between cartesian
> coordinates and trigonometric calculations.  If I have an arc that has
> been centered between two points and I calculate its endpoints,
> rounding each coordinate (to any decimal place), they are not matching
> up to the points that were averaged to get to the center point.  While
> I am able to sidestep the issue, it is causing problems in downstream
> programs which are expecting higher precision.
> 
>> The simple truth is, you cannot reliably use == or != with
>> floating-point numbers.  You must do some sort of "is this close
>> enough" comparison on your own.  You have to decide what constitutes
>> "close enough".
> 
> I have just realized that maybe I have what I was asking for:
> 
> 0.375000000000000002 != 0.375 comes from the 5.8.0 custom build
> 0.375000000000004 != 0.375 comes from the 5.6.1 which has been
> installed 

If you don't consider two numbers that differ by 10^-12 percent to be 
identical, then you are going about things the wrong way.

    sub close_enough
    {
        my ($a,$b) = @_;
        return abs($a - $b) < 1e-10;
    }

Or, if you want to be even more picky:

    sub close_enough
    {
        my ($a,$b) = @_;
        my $delta = abs($a - $b);
        my $base = (abs($a) + abs($b))/2;
        return $delta / $base < 1e-10;
    }

Forget about equality.  Installing a more precise library will not solve 
your problem; you're dealing with transcendental functions which simply 
cannot be represented exactly in any number system.

- -- 
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print

-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBP7cIEGPeouIeTNHoEQLPTACgtHvNl6hB9NphWra/sxYMEN812AUAoLCP
DhL6VJMkhcxiBYqZ7oMEL+Sv
=0A60
-----END PGP SIGNATURE-----


------------------------------

Date: Sun, 16 Nov 2003 04:01:55 GMT
From: Eric Wilhelm <ewilhelm@somethinglike.sbcglobalDOTnet>
Subject: Re: ack! problem
Message-Id: <pan.2003.11.15.22.02.35.222980.1618@somethinglike.sbcglobalDOTnet>

On Sat, 15 Nov 2003 20:59:45 -0600, Jürgen Exner wrote:

> Well, if the difference betwen those 64 bits and the 80 bits gets the
> epsilon within the desired range: fine I guess. But it's not the right
> solution.

You are absolutely right.

Ack!  I just realized that the dxf file format was not storing more than 6
digits of accuracy.  This was causing the problem in the downsteam app
which is what led me down the snipe hunt of trying to check the precision
inside of the perl library and the further adventures of building a new
perl interpreter.

Many thanks for setting my thinking straight on that problem (though of
course you couldn't have known all of the details from the posting of my
misguided unit test script.)  Next time I will remember to question the
storage of the data on disk before pointing the finger at Perl.

Yes, I've read perldoc -q 999 several times and had already ruled out
using Math::BigFloat due to the number of libraries which would need a
complete rewrite to carry the accuracy through.  I had actually already
punted the problem by skipping the arc entirely with the thought that it
could come back in another step if need be, but it was bugging me to no
end.  Turns out that it all stems from a long-ago-forgotten bit of my own
code with the number "6" in it.

--Eric


------------------------------

Date: Sun, 16 Nov 2003 02:13:37 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: arrange form data in same order as on form
Message-Id: <bp6mgh$svb$2@wisteria.csv.warwick.ac.uk>

Gunnar Hjalmarsson <noreply@gunnar.cc> wrote:
> Yes, I have an idea. I'm sure that CGI.pm is slower. Thought the code
> I posted made that apparent to anybody who has an idea of what CGI.pm
> is about.

By no means. In general, guessing that a particular piece of code will
run slower or faster than another is a dodgy business. The *only* way
to tell is to run benchmarks.

Premature optimisation is the root of all evil, &c...

Ben

-- 
"The Earth is degenerating these days. Bribery and corruption abound.
Children no longer mind their parents, every man wants to write a book,
and it is evident that the end of the world is fast approaching."
     -Assyrian stone tablet, c.2800 BC                         ben@morrow.me.uk


------------------------------

Date: Sun, 16 Nov 2003 03:43:29 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: arrange form data in same order as on form
Message-Id: <bp6o7e$1ljm3c$1@ID-184292.news.uni-berlin.de>

Ben Morrow wrote:
> Gunnar Hjalmarsson wrote:
>> Yes, I have an idea. I'm sure that CGI.pm is slower. Thought the
>> code I posted made that apparent to anybody who has an idea of
>> what CGI.pm is about.
> 
> By no means.

Please, Ben, how about reading the code before making such a comment?

> In general, guessing that a particular piece of code will run
> slower or faster than another is a dodgy business. The *only* way 
> to tell is to run benchmarks.

Yes, in general.

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



------------------------------

Date: Sun, 16 Nov 2003 02:07:45 GMT
From: Steve Grazzini <grazz@pobox.com>
Subject: Re: binmode and the diamond operator
Message-Id: <RZAtb.38543$bQ3.10222@nwrdny03.gnilink.net>

J. Romano <jl_post@hotmail.com> wrote:
> So how do you tell the diamond operator to open files in binmode?

    use open IN => ':raw';    # [ untested ]

-- 
Steve


------------------------------

Date: Sun, 16 Nov 2003 02:08:34 GMT
From: Mike Flannigan <mikeflan@earthlink.net>
Subject: Re: Chomp doesn't work for me
Message-Id: <3FB6DCDC.9429049A@earthlink.net>


Bob Walton wrote:

> Maybe it's because your program doesn't contain a call to chomp?  The
> simple way would be:
>
>      my @data=<DATA>;
>      chomp @data;
>      @data = map [ split /\t/, $_, 2 ], @data;
>
> That way you don't have to fuss around trying to chomp something in a
> list of lists -- you can just use a simple array chomp.
>

I tried that, but it didn't work.  It just gives 6 "Use of uninitialized
value in . . . " and no output.

Here is what I did:
#my @data = map [ split /\t/, $_, 2 ], <DATA>;
my @data=<DATA>;
chomp @data;
@data = map [ split /\t/, $_, 2 ], @data;


> > 2)  Why didn't my substring work on line 13?
>
> That's probably because you messed up on operator precedence.  Note that
>
>     (substr $_->[0],1 eq "#")
>
> is the same as:
>
>     (substr($_->[0],(1 eq "#")))
>
> In this case, you want to use the parens.  Note that the comma has a
> particularly low operator precedence -- much lower than eq.

Crap - believe it or not - that didn't work either.
I think I need to hit it again tomorrow when I'm sharper.
Here is what I tried:
    if (((substr $_->[0],1) eq "#") and ((substr $_->[1],1) eq "#")) {

I'm going to mix a gin & tonic right now and settle down  :-)


>
> My other comments are:  It doesn't look like it is really necessary to
> read the entire file into an array.  If you had a humongo input file, it
> would be much better to read it line-by-line.  Since you process @data
> only once (not counting the map transformation which could easily be
> done line-by-line without the complication of map) and line-by-line, it
> would have required no significant modification to your program to do it
> line-by-line.

Yeah, you're right.  I didn't know I was doing that at first, and then
realized I did want to do it because I was going to work on 3-4 lines
at a time - then went back to one line at a time processing later, but
stayed with the slurp.

> I doubt the above is actually doing what you want??  You want to
> concatenate $namt with a string consisting of a space, whatever is in
> $_->[0], a period, and whatever is in $_->[1]?

Right you are - I fixed that too.


> [Note:  tabs in your data were not preserved during posting, so I
> guessed at where they went.  For posting purposes, please use something
> else for a delimiter -- thanks.]

I didn't know that.  Now I do.  I tried to attach a file to my
post, but surprisingly Earthlink does not allow outgoing
attachments to a newsgroup.  Strange, huh?




------------------------------

Date: Sun, 16 Nov 2003 02:21:47 GMT
From: Mike Flannigan <mikeflan@earthlink.net>
Subject: Re: Chomp doesn't work for me
Message-Id: <3FB6DFF5.F0CB5383@earthlink.net>


Mike Flannigan wrote:

> I tried that, but it didn't work.  It just gives 6 "Use of uninitialized
> value in . . . " and no output.
>

As an aside here, could somebody help me with getting the
run time errors to an output file.  I've done it before.  I
thought I did
perl cem2.pl > txt.txt, but that doesn't work now.
Then I tried:
perl cem2.pl > STDERR>txt.txt, but that doesn't work either.




------------------------------

Date: Sun, 16 Nov 2003 02:44:48 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Chomp doesn't work for me
Message-Id: <bp6ob0$p5$1@wisteria.csv.warwick.ac.uk>


Mike Flannigan <mikeflan@earthlink.net> wrote:
> As an aside here, could somebody help me with getting the
> run time errors to an output file.  I've done it before.  I
> thought I did
> perl cem2.pl > txt.txt, but that doesn't work now.

That sends STDOUT to txt.txt.

> Then I tried:
> perl cem2.pl > STDERR>txt.txt, but that doesn't work either.

No. The correct way depends on your shell.

Win9x's command.com: can't be done.
WinNT's cmd.exe:     perl cem2.pl 2>txt.txt *may* work, don't know.
Unix sh-like:        perl cem2.pl 2>txt.txt
Unix csh-like:       You can't get just the errors. You can get both
                     STDOUT & STDERR with perl cem2.pl >& txt.txt.

If you're stuck on Win32 you can get a sh-like shell from
<ftp://ftp.blarg.net/users/amol/zsh>.

Ben

-- 
perl -e'print map {/.(.)/s} sort unpack "a2"x26, pack "N"x13,
qw/1632265075 1651865445 1685354798 1696626283 1752131169 1769237618
1801808488 1830841936 1886550130 1914728293 1936225377 1969451372
2047502190/'                                                 # ben@morrow.me.uk


------------------------------

Date: Sun, 16 Nov 2003 03:47:10 GMT
From: Mike Flannigan <mikeflan@earthlink.net>
Subject: Re: Chomp doesn't work for me
Message-Id: <3FB6F3F7.D3D9C1D0@earthlink.net>


Ben Morrow wrote:

> No. The correct way depends on your shell.
>
> Win9x's command.com: can't be done.
> WinNT's cmd.exe:     perl cem2.pl 2>txt.txt *may* work, don't know.
> Unix sh-like:        perl cem2.pl 2>txt.txt
> Unix csh-like:       You can't get just the errors. You can get both
>                      STDOUT & STDERR with perl cem2.pl >& txt.txt.

Thank you.  That
perl cem2.pl 2>txt.txt
does work on my Win2000.  That's almost surely not
the way I did it before, but it works.  I better write
that one down for future reference.


Here are my errors when trying the chomp like this:
my @data=<DATA>;
chomp @data;
@data = map [ split /\t/, $_, 2 ], @data;


Use of uninitialized value in string eq at cem2.pl line 19, <DATA> line 131.
Use of uninitialized value in concatenation (.) or string at cem2.pl line 27,
<DATA> line 131.
Use of uninitialized value in concatenation (.) or string at cem2.pl line 27,
<DATA> line 131.
Use of uninitialized value in string eq at cem2.pl line 19, <DATA> line 131.
Use of uninitialized value in concatenation (.) or string at cem2.pl line 27,
<DATA> line 131.
Use of uninitialized value in concatenation (.) or string at cem2.pl line 27,
<DATA> line 131.

I can't figure out what is wrong with that line 131, but it sure is persistent.
Sometimes I think I'm not smart enough to do Perl, but I do it anyway
thanks to  TIMTOWTDI  :-)


Jewell "Hamilton, IA"
# #
# "Jewell,"
Jewell "Hamilton, IA"
# #
# "Jewell,"
Jewell "Hamilton, IA"
# #                                                                               -
LINE 131
Jewell "Jewell,"
# "Hamilton, IA"
# #
# "Jewell,"
Jewell "Hamilton, IA"
# #




------------------------------

Date: Sat, 15 Nov 2003 23:20:32 -0600
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: Chomp doesn't work for me
Message-Id: <Xns943539A65EE8sdn.comcast@216.196.97.136>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

Mike Flannigan <mikeflan@earthlink.net> wrote in
news:3FB6F3F7.D3D9C1D0@earthlink.net: 

> Here are my errors when trying the chomp like this:
> my @data=<DATA>;
> chomp @data;
> @data = map [ split /\t/, $_, 2 ], @data;
> 
> 
> Use of uninitialized value in string eq at cem2.pl line 19, <DATA>
> line 131. Use of uninitialized value in concatenation (.) or string at
> cem2.pl line 27, <DATA> line 131.
> Use of uninitialized value in concatenation (.) or string at cem2.pl
> line 27, <DATA> line 131.
> Use of uninitialized value in string eq at cem2.pl line 19, <DATA>
> line 131. Use of uninitialized value in concatenation (.) or string at
> cem2.pl line 27, <DATA> line 131.
> Use of uninitialized value in concatenation (.) or string at cem2.pl
> line 27, <DATA> line 131.

These are not errors.  These are warnings.  Warning you that you are 
using an undef value at some point.  Line 27, to be exact.

> I can't figure out what is wrong with that line 131, but it sure is
> persistent. Sometimes I think I'm not smart enough to do Perl, but I
> do it anyway thanks to  TIMTOWTDI  :-)

- -- 
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print

-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBP7cJSWPeouIeTNHoEQJIFQCfex+p+sH4xmpA8uRjYCV7A5QdqIAAn04z
N2Ngf51IokI1Ex1gn1y2AjM0
=cOxj
-----END PGP SIGNATURE-----


------------------------------

Date: Sun, 16 Nov 2003 07:24:35 GMT
From: Default@User011011101101.net
Subject: dbmopen question
Message-Id: <TCFtb.4214$3o6.3062@nwrdny01.gnilink.net>

Just wondering if anyone can help me figure out what this dbmopen option
is all about.

dbmopen(my %WORDS, $dbfile,0666)         # There see that number?

What is that?  No better yet where in perldoc can i find information on this?
Please help I've got a feeling that this is something I need to know about.

If anyone would be kind enough to comment on the program that would be
greatly appreciated.  This is only my 25th ish program so im sure it's far from
efficient.

Here is the code.

#!
use strict;
use warnings;
print "\n" . ' ' . '='x78 . "\n Creates a database of words and how " .
	 "often each word has been seen.\n " . '='x78 . "\n\n";
our $files = lc(shift) || help() && die "\n";
my $opt1 = lc(shift);
my $opt2 = lc(shift);
my $opt3 = lc(shift);
my $opt4 = lc(shift);
my $opt5 = lc(shift);
my $opt6 = lc(shift);
my $dbfile = "words";
my $file = "";
if ($files eq "-?") {help();die "\n";}
if ($opt1 eq "-?" or $opt2 eq "-?" or $opt3 eq "-?" or $opt4 eq "-?" or
    $opt5 eq "-?" or $opt6 eq "-?") {help();}
if ($files eq "-n" or $opt1 eq "-n" or $opt2 eq "-n" or $opt3 eq "-n" or
    $opt4 eq "-n" or $opt5 eq "-n" or $opt6 eq "-n")
{
	my $new_db = "";
	print ' ' . '='x78 . "\n";
	print " Select or create a database.  " .
	'The default database is: "' . "$dbfile" . '"' . "\n";
	print ' ' . '='x78 . "\n\n";
	while ($new_db eq "")
	{
		print 'Enter the name of the database: ';
		chomp ($new_db = lc<STDIN>);
	}
	my $new_db_1 = "$new_db" . ".pag";
	my $new_db_2 = "$new_db" . ".dir";
	if (!-e $new_db_1 and !-e $new_db_2)
	{
		print "\n".'Create new database "'."$new_db".'" (y or n) ';
		chomp (my $verify = lc<STDIN>);
		die "\n".'Quitting: "'."$new_db".'" was not created'."\n"
		unless ($verify eq "y");
	}
	else {print 'Selecting the "'."$new_db".'" database.'."\n\n";}
	$dbfile = $new_db;
}
if ($files eq "-w" or $opt1 eq "-w" or $opt2 eq "-w" or $opt3 eq "-w" or
    $opt4 eq "-w" or $opt5 eq "-w" or $opt6 eq "-w")
{
	print "Updating database...\n";
	dbmopen(my %WORDS,"$dbfile",0644)||die "\nCan't open $dbfile #!\n";
	foreach $file (<${files}>)
	{
		open(READFILE, "$file") || warn "\nCan't open $file $!\n";
		while (<READFILE>)
		{
			foreach my $word (split (/\W+/))
			{
				if ($opt1 eq "-i" or $opt2 eq "-i" or $opt3 eq "-i"
				    or $opt4 eq "-i" or $opt5 eq "-i"
				    or $opt6 eq "-i")
					{$word = lc($word);}
				$WORDS{$word}++;
			}
		}
		close (READFILE) || warn "\nCan't close $file $!\n";
	}
	dbmclose(%WORDS) || warn "\nCan't close $dbfile #!\n";
	print "\nFinished updating database.\n\n";
}
if ($files eq "-r" or $opt1 eq "-r" or $opt2 eq "-r" or $opt3 eq "-r" or
    $opt4 eq "-r" or $opt5 eq "-r" or $opt6 eq "-r")
{
	print ' ' . '='x78 . "\n This will read the" . '"' . "$dbfile" .
			'" database.' . "\n" . ' ' . '='x78 . "\n\n";
	print "Press <Enter> to continue.";
	my $pause = <STDIN>; $pause = undef; print "\n\n";
	dbmopen(my %WORDS,"$dbfile",0644)||die "Can't open $dbfile:\n#!\n";
	while ((my $key, my $value) = each(%WORDS))
	{print "$key has been seen $value times.\n";}
	dbmclose(%WORDS) || warn "\nCan't close $dbfile #!\n";
}
if ($files eq "-c" or $opt1 eq "-c" or $opt2 eq "-c" or $opt3 eq "-c" or
    $opt4 eq "-c" or $opt5 eq "-c" or $opt6 eq "-c")
{
	print "\n" . ' ' . '='x78 . "\n";
	print ' This will clear the "' . "$dbfile" . '" database.';
	print "\n" . ' ' . '='x78 . "\n\n";
	print 'Are you sure you wish to do this (y or n)? ';
	chomp (my $verify = lc<STDIN>);
	print "\n";
	die 'Quitting: The "'."$dbfile".'" database was not cleared.'."\n"
	unless ($verify eq "y");
	dbmopen(my %WORDS, $dbfile,0666)||die "Can't open $dbfile: $!\n";
	%WORDS = ();
	dbmclose (%WORDS);
	die '"' . "$dbfile" . '" has been cleared.' . "\n";
}
print "\nDone.\n";

#Subroutines#
sub help
{
print <<ENDTEXT; 
     USAGE:    perl 17_1.plx [file or wildcard] [options]

     OPTIONS:  -?  Help.
               -c  Clear the database.
               -i  Ignore case while searching words.
               -n  Create a new database, or select a database to read.
               -r  Read from the database.
               -w  Write to the database.
     NOTES:    Default database will be used unless -n is specified.
               You will not be able to write to the database unless
               files are specified and the -w switch is issued.
EXAMPLES:
perl 17_1.plx file.txt -w          Updates the default database with
                                   information obtained from the
                                   specified files.
perl 17_1.plx *.* -n -w -r         Creates a new database from the
                                   information contained in the
                                   specified files, and then reads it.
perl 17_1.plx -n -r                Selects an alternate database and
                                   reads the contents.
perl 17_1.plx -r -n -c             Selects an alternate database and
                                   clears then reads the contents.
perl 17_1.plx -r -?                Reads from the default database and
                                   displays this help screen.

ENDTEXT
}


------------------------------

Date: Sun, 16 Nov 2003 02:06:57 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Echo '*' chars instead of what's typed
Message-Id: <bp6m41$svb$1@wisteria.csv.warwick.ac.uk>


Andrew DeFaria <Andrew@DeFaria.com> wrote:
> -=-=-=-=-=-
> [Alternative: text/html]
> -=-=-=-=-=-

DON'T do that.

> Tad McClellan wrote:
> > If you have a properly installed perl, then you already have it.
> 
> The perl is the perl that was installed when I installed Mandrake 9.1.
> 
> > Looks like wherever it got installed is not in your path...
> 
> Looks like perldoc isn't installed:
<snip rpmage>

Then you will need to ask a Mandrake group/list how to install it. A
proper install of perl will always include perldoc: I would have
thought it would have been in perl-{,base-,devel-}5.8.0-17mdk, but it
seems Mandrake in their infinite wisdom have put it somewhere else.

Ben

-- 
  The cosmos, at best, is like a rubbish heap scattered at random.
                                                         - Heraclitus
  ben@morrow.me.uk


------------------------------

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 5811
***************************************


home help back first fref pref prev next nref lref last post