[18973] in Perl-Users-Digest
Perl-Users Digest, Issue: 1168 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jun 21 00:05:38 2001
Date: Wed, 20 Jun 2001 21:05:11 -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: <993096310-v10-i1168@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 20 Jun 2001 Volume: 10 Number: 1168
Today's topics:
Re: 2 questions about flock (Garry Williams)
Re: CGI.pm, cookies and redirect PLS HELP! (CPERL520335)
Re: CGI::CARP (carpout) or (fatalsToBrowser) ? (Zur Aougav)
Click here to crash the browser? <davsoming@lineone.net>
command line news posting tools <sun_tong@users.sourceforge.net>
Re: Complete hash of an array <bwalton@rochester.rr.com>
Re: Configuration problem (David Efflandt)
Difficulty exporting from modules (Matthew Miller)
Re: Difficulty exporting from modules <ron@savage.net.au>
Re: Difficulty exporting from modules (Matthew Miller)
Re: Exception handling ? <der.prinz@gmx.net>
Re: Exception handling ? <kevin@vaildc.net>
Re: Finding if an executable... <mischief@velma.motion.net>
Re: hash os hashes sorting <der.prinz@gmx.net>
Re: hash os hashes sorting <bwalton@rochester.rr.com>
Help -- MLDBM and Segmentation faults viscido@u.washington.edu
Re: Help -- MLDBM and Segmentation faults <bwalton@rochester.rr.com>
Re: int sub - strange behaviour <ron@savage.net.au>
Re: libwww question <jdblack@black.metronet.com>
Re: Mix JS variables - David Eff.. <abuse@SCasey.com>
Password encryption <jcs@netexpansion.com>
perl context: Strange behaviour? (Shankar)
Re: perl context: Strange behaviour? <joe+usenet@sunstarsys.com>
PERL scripts for web email (using POP3 and SMTP interna (Jason)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 21 Jun 2001 03:17:21 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: 2 questions about flock
Message-Id: <slrn9j2pq1.lld.garry@zfw.zvolve.net>
On Tue, 19 Jun 2001 09:20:01 +0100, Mark Grimshaw
<m.grimshaw@salford.ac.uk> wrote:
> Garry Williams wrote:
>>
>> On Fri, 15 Jun 2001 11:55:33 +0100, Mark Grimshaw
>> <m.grimshaw@salford.ac.uk> wrote:
>>
>> > I'm curious why strict would not complain if I attempted to call an
>> > undefined method sync() as I originally did.
>>
>> This has nothing to do with `strict'. It's a run-time exception no
>> matter what:
>>
>> $ perl -we 'package A; sub new{return bless{}}package main;' \
>> -e 'my $x=A->new;$x->nope'
>> Can't locate object method "nope" via package "A" (perhaps you forgot
>> to load "A"?) at -e line 2.
>
> I use -w as a matter of course and still did not get warnings/errors.
Well, I guess you need to show the code.
It's a run-time *error* when a subroutine is called but not defined.
(See above.)
--
Garry Williams
------------------------------
Date: 21 Jun 2001 00:26:11 GMT
From: cperl520335@aol.com (CPERL520335)
Subject: Re: CGI.pm, cookies and redirect PLS HELP!
Message-Id: <20010620202611.12364.00000276@ng-fr1.aol.com>
>
>drop the 'print $query->header' line and mod your redirect thusly:
>
>print $query->redirect(-location=>$site1,
> -cookie=>$mycookie);
>
>hth-
Now the cookie isn't being set. :(
I also tried:-
print $query->header(-cookie=>$my_cookie,-location=>$sitelocation);
and:-
print $query->redirect(-cookie=>$my_cookie,-location=>$sitelocation);
Pls help, I need to get this done.
------------------------------
Date: 20 Jun 2001 19:50:32 -0700
From: aougav@hotmail.com (Zur Aougav)
Subject: Re: CGI::CARP (carpout) or (fatalsToBrowser) ?
Message-Id: <bccc87cc.0106201850.21dafb3a@posting.google.com>
"David Soming" <davsoming@lineone.net> wrote in message news:<tj1pqohv956h52@corp.supernews.co.uk>...
> Hi,
> What is the difference between...
> #use CGI::Carp qw(carpout);
> #use CGI::Carp qw(fatalsToBrowser);
> and what is the "qw"? I've looked in perldocs but no wiser.
> Thanks.
First, the two lines are commented... :-)
Second, fatalsToBrowser direct errors back to your browser. Carpout
direct STDERR to your own file/log (and not to the server's log). You
need much more info in order to use it. To keep things clear and
simple, you can start using fatalsToBrowser.
What is qw? Use qw to put quotes around lists. Why do you need it
here? Something with exporting names (A package like CGI::Carp can
have some hidden names, but you are alowed to export (read: expose)
them to your program and use them freely). In short, read the
manual... :-)
Zur
------------------------------
Date: Thu, 21 Jun 2001 04:54:29 +0100
From: "David Soming" <davsoming@lineone.net>
Subject: Click here to crash the browser?
Message-Id: <tj2rjjsvecegdc@corp.supernews.co.uk>
Hi,
Don't know if this is specific to cgi or perl...
$our_link = "http://www.mydomain.com/";
$our_image = "<font size=-1>ChatPro v1.0 by me<br> <a target=\"_new\"
href=\"$our_link\">click here to crash the browser</a></font>";
I'm wanting to create an active link but it always crashes (hangs) IE 5.5!
In NN the hyperlink works but goes to:
http://www.mydomain.com/chat/$our_link
What is wrong with the syntax?- or is it all ok?
Maybe the $our_link is in the wrong place?
Thanks for all your help
--
David Soming
'Just a head-banger- doing what I do best'
______________
------------------------------
Date: 20 Jun 2001 23:58:19 -0300
From: * Tong * <sun_tong@users.sourceforge.net>
Subject: command line news posting tools
Message-Id: <sa8n172wnck.fsf@suntong.personal.users.sourceforge.net>
Hi,
Please suggest a news posting tool that can be used from command
line, which has the function that like 'sendmail -t' (scanned
message for headers) TIA
--
Tong (remove underscore(s) to reply)
*niX Power Tools Project: http://xpt.sourceforge.net/
- All free contribution & collection
------------------------------
Date: Thu, 21 Jun 2001 02:59:52 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Complete hash of an array
Message-Id: <3B3162EC.D6F62403@rochester.rr.com>
JohnShep wrote:
>
> I thought I had this array/hash business figured but I'm really losing it on
> this one.
>
> my %ratings;
> while (my $ref = $sth->fetchrow_arrayref) {
>
> if (!$ratings{$$ref[3]}{"now"}) {
> $ratings{$$ref[3]}{"now"} = 1000;
> $ratings{$$ref[3]}{"max"} = 1000;
> }
>
> (ratings{$$ref[3]}{"now"}) = get_rating_now($$ref[3]);
> (ratings{$$ref[3]}{"max"}) = get_rating_max($$ref[3]);
> }
>
> OK so far I think, but how do I iterate through %ratings to update the
> database with the new values ?
>
> Thanks in advance, John
Well, there are two basic ways to iterate through a hash:
for $key (keys %ratings){
#do whatever
}
or:
while(($key,$value)=each %ratings){
#do whatever
}
The latter is preferred if the hash is huge, like maybe a dbm-type tied
hash, since the former creates an anonymous array containing all the
keys.
--
Bob Walton
------------------------------
Date: Wed, 20 Jun 2001 23:51:48 +0000 (UTC)
From: see-sig@from.invalid (David Efflandt)
Subject: Re: Configuration problem
Message-Id: <slrn9j2dok.5eq.see-sig@typhoon.xnet.com>
On Wed, 20 Jun 2001 20:03:49 +0100, David Soming <davsoming@lineone.net> wrote:
> According to my ssi-env.shtml script Using: <!--#exec
> cgi="cgi-bin/ALL_ENV.cgi"-->)
> document root is:
> DOCUMENT_ROOT = /home/sites/site13/web - this is OK and is set for all my
> other
> programs running on Unix virtual server.
>
> However the following will not config properly and I only have two variables
> to set
> in variables.pl...
>
> use constant TOP => 'home/sites/site13/web/cgi-bin/track';
> use constant HOME => 'http://www.mydomain.com/cgi-bin/track';
>
> but get software error using CGI::Carp qw(carpout);
> "Cant open home/sites/site13/web/mydomain/cgi-bin/track/data/adps.txt(No
> such
> file or directory)!"
Maybe there is no 'home' relative to the current working dir (which is the
dir of the page for includes). Did you forget a '/' on '/home'?
> The directories track/data/permissions are OK and the file adps.txt already
> exists in data dir!
> Anything obvious why I get error message?
> Also, what exactly does "use constant" mean?
'perldoc constant' should explain.
> Thanks
> --
> David Soming
> 'Just a head-banger- doing what I do best'
> ______________
>
>
>
>
--
David Efflandt (Reply-To is valid) http://www.de-srv.com/
http://www.autox.chicago.il.us/ http://www.berniesfloral.net/
http://cgi-help.virtualave.net/ http://hammer.prohosting.com/~cgi-wiz/
------------------------------
Date: 21 Jun 2001 01:17:26 GMT
From: namille2@news.vt.edu (Matthew Miller)
Subject: Difficulty exporting from modules
Message-Id: <9grhv6$1ep$1@solaris.cc.vt.edu>
Hello,
I'm working on my first module/OO based program. So far it has been
interesting ;) The main package name is CWidget. I try to export some
subroutines from that package but, it doesn't work. It is still necessary
to call the subroutine like this: CWidget::cwidget_init(); in my test
program, I want to be able to leave off the CWidget:: part.
While I have read all the relevant stuff from the man pages and _Programming
Perl_, I haven't seen anything detailing how a module with multiple
packages should be arranged. Especially, if two packages use subroutines
contained in the other package, like I have below with fill_win and
Menu->new. Also, if anyone knows of a modules that shows a good OO style
I would like to know about it.
Still, my main question is about the exporting issue. When I 'use CWidget;'
my subroutines in CWidget aren't exported as they should be. Can someone
tell me why?
Below is a stripped down version of the file CWidget.pm:
package CWidget::Menu;
use Curses;
use CWidget;
#our @ISA = qw( CWidgit );
# A menu is a window across the top of the screen that is just
# one line high. An optional color parameter can be passed in.
sub new {
my $class = shift;
my $color = shift || $CWidget::menu_color;
my $self = {};
bless $self, $class;
my $menu = Curses->new( 1, $COLS, 0, 0 );
CWidget::fill_win( $menu, $color );
$self->{win} = $menu;
return $self;
}
package CWidget;
require Exporter;
require DynaLoader;
use Carp;
use Curses;
use strict;
our @ISA = qw(Exporter DynaLoader);
our @EXPORT = qw( init_cwidget cleanup_cwidget fill_win );
our ( $menu_color, $main_win, $win_color, $status_color, $menu_win,
$status_win );
# Preform the necessary work to initialize curses and the widgets.
#
sub cwidget_init {
initscr(); # init curses.
noecho(); # don't echo typed characters
cbreak(); # disable line buffering (no cooked mode)
start_color(); # we want color
keypad(1); # enable the keypad
$menu_win = CWidget::Menu->new();
$menu_win->{win}->refresh();
}
# Preform any necessary clean-up for our package and Curses
sub cwidget_cleanup {
endwin();
}
# Fill an entire window with spaces, this is used to set
# a windows background.
#
# The subroutine doesn't call doupdate() on the window.
#
# Arguments:
# 1. The window to fill.
# 2. The color to use.
sub fill_win {
my $win = shift || die "no win argument!";
my $color = shift || die "no color argument!";
my ($line, $col);
# get the window size.
$win->getmaxyx( $line, $col );
$win->attron( $color ); # Turn the color on.
my $l;
foreach $l (0 .. $line-1) {
$win->addstr( $l, 0, " " x $col );
}
$win->attroff( $color ); # turn is off.
}
1;
Thanks everyone, Matthew
------------------------------
Date: Thu, 21 Jun 2001 11:28:32 +1000
From: "Ron Savage" <ron@savage.net.au>
Subject: Re: Difficulty exporting from modules
Message-Id: <m7cY6.8647$qJ4.351488@ozemail.com.au>
Matthew
See below.
--
Cheers
Ron Savage
ron@savage.net.au
http://savage.net.au/index.html
Matthew Miller <namille2@news.vt.edu> wrote in message news:9grhv6$1ep$1@solaris.cc.vt.edu...
> subroutines from that package but, it doesn't work. It is still necessary
> to call the subroutine like this: CWidget::cwidget_init(); in my test
[snip]
> our @ISA = qw(Exporter DynaLoader);
> our @EXPORT = qw( init_cwidget cleanup_cwidget fill_win );
Why not try putting cwidget_init in the @EXPORT line?
Actually, the guidelines for this say you should _not_ export things by default, but should use EXPORT_OK.
CWidget eh? Sure looks like a hangover from C++ to me... You have my sympathy.
------------------------------
Date: 21 Jun 2001 02:16:39 GMT
From: namille2@news.vt.edu (Matthew Miller)
Subject: Re: Difficulty exporting from modules
Message-Id: <9grle7$3p9$1@solaris.cc.vt.edu>
On Thu, 21 Jun 2001 11:28:32 +1000, Ron Savage <ron@savage.net.au> wrote:
>Matthew Miller <namille2@news.vt.edu>
>
>> our @ISA = qw(Exporter DynaLoader);
>> our @EXPORT = qw( init_cwidget cleanup_cwidget fill_win );
>
>Why not try putting cwidget_init in the @EXPORT line?
<Slaps self on head> yep, after filling in @EXPORT I changed the subroutine
name.
>Actually, the guidelines for this say you should _not_ export things by
>default, but should use EXPORT_OK.
Your right. I have been using some other modules as guides, like Curses.pm,
and most just use EXPORT.
>CWidget eh? Sure looks like a hangover from C++ to me... You have my sympathy.
No, I'm trying to make some curses widgets. Now, I _am_ a hold over from
C and C++ ;) Making the transition from C scoping rules to perl symbol
tables is hard for a guy like me!
Next question: after making the correction you suggested, I uncommented
this line:
our @ISA = qw( CWidgit );
in package CWidget::Menu. After my test program exits this message is
printed twice:
Can't locate package CWidgit for @CWidget::Menu::ISA during global destruction.
The original post shows the ISA line that was commented out. Any ideas why this
happens?
Thanks for your previous reply Rob.
Matthew
--
Most people don't realize that large pieces of coral, which have been
painted brown and attached to the skull by common wood screws, can
make a child look like a deer.
------------------------------
Date: Thu, 21 Jun 2001 00:46:24 +0200
From: "Stefan Weiss" <der.prinz@gmx.net>
Subject: Re: Exception handling ?
Message-Id: <3b312773@e-post.inode.at>
BeyondContol Inc. <beyondcontrol@runbox.com> wrote:
> Is there an equivalent to the try/catch c++ directives?
> I saw something in the form of an Exception module at CPAN, but I'm not sure
> it'll catch errors not thrown using this same module....
eval {
# call subs that might die...
};
if ($@) {
# ...and catch the 'exception' here
warn $@; # or whatever
}
Or check out the Error.pm module from CPAN to get the semantics
you are used to (try, catch, throw, finally, etc...).
cheers,
stefan
------------------------------
Date: Wed, 20 Jun 2001 18:54:43 -0400
From: Kevin Michael Vail <kevin@vaildc.net>
Subject: Re: Exception handling ?
Message-Id: <200620011854436197%kevin@vaildc.net>
In article <9gqof8$r9d$1@news.netvision.net.il>, BeyondContol Inc.
<beyondcontrol@runbox.com> wrote:
> I'm running a scripts that loads subroutines from other script files.
> My problem is that every time that any subroutine from those files fails
> (like trying to manipulate undefined objects), my main script dies with it.
> Now, I'm not going to sell myself out by running the subroutines using
> system('perl xxx.pl'), I want to run them (relatively) cleanly as
> subroutines.
>
> Is there an equivalent to the try/catch c++ directives?
> I saw something in the form of an Exception module at CPAN, but I'm not sure
> it'll catch errors not thrown using this same module....
perldoc -f eval
--
Kevin Michael Vail | a billion stars go spinning through the night,
kevin@vaildc.net | blazing high above your head.
. . . . . . . . . | But _in_ you is the presence that
. . . . . . . . . | will be, when all the stars are dead. (Rainer Maria Rilke)
------------------------------
Date: Thu, 21 Jun 2001 00:37:54 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: Finding if an executable...
Message-Id: <tj2gf2n5kqt43f@corp.supernews.com>
kurt.hindenburg@gte.net wrote:
> I'm attempting to find a way to determine if an executable is on a system.
> I would like it to work on any OS. I would prefer not to search through
> the $PATH variable (I'm not even sure if Mac OS has one). MS Windows does
> not handle 2>&1 correctly, so I can't run the executable and look at the
> results. Other than redirectly all the output to a temp file, is there
> a way to do this?
Sounds like a good use for File::Find and the -x built-in.
Chris
--
You must not lose faith in humanity. Humanity is an ocean;
if a few drops of the ocean are dirty, the ocean does not
become dirty. -- Mohandas K. Gandhi
------------------------------
Date: Thu, 21 Jun 2001 00:29:23 +0200
From: "Stefan Weiss" <der.prinz@gmx.net>
Subject: Re: hash os hashes sorting
Message-Id: <3b312376@e-post.inode.at>
woltz <woltz@sewp.nasa.gov> wrote:
> I'm perplexed on how to sort, or retrieve my data in a sorted
> fashion from, a hash of hashes on a
> value from the bottom hash.
(structure snipped)
> I want to print all items sorted on another_value.
#/usr/bin/perl -w
use strict;
my $top_hash = {
id1 => {
some_key => "some_value3",
anotherkey => "another_value3",
},
id2 => {
some_key => "some_value1",
anotherkey => "another_value1",
},
id3 => {
some_key => "some_value2",
anotherkey => "another_value2",
},
};
foreach my $item (sort byval keys %$top_hash) {
print qq[
item $item:
some_key: $top_hash->{$item}{some_key}
anotherkey: $top_hash->{$item}{anotherkey}
];
}
sub byval {
$top_hash->{$a}{anotherkey} cmp $top_hash->{$b}{anotherkey}
}
enjoy,
stefan
------------------------------
Date: Thu, 21 Jun 2001 03:40:43 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: hash os hashes sorting
Message-Id: <3B316C7E.9927E2F0@rochester.rr.com>
woltz wrote:
>
> I'm perplexed on how to sort, or retrieve my data in a sorted fashion from, a hash of hashes on a
> value from the bottom hash.
> %top_hash = {id1=>%bottom_hash = {some_key => some_value,
> anotherkey => another_value},
> id2=>%bottom_hash = {some_key => some_value,
> anotherkey => another_value},
> id3=>%bottom_hash = {some_key => some_value,
> anotherkey => another_value}}
> I want to print all items sorted on another_value.
> Thanks,
> KG
perldoc -q sort anything
--
Bob Walton
------------------------------
Date: 20 Jun 2001 17:22:04 -0700
From: viscido@u.washington.edu
Subject: Help -- MLDBM and Segmentation faults
Message-Id: <m3lmmmu1g3.fsf@fiddler.u.washington.edu>
I'm a bit baffled at some behavior I'm getting from perl. I'm using
the MLDBM module to create a multi-level database (a hash of hashes
format, which eventually will probably turn into a hash of hashes of
hashes of arrays or something equally complicated). I've been doing
all my coding on a G4/450 running Black Lab Linux (2.2.18 kernel),
with 512 MB of RAM, and perl 5.6.0 and MLDBM 2.00. Everything has
worked fine. I tie %players (the database name) to players.db, which
at the moment has a very small hash in it. However, when I port the
code to a RedHat Linux P-III 1 GHZ machine with 128 MB of ram, the
same exact setup (including all files, perl 5.6.0, MLDBM 2.00) gives
me a segmentation fault on the same script.
The script's short, so here it is in its entirety:
#!/usr/bin/perl -w
use POSIX;
use FindBin qw($Bin);
use lib "$Bin/modules";
use MLDBM;
# Tie the hash to the database.
tie %players, 'MLDBM', "$Bin/game/data/players.db",
O_CREAT|O_RDWR, 0640 or die $!;
# Print the hash
foreach $dbnum (keys %players) {
print "\#$dbnum\n";
foreach $attribute (keys %{ $players{$dbnum} }) {
print "$attribute: $players{$dbnum}{$attribute}\n";
}
}
############### end of script
Running that script on the G4/450 gives a printed list of the DB, and
on the PIII/1GHz gives a segmentation fault. I'm wondering how this
can be.
My suspicion is MLDBM is the culprit. If I comment out the tie
command, and replace it with
for ($i=1; $i < 7; $i++) {
$players{"P$i"} = {
name => "Guest",
password => "guest",
describe => "A guest. Be kind. :)"
};
}
thus generating the database in its entirety by hand, both systems
print it out quite nicely.
Anyone have any clues about this? Is this truly an MLDBM problem, or
is it something else? And why would there be such apparently narrow
platform dependency on two linux systems with perl 5.6.0, especially
for such a seemingly simple script?
Thanks for any help you can give...
Steve
--
Steven Viscido [viscido@u.washington.edu]
Department of Zoology, Box 351800 Kincaid Hall
University of Washington
Seattle, WA 98195 Tel: 206-221-6893
------------------------------
Date: Thu, 21 Jun 2001 03:37:45 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Help -- MLDBM and Segmentation faults
Message-Id: <3B316BCD.F15020F5@rochester.rr.com>
viscido@u.washington.edu wrote:
>
> I'm a bit baffled at some behavior I'm getting from perl. I'm using
> the MLDBM module to create a multi-level database (a hash of hashes
> format, which eventually will probably turn into a hash of hashes of
> hashes of arrays or something equally complicated). I've been doing
> all my coding on a G4/450 running Black Lab Linux (2.2.18 kernel),
> with 512 MB of RAM, and perl 5.6.0 and MLDBM 2.00. Everything has
> worked fine. I tie %players (the database name) to players.db, which
> at the moment has a very small hash in it. However, when I port the
> code to a RedHat Linux P-III 1 GHZ machine with 128 MB of ram, the
> same exact setup (including all files, perl 5.6.0, MLDBM 2.00) gives
> me a segmentation fault on the same script.
>
> The script's short, so here it is in its entirety:
>
> #!/usr/bin/perl -w
>
> use POSIX;
> use FindBin qw($Bin);
> use lib "$Bin/modules";
> use MLDBM;
>
> # Tie the hash to the database.
> tie %players, 'MLDBM', "$Bin/game/data/players.db",
> O_CREAT|O_RDWR, 0640 or die $!;
>
> # Print the hash
> foreach $dbnum (keys %players) {
> print "\#$dbnum\n";
> foreach $attribute (keys %{ $players{$dbnum} }) {
> print "$attribute: $players{$dbnum}{$attribute}\n";
> }
> }
>
> ############### end of script
>
> Running that script on the G4/450 gives a printed list of the DB, and
> on the PIII/1GHz gives a segmentation fault. I'm wondering how this
> can be.
>
> My suspicion is MLDBM is the culprit. If I comment out the tie
> command, and replace it with
>
> for ($i=1; $i < 7; $i++) {
> $players{"P$i"} = {
> name => "Guest",
> password => "guest",
> describe => "A guest. Be kind. :)"
> };
>
> }
>
> thus generating the database in its entirety by hand, both systems
> print it out quite nicely.
>
> Anyone have any clues about this? Is this truly an MLDBM problem, or
> is it something else? And why would there be such apparently narrow
> platform dependency on two linux systems with perl 5.6.0, especially
> for such a seemingly simple script?
...
> Steve
...
Well, the segmentation fault should not happen regardless (you should
get some other error), but the root of your problem is probably that
binary dbm-type files are generally not compatible from one computer to
another, let alone one OS to another. If you are copying "all files" as
you state, the tied hash used by MLDBM will most likely not be usable on
the other system. One solution is to convert the tied hash to an ASCII
file with delimited key:value pairs (making sure, of course, to choose a
delimiter which doesn't appear in your keys), and then set the dbm-type
tied hash up again on the other system.
Note that dbm-type files may not even be compatible from one computer to
another even if they are running the exact same version of the same OS
-- the dbm-type file code in the OS could have been compiled during
installation with different options, like bucket size etc, on the two
computers. Or maybe someone tuned one of them for performance. That
could readily happen between two distributions of Linux, for example.
--
Bob Walton
------------------------------
Date: Thu, 21 Jun 2001 12:16:48 +1000
From: "Ron Savage" <ron@savage.net.au>
Subject: Re: int sub - strange behaviour
Message-Id: <DQcY6.8681$qJ4.352026@ozemail.com.au>
George
See below.
--
Cheers
Ron Savage
ron@savage.net.au
http://savage.net.au/index.html
Philip Newton <pne-news-20010620@newton.digitalspace.net> wrote in message news:ucg1jtotirjvcj5tkb57kg7rtvlerl7ua6@4ax.com...
[snip]
> No: one of the numbers you are calculating with is not exactly
> representable in floating point, and the product is not representable
> exactly either. So the result is not 3980.0000... but 3979.99..99xyz...
> (on my machine it's 3979.99999999999950000000000000000000 to 32 decimal
> places). So int() truncates that to 3979.
Good stuff.
> > Do you guys [k]now anything?
>
> Don't do maths with floating point if you expect to get exact answers.
> For example, if you are calculating with money, do all your arithmetic
> in cents rather then fractional dollars.
Idealistic. If you need to calculate a %, eg for tax, do the job properly. Use Math::Currency.
> Or you could try using sprintf() for rounding rather than int() for
> truncating.
Hmmm. And despite Greg's reponse, I don't see sprintf rounding-to-even. Math::Currency does. Try (tested code):
-----><8-----
#!/perl/lib/perl
use strict;
use warnings;
# ---------------------------------------------------------------
print sprintf("Perl V %vd. \n", $^V);
for my $i (0.555, 1.555, 0.565, 1.565, 0.575, 1.575)
{
print "$i => ", sprintf("%.2f. \n", $i);
}
-----><8-----
My output:
-----><8-----
Perl V 5.6.1.
0.555 => 0.56.
1.555 => 1.55. # Sure looks odd to me :-).
0.565 => 0.56.
1.565 => 1.56.
0.575 => 0.57.
1.575 => 1.58.
-----><8-----
------------------------------
Date: Wed, 20 Jun 2001 20:48:51 -0500
From: "W.W.J.D. Black" <jdblack@black.metronet.com>
Subject: Re: libwww question
Message-Id: <200620012048511193%jdblack@black.metronet.com>
Hash: SHA1
In article
<Pine.A41.4.33.0106192303100.94310-100000@dante53.u.washington.edu>, M.
Scholz
<msperrin@u.washington.edu> wrote:
}I am trying to use CPAN, and when that didn't work , downloading the
}tarball from sourceforge, for libwww. The problem is that it keeps
}spitting this error at me from the `make test` command. Is there any way
}to make the output more verbose, so I can see why? Or does anyone know
}what the problem might be? The machine is a newly installed RH 7.1 box.
}The error (the only one, I might add) is:
}
}robot/rules-dbm.....FAILED test 8
} Failed 1/13 tests, 92.31% okay
}
}...
}
}robot/rules-dbm.t 13 1 7.69% 8
}Failed 1/22 test scripts, 95.45% okay. 1/287 subtests failed, 99.65% okay.
}
A shot in the dark as what this is all about is that it is referring to
the database manager
installed (or lack thereof) on your system. Unless you are planning on
using a database I wouldn't
worry about it.
jdb
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>
iQA/AwUBOzFSfGy/lre8y0dpEQJUZACghkvHWmf0fUsR2O/sSuKEfeKt1mgAoMZ5
reVp4zSnUk91tcWpq6h6Oq/T
=5IEP
-----END PGP SIGNATURE-----
------------------------------
Date: Thu, 21 Jun 2001 03:26:15 GMT
From: "Sean Casey" <abuse@SCasey.com>
Subject: Re: Mix JS variables - David Eff..
Message-Id: <rPdY6.86319$L4.10408458@news1.rdc1.az.home.com>
"Alan J. Flavell" <flavell@mail.cern.ch> wrote
> On Tue, 19 Jun 2001, BUCK NAKED1 wrote:
>
> > I'm still curious if anyone knows of a site that explains mixing JS with
> > Perl. All I can find on the subject are the JS Event Handlers that are
> > mixed with perl in CGI.pm.
>
> No, they aren't "mixed", and that's the whole key to understanding.
>
> CGI.pm offers you a way to put event handlers into the generated HTML,
> but there's nothing magical about that. You could perfectly well code
> that by hand (as the 'zilla keeps telling us), just that (contrary to
> what the 'zilla keeps telling us), there are benefits in first knowing
> _how_ to do it by hand, and then _refraining_ from doing that.
I've been coding the HTML and JS "by hand" - in part because the client will
be modifying/maintaining the actual page presentation, and doesn't want/need
to learn perl. . .so there may be some legitimate reasons to do so.
Back on topic: I've an application that has a requirement to
redirect/recall/run a script on another server (a shopping cart), passing to
it several form parameters via method POST. I have managed to locate the
redirect function provided by GGI.pm, but can find no way to also send along
the parameters.
In early development, my shopping cart 'simulator' was another script in my
cgi-bin, so:
$shopprog = "./otherscript.pl";
open (SHOPPER, "| $shopprog " ) or die "Cannot start shopping program.
$!\n";
print SHOPPER "Filename=$filename\&";
print SHOPPER "Question=$question\&";
print SHOPPER "Email=$email\n";
close(SHOPPER);
worked just fine - except that it didn't 'redirect' the browser. That
seemed not to matter.
However, when $shopprog = http://www.someotherdomain.com/some.html;
I (naturally) got the error "no such file..."
So, I used redirect, but I cannot find a way to include the name=value
pairs. I suspect it's not possible, for security reasons.
As of now, (ah, here's the topic!) the script writes out a web page with a
form containing the type=hidden input tags and a JavaScript
onLoad="document.forms[0].submit();"
which works great, but overwhelms me with it's geekyness.
Any suggestions?
RH 6.0 and 6.2
perl 5.005_03 and 5.004_04
Sean
------------------------------
Date: Thu, 21 Jun 2001 01:40:33 +0200
From: jean-charles savelli <jcs@netexpansion.com>
Subject: Password encryption
Message-Id: <3B313471.2388211B@netexpansion.com>
Hello,
I have RH7.1.
I am trying to create a user account in PERL using
useradd (or adduser) together with a password.
On my machine passwords are 34 characters long
I use a program containing two sub programs
* authGetRandom salt
* called by authCryptPassword
called by the main programm
##############################################################################
#!/usr/bin/perl
use strict 'vars';
use Crypt::PasswdMD5;
my $login='user3';
my $pwd='abcdefgh';
my $ret;
##############################################################################
sub authGetRandomSalt
{
my ($length) = @_;
my (@hash_saltset, $rchars, $rnum, $index);
@hash_saltset = ('a' .. 'z', 'A' .. 'Z', '0' .. '9', '.', '/');
$rchars = "";
for ($index=0; $index<$length; $index++) {
$rnum = rand(64);
$rchars .= $hash_saltset[$rnum % 64];
}
return($rchars);
}
##############################################################################
sub authCryptPassword
{
my ($plaintextpassword)@_;
my $cryptedpassword;
my $salt = authGetRandomSalt(11);
$cryptedpassword = unix_md5_crypt($plaintextpassword, $salt);
return($cryptedpassword);
}
##############################################################################
# Main
# Password encryption
$pwd=&authCryptPassword($pwd);
$ret=system(qq{/usr/local/bin/sudo useradd -p '$pwd' $login});
##############################################################################
The user and password get added correcly to shadow
but when I try connecting I get a message
"error password"
I might not be using use Crypt::PasswdMD5
correctly.
Could any one tell me what I am doing wrong
this program used to work with the function crypt() for DES encryption
on Suse 7.0
Thank you
Jean-Charles Savelli
------------------------------
Date: 20 Jun 2001 17:05:25 -0700
From: SNeelakantan_C@zaplet.com (Shankar)
Subject: perl context: Strange behaviour?
Message-Id: <4a0341c8.0106201605.201d8483@posting.google.com>
Does "context" have a different meaning with the /e
switch in a regular expression?
I have a string which reads like "MAIN 0-0-0-29" appearing
in some place in a file and I wanted to increment the
last digit (i.e 29) in the file via command line.
This is the exact command that I used:
perl -p -i -e 's/(.*MAIN .*\-)(\d+)/print($1), $2 + 1/e' fileX
With this, I could get the desired change in the string and make
it "MAIN 0-0-0-30"
I found that if I use print $1, $2 + 1
(i.e remove the brackets in the print),
I get a different behaviour.
The string becomes "MAIN 0-0-0-301"
However, when I try something like this at the command line,
perl -e '{ $x=2; $y=3; print $x, $y + 5 }'
I get: 28 and not 235 or 85
Am I missing something completely?
Any help would be appreciated.
-Shankar
------------------------------
Date: 20 Jun 2001 20:20:38 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: perl context: Strange behaviour?
Message-Id: <m3zob23cq1.fsf@mumonkan.sunstarsys.com>
SNeelakantan_C@zaplet.com (Shankar) writes:
> I have a string which reads like "MAIN 0-0-0-29" appearing
> in some place in a file and I wanted to increment the
> last digit (i.e 29) in the file via command line.
> This is the exact command that I used:
>
> perl -p -i -e 's/(.*MAIN .*\-)(\d+)/print($1), $2 + 1/e' fileX
The steps you are performing are:
1) -p: $_ = "MAIN 0-0-0-29";
2) -e: $1 = "MAIN 0-0-0-"; $2="29";
print $1;
$_ = $2 + 1;
3) -p: print $_; # from continue block
I think what you really want to do is something like (untested):
% perl -pi -e 's/(.*MAIN .*\-)(\d+)/$1 . ($2 + 1)/e' fileX
> With this, I could get the desired change in the string and make
> it "MAIN 0-0-0-30"
>
> I found that if I use print $1, $2 + 1
> (i.e remove the brackets in the print),
> I get a different behaviour.
>
> The string becomes "MAIN 0-0-0-301"
print() returns 1, which replaces the old string in $_ and
gets printed by -p's continue block. See
% perldoc perl
for details.
Joe Schaefer
--
"There are two ways of constructing a software design; one way is to make it so
simple that there are obviously no deficiencies, and the other way is to make
it so complicated that there are no obvious deficiencies. The first method is
far more difficult."
-- C. A. R. Hoare
------------------------------
Date: 20 Jun 2001 19:21:50 -0700
From: jarose@angelfire.com (Jason)
Subject: PERL scripts for web email (using POP3 and SMTP internally)?
Message-Id: <fae4fd10.0106201821.4770fb2b@posting.google.com>
Looking for such scripts, or anyone developing them... please email me
jarose@angelfire.com
------------------------------
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 1168
***************************************