[25571] in Perl-Users-Digest
Perl-Users Digest, Issue: 7815 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Feb 23 06:05:53 2005
Date: Wed, 23 Feb 2005 03:05:28 -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 Wed, 23 Feb 2005 Volume: 10 Number: 7815
Today's topics:
Re: '+<' mode for opening files <mritty@gmail.com>
Re: '+<' mode for opening files <eric-amick@comcast.net>
Annoying Problem with a Basic Perl app and XP Pro <jpmythic@ntlworld.com>
Re: Annoying Problem with a Basic Perl app and XP Pro <1usa@llenroc.ude.invalid>
Re: Annoying Problem with a Basic Perl app and XP Pro <jpmythic@ntlworld.com>
Re: Annoying Problem with a Basic Perl app and XP Pro <jpmythic@ntlworld.com>
Re: Annoying Problem with a Basic Perl app and XP Pro <wyzelli@yahoo.com>
Re: Annoying Problem with a Basic Perl app and XP Pro <wyzelli@yahoo.com>
BerkeleyDB locking question <admin@asarian-host.net>
Re: BerkeleyDB locking question <leslievNO@SPAMicoc.co.za>
Re: BerkeleyDB locking question <admin@asarian-host.net>
Re: BerkeleyDB locking question <Paul.Marquess@btinternet.com>
Comparing huge XML Files <junnuthula@yahoo.com>
Re: cubic root subroutine <do-not-use@invalid.net>
Re: cubic root subroutine <sbryce@scottbryce.com>
Re: cubic root subroutine <1usa@llenroc.ude.invalid>
Re: exercise: partition a list by equivalence <eppstein@ics.uci.edu>
Re: exercise: partition a list by equivalence <xah@xahlee.org>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 22 Feb 2005 18:31:59 -0800
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: '+<' mode for opening files
Message-Id: <1109125919.021550.78850@o13g2000cwo.googlegroups.com>
Abigail wrote:
> Paul Lalli (mritty@gmail.com) wrote on MMMMCXCIII September MCMXCIII
in
> <URL:news:6gLSd.68077$g16.42650@trndny08>:
> // and the input file now contains:
> // 1
> // 2
> // 3
> // 4
> // 5
> // 1
> // A
>
> Really? What version of Perl, and what OS?
I have access to three perl's:
"This is perl, v5.8.0 built for sun4-solaris"
"This is perl, v5.8.2 built for sun4-solaris-thread-multi"
"This is perl, v5.8.4 built for MSWin32-x86-multi-thread"
All three produce the same result
> Because that's wrong. What
> should be in the input file is:
>
> 1
> A
> 3
> 4
> 5
That's what I would expect... and that is what I receive when I seek to
the current position as Xho suggested earlier today. From the
documentation of seek, I would say this is a known issue? <shrug>
Paul Lalli
------------------------------
Date: Tue, 22 Feb 2005 23:22:14 -0500
From: Eric Amick <eric-amick@comcast.net>
Subject: Re: '+<' mode for opening files
Message-Id: <2s0o1117qh0n49m8vude6dkqjr45e66vk7@4ax.com>
On Tue, 22 Feb 2005 23:35:01 +0100, Gunnar Hjalmarsson
<noreply@gunnar.cc> wrote:
>Abigail wrote:
>> Paul Lalli wrote:
>>> For example, a sample input file contains the five lines:
>>> 1
>>> 2
>>> 3
>>> 4
>>> 5
>>>
>>> Executing the following script:
>>> #!/usr/bin/perl
>>> use strict;
>>> use warnings;
>>> open my $fh, '+<', 'input.txt' or die "Cannot open: $!\n";
>>> my $line = <$fh>;
>>> print "Line is: $line";
>>> print $fh "A\n";
>>> __END__
>>>
>>> results in output of:
>>> Line is: 1
>>>
>>> and the input file now contains:
>>> 1
>>> 2
>>> 3
>>> 4
>>> 5
>>> 1
>>> A
>>
>> Really? What version of Perl, and what OS? Because that's wrong. What
>> should be in the input file is:
>>
>> 1
>> A
>> 3
>> 4
>> 5
>
>Paul's post surprised me too, but I repeated his result on my W98 box
>(perl 5.8.0). On Linux I get the expected result.
>
>Explicitly using seek() produced the expected result on W98 as well.
ANSI C (which underlies PerlIO on some systems) requires a file
positioning call such as seek() when switching from reading to writing
or vice versa, otherwise the result is undefined.
--
Eric Amick
Columbia, MD
------------------------------
Date: 23 Feb 2005 00:51:46 -0800
From: "arek" <jpmythic@ntlworld.com>
Subject: Annoying Problem with a Basic Perl app and XP Pro
Message-Id: <1109148706.355661.207320@z14g2000cwz.googlegroups.com>
New to perl, but not new to C++. I wanted a simple and efficeint app
to update some small pages to a remote website. I had used a old perl
app in Linux before called AutoFtp.pl, so I looked for it and did some
modifications. It was working fine on my Test workstations, (XP Home),
so I figured I had it licked and moved to the Main Server, (XP Pro).
Now I am getting nowhere, Literally. The application runs, but does
absolutely nothing....
heres the script: (A modified AutoFtp.pl)
<------------------------------------------------------->
# Automatically FTP files to the web site.
#
# The movfiles.txt file lists which files should be transfered.
# It compares the last modification time of each file to see if it has
been updated.
# Only updated files are transfered.
#
# Changes to the primary site only require their information files to
be updated.
# After successfully updating it sleeps until next transfer time.
#
# A logfile is kept of updates done.
# Only Extreme Failures will cause it to DIE.
#-----------------------------------------------------------------------------
use English;
use strict;
use Time::Local;
use Net::FTP;
my $mov_file; # List of Files to transfer
my $log_file; # Log file to store information
my $primary_info; # WebSite connection information
my $now_string; # Current Time for Log File
my $time_period; # Time Period to transfer files
my @ftp_commands; # List of commands to send to FTP.
my @raw_files; # contents of newfiles.txt
my @files; # Final list after removing Dupes to transfer
my $primary_web; # Web Site url
my $primary_directory; # Web Site directory to store in
my $primary_username; # Username to login
my $primary_password; # Password 'Duh'
my $file_time; # File's Last Modified time
my $system; # System time to check last Modification time
$log_file = "logFtp.txt";
$mov_file = "movfiles.txt";
$primary_info = "primary.inf";
$time_period = 1800; # Every 1/2 hr
#-------------------------------------------------------------
# Main body that calls the Transfer routine
# Sleeps for specified period
# Checks for Updated files to transfer
# ONLY a few DIE statements used for Extreme failures will kill it
# I have it SLEEP first as I don't need it to UPDATE on initial
startup.
#-------------------------------------------------------------
do {
sleep $time_period; # Sleep until next transfer time
main_transfer(); # Transfer Status files
} while (1); # Forever loop as XP Scheduler SUCKS!!
# ----------------------------------------------------------------
# Primary Transfer routine here
# Called by Do Loop once per PreSet Time to transfer updated files
#
# Paramters:
# None
# Return Value:
# None
#-----------------------------------------------------------------
sub main_transfer {
# Only have something to do if there is a list of new files.
if (-f "$mov_file")
{
my $result;
($primary_web, $primary_directory, $primary_username,
$primary_password) = parse_information_file $primary_info);
open FILES, "$mov_file" || die write_log("Unable to open file
$mov_file");
@raw_files = <FILES>;
@files = remove_duplicates(@raw_files);
close(FILES);
$result = put_files($primary_web, $primary_directory,
$primary_username, $primary_password, @files);
if( $result == 0 )
{
write_log("Primary Transfer Failed");
}
elsif ( $result == 1 )
{
write_log("File transfer to primary completed");
}
}
else
{
die write_log("Unable to find $mov_file");
}
}
#----------------------------------------------------------------------------
# Write a file via FTP using the specified user information.
# Parameters:
# hostname - name of the host that contains the file.
# directory - the directory that contains the file.
# username - log in name
# password - duh
# files - the name of the files to get.
#
# Return value:
# boolean - true if the FTP was successful, false if not.
#----------------------------------------------------------------------------
sub put_files {
my $hostname = shift @_;
my $directory = shift @_;
my $username = shift @_;
my $password = shift @_;
my @files = @_;
my $n_files;
my $file;
my $ret;
my $ftp;
my @transfers;
my $dotransfers;
$n_files = @files;
$dotransfers = 0;
clear_ftp();
if ($n_files > 0)
{
my $count;
$count = 0;
foreach $file (@files)
{
# The Job runs at a PreSet time period
$file_time = (stat($file))[9];
$system = time;
$system -= $file_time;
# Has the file been changed within the last time Period?
if ( $system < $time_period )
{
$transfers[$count] = $file;
$count++;
$dotransfers = 1;
}
}
if( !($dotransfers) )
{
# write_log("No updated files to transfer, exiting Ftp.");
$ret = 2;
return $ret;
}
# print "FTP to $hostname - ";
if( !($ftp = Net::FTP->new($hostname, Timeout => 30)) )
{
write_log("Can't connect to $hostname: $ERRNO");
return $ret;
}
if( !($ftp->login($username, $password)) )
{
write_log("Can't login with <$username> <$password>: $ERRNO");
return $ret;
}
if ($directory ne "")
{
if( !($ftp->cwd($directory)) )
{
write_log("Can't cwd to <$directory>: $ERRNO");
return $ret;
}
}
$ftp->type("I"); # binary mode
foreach $file (@transfers)
{
# file updated --> transfer
if( !($ftp->put($file)) )
{
write_log("Can't put $file: $ERRNO");
return $ret;
}
}
if( !($ftp->quit()) )
{
write_log("Couldn't quit FTP: $ERRNO");
}
$ret = 1;
}
return $ret;
} #put_files
#------------------------------------------------------------------------------
# Collect commands to send to FTP.
# Parameters:
# line - a new line to send
# Return value:
# none
#------------------------------------------------------------------------------
sub collect_ftp {
my $line = @_[0];
push @ftp_commands, $line;
} # collect_ftp
#------------------------------------------------------------------------------
# Clear out list of commands to send to FTP.
# Parameters:
# none
# Return value:
# none
#------------------------------------------------------------------------------
sub clear_ftp {
@ftp_commands = ();
} # clear_ftp
#------------------------------------------------------------------------------
# Send commands to FTP.
# Parameters:
# args - list of FTP commands
# Return value:
# none
#------------------------------------------------------------------------------
sub send_ftp {
my $line;
my $command_line;
$command_line = shift(@_);
if ( open(FTP, "$command_line") )
{
for $line (@_)
{
print FTP "$line\n";
}
print FTP "disconnect\n";
print FTP "bye\n";
close(FTP);
}
else
{
write_log("FTP Connection failed");
write_log($command_line);
return;
}
} # send_ftp
#----------------------------------------------------------------------------
# Scan a site information file and return the site, directory, username
and
# password entries.
#
# Parameters:
# file - name of the information file.
# Return value:
# list - site, directory, username, password.
#------------------------------------------------------------------------------
sub parse_information_file
{
my $file = $_[0];
my $site = "";
my $directory = "";
my $username = "";
my $password = "";
my $keyword;
my $value;
open INFO, "$file" || die write_log("Unable to open FTP site
information file $file\n");
while (<INFO>)
{
($keyword, $value) = split;
if ($keyword eq "site")
{
$site = $value;
}
elsif ($keyword eq "directory")
{
$directory = $value;
}
elsif ($keyword eq "username")
{
$username = $value;
}
elsif ($keyword eq "password")
{
$password = $value;
}
else
{
write_log("Unknown keyword in FTP site information file $file: ");
write_log($keyword);
die;
}
}
return ($site, $directory, $username, $password);
} # parse_information_file
#------------------------------------------------------------------------
# Remove duplicates from a list. A side-effect is that the return
values are
# sorted.
#
# Parameters:
# in_list - list which may have duplicate entries.
# Return value:
# out_list - in_list, sorted with duplicates removed.
#------------------------------------------------------------------------------
sub remove_duplicates {
my @unsorted_in_list = @_;
my @in_list;
my @out_list;
my $element;
my $last_element;
@in_list = sort @unsorted_in_list;
# Prime the pump.
$element = shift(@in_list);
chop $element;
@out_list = ($element);
$last_element = $element;
foreach $element (@in_list)
{
chop $element;
if ($element eq $last_element)
{
next;
}
$last_element = $element;
push(@out_list, $element);
}
return @out_list;
} #remove_duplicates
#------------------------------------------------------------------------------
# Write Information to LogFile
# Parameters:
# Info String
# Return value:
# none
#------------------------------------------------------------------------------
sub write_log {
open LOGFILE, ">>", "$log_file" || die "Unable to open file
$log_file";
my $log_data = $_[0];
$now_string = localtime;
print LOGFILE "$now_string : $log_data\n";
close LOGFILE;
} # write_log
<----------------------------------------------------->
It's very simple... It shouldn't be doing what it is doing, which is
absolutely nothing at all...
No errors on compile, no errors during running, NO Log writes either.
The machines I first tested it on were XP Home with the latest 5.++
The XP Pro box has the Same version installed from the same download.
No major applications except the Primary Server app running on the XP
Pro box.
The XP Pro box is whittled down to as few services as neccessary as the
primary application uses well over 300MB Ram and runs 24/7.
I've tried running the Perl App from cmd.exe by hand, by Shortcut with
the appropriate command line settings to start it.. all start up, but
nothing.
The Perl App is started in the SAME directory as the Files it accesses
so I don't need to
change directories, (It's a specialised application, so no sense having
do extra work).
I set the cmd.exe to the correct Dir as the Perl App when I have a XP
shortcut to start it.
I also tried manually starting it from cmd.exe after changing to the
correct Dir.
I suspect several possible causes:
File permissions? All files are created by the Same User running the
App.
File Times: This one I am not sure about, but have manually changed
the file so it's time is within update time.
Some days I really HATE MS. As far as I can figure this has to be an
issue with XP Pro. I am aware that it has some differences from XP
Home...
I've looked through the lists, but this issue hasn't shown up...
Any help would be appreciated..
Thx
------------------------------
Date: Wed, 23 Feb 2005 09:44:35 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Annoying Problem with a Basic Perl app and XP Pro
Message-Id: <Xns960630410FD71asu1cornelledu@127.0.0.1>
"arek" <jpmythic@ntlworld.com> wrote in
news:1109148706.355661.207320@z14g2000cwz.googlegroups.com:
[ lotsa lines of code snipped ]
> No errors on compile, no errors during running, NO Log writes either.
D:\Home\asu1\UseNet\clpmisc> perl -c v.pl
Scalar value @_[0] better written as $_[0] at v.pl line 195.
syntax error at v.pl line 62, near "$primary_info)"
syntax error at v.pl line 245, near "and"
v.pl had compilation errors.
> Some days I really HATE MS.
Whatever ...
Sinan
------------------------------
Date: 23 Feb 2005 02:08:16 -0800
From: "arek" <jpmythic@ntlworld.com>
Subject: Re: Annoying Problem with a Basic Perl app and XP Pro
Message-Id: <1109153296.612715.40020@o13g2000cwo.googlegroups.com>
Actually those were caused by Wrapping during post...
It DOES compile without errors if you correct the Wrapping in the Post.
As I said, "It Compiles without Errors AND works on the XP Home boxes"
So a more usefull reply would be appreciated...
as for the @_[0] better as $_[0], I was not sure and had NOT changed
that from
the Original Authors AutoFtp.pl code as it worked fine.
Not trying to be nasty, but those Compile Errors are not Code issues,
just failure to
look at the Code before just cutting and pasting it and running it.. I
am quite used to
watching out for Wrapping problems from Web Based copys...
------------------------------
Date: 23 Feb 2005 02:15:51 -0800
From: "arek" <jpmythic@ntlworld.com>
Subject: Re: Annoying Problem with a Basic Perl app and XP Pro
Message-Id: <1109153751.092774.281480@g14g2000cwa.googlegroups.com>
Also, it WILL fail if the following Files do NOT exist in the same Dir:
movfiles.txt
primary.inf
movfiles:
a simple txt list of files to find / check modification times /
transfer
Example: status.html (a one line list, file--> status.html
MUST exist)
primary.inf:
A list of Data for AutoFtpCode.pl to parse as Commands to FTP
Example: (Seperate each command/data by a space)
site www.somewhere.com
directory www
username someone
password something
without these it will not run correctly
just create them for an appropriate site, I used Cerebrus FTP and ran
it on the Same Machine
to do the basic testing before having it connect to the Actually Remote
site.
------------------------------
Date: Wed, 23 Feb 2005 10:51:00 GMT
From: "Peter Wyzl" <wyzelli@yahoo.com>
Subject: Re: Annoying Problem with a Basic Perl app and XP Pro
Message-Id: <oeZSd.172385$K7.35073@news-server.bigpond.net.au>
"arek" <jpmythic@ntlworld.com> wrote in message
news:1109153296.612715.40020@o13g2000cwo.googlegroups.com...
: Actually those were caused by Wrapping during post...
: It DOES compile without errors if you correct the Wrapping in the Post.
:
: As I said, "It Compiles without Errors AND works on the XP Home boxes"
:
: So a more usefull reply would be appreciated...
:
: as for the @_[0] better as $_[0], I was not sure and had NOT changed
: that from
: the Original Authors AutoFtp.pl code as it worked fine.
:
: Not trying to be nasty, but those Compile Errors are not Code issues,
: just failure to
: look at the Code before just cutting and pasting it and running it.. I
: am quite used to
: watching out for Wrapping problems from Web Based copys...
Those are not cut and paste errors. I also did the cut and paste, fixed all
the line wrap errors, and get the same errors as Sinan. A close inspection
shows a missing left bracket and a scalar epressed as a single element
slice. #1 prevents compiling, #2 is a simple warning elicited by turning
on -w or warnings, the first thing to do in diagnosing such problems.
This is not and 'XP' problem, it is a 'Bad Code' problem.
It is also not exactly the same as whatever code _IS_ working on the XP Home
PC.
P
--
print "Just another Perl Hacker";
------------------------------
Date: Wed, 23 Feb 2005 10:55:15 GMT
From: "Peter Wyzl" <wyzelli@yahoo.com>
Subject: Re: Annoying Problem with a Basic Perl app and XP Pro
Message-Id: <niZSd.172389$K7.93343@news-server.bigpond.net.au>
"arek" <jpmythic@ntlworld.com> wrote in message
news:1109148706.355661.207320@z14g2000cwz.googlegroups.com...
: New to perl, but not new to C++. I wanted a simple and efficeint app
: to update some small pages to a remote website. I had used a old perl
: app in Linux before called AutoFtp.pl, so I looked for it and did some
: modifications. It was working fine on my Test workstations, (XP Home),
: so I figured I had it licked and moved to the Main Server, (XP Pro).
:
: Now I am getting nowhere, Literally. The application runs, but does
: absolutely nothing....
You are aware that the first thing the program does (after fixing the main
errors, see Sinan and my other post) is sleep for 30 minutes?
P
--
print "Just another Perl Hacker";
------------------------------
Date: Wed, 23 Feb 2005 06:23:07 +0100
From: "Mark" <admin@asarian-host.net>
Subject: BerkeleyDB locking question
Message-Id: <eeednawM8s2mjoHfRVnyiQ@giganews.com>
I have a small locking question.
When two different processes are using, say, tie %h, "BerkeleyDB::Hash",
and both try to write to the same database, using, say, $h{"apple"} =
"red", do they need some IPC locking between them? Or do you only need
locking within the same process? I read the BerkeleyDB manual, which talks
a lot about write 'cursors' and such, but I could not really find my answer.
I would appreciate any suggestions,
- Mark
------------------------------
Date: Wed, 23 Feb 2005 11:28:13 +0200
From: Leslie Viljoen <leslievNO@SPAMicoc.co.za>
Subject: Re: BerkeleyDB locking question
Message-Id: <nr2dneZfGJMt0YHfRVn-gg@is.co.za>
Mark wrote:
> I have a small locking question.
>
> When two different processes are using, say, tie %h, "BerkeleyDB::Hash",
> and both try to write to the same database, using, say, $h{"apple"} =
> "red", do they need some IPC locking between them? Or do you only need
> locking within the same process? I read the BerkeleyDB manual, which talks
> a lot about write 'cursors' and such, but I could not really find my answer.
>
> I would appreciate any suggestions,
>
> - Mark
>
>
Yes, you do need locking. You can find the underlying file
that the tie is using and use flock to lock it...
Here's where to find some great info on it all:
http://www.hk8.org/old_web/linux/dbi/ch02_07.htm
Here's the recommended code:
use Fcntl; # import O_EXLOCK, if available
### Create the new database ...
$db = tie %database, 'DB_File', "megaliths.dat", O_EXLOCK
or die "Can't initialize database: $!\n";
### Acquire the file descriptor for the DBM file
my $fd = $db->fd();
### Do a careful open() of that descriptor to get a Perl filehandle
open DATAFILE, "+<&=$fd" or die "Can't safely open file: $!\n";
### And lock it before we start loading data ...
print "Acquiring an exclusive lock...";
flock( DATAFILE, LOCK_EX )
or die "Unable to acquire exclusive lock: $!. Aborting";
print "Acquired lock. Ready to update database!\n\n";
--------------
Leslie Viljoen
perl -e '$str="Kvtu!Bopuifs!Qfsm!Ibdlfs";for($i=0;$i<length($str);$i++)
{print(chr(ord(substr($str,$i,1))-1));}print"\n";'
------------------------------
Date: Wed, 23 Feb 2005 11:09:47 +0100
From: "Mark" <admin@asarian-host.net>
Subject: Re: BerkeleyDB locking question
Message-Id: <hZGdnRsimI_3y4HfRVnygg@giganews.com>
"Leslie Viljoen" <leslievNO@SPAMicoc.co.za> wrote in message
news:nr2dneZfGJMt0YHfRVn-gg@is.co.za...
>> I have a small locking question.
>>
> Yes, you do need locking. You can find the underlying
> file that the tie is using and use flock to lock it...
>
> Here's where to find some great info on it all:
> http://www.hk8.org/old_web/linux/dbi/ch02_07.htm
>
> Here's the recommended code:
>
> use Fcntl; # import O_EXLOCK, if available
>
> ### Create the new database ...
> $db = tie %database, 'DB_File', "megaliths.dat", O_EXLOCK
> or die "Can't initialize database: $!\n";
Thank you for your reply. This is about DB_File; but does it apply to the
package BerkeleyDB too? (as in "use BerkeleyDB")? I get the distinct
impression that BerkeleyDB uses some internal locking (which could be
done, I suppose, since it uses shared memory, too). Only, its
documentation:
http://search.cpan.org/~pmqs/BerkeleyDB-0.26/BerkeleyDB.pod
is not clear about this at all.
Thanks,
- Mark
------------------------------
Date: Wed, 23 Feb 2005 10:15:30 -0000
From: "Paul Marquess" <Paul.Marquess@btinternet.com>
Subject: Re: BerkeleyDB locking question
Message-Id: <3833e5F5fj92fU1@individual.net>
"Leslie Viljoen" <leslievNO@SPAMicoc.co.za> wrote in message
news:nr2dneZfGJMt0YHfRVn-gg@is.co.za...
> Mark wrote:
> > I have a small locking question.
> >
> > When two different processes are using, say, tie %h, "BerkeleyDB::Hash",
> > and both try to write to the same database, using, say, $h{"apple"} =
> > "red", do they need some IPC locking between them? Or do you only need
> > locking within the same process? I read the BerkeleyDB manual, which
talks
> > a lot about write 'cursors' and such, but I could not really find my
answer.
> >
> > I would appreciate any suggestions,
> >
> > - Mark
> >
> >
>
> Yes, you do need locking. You can find the underlying file
> that the tie is using and use flock to lock it...
If you want to use DB_File, an external lock file is the way to go, but for
the BerkeleyDB module, you can get better locking semantics by using the
locking provided by the underlying Berkele DB library.
The simplest form of locking available in Berkeley DB is called Concurrent
Data Store CDS. It allows single writer, multiple readers.
Here is the typical signature that is used when opening a database in CDS
mode.
use BerkeleyDB ;
my $env = new BerkeleyDB::Env
-Home => "./home" ,
-Flags => DB_CREATE| DB_INIT_CDB | DB_INIT_MPOOL
or die "cannot open environment: $BerkeleyDB::Error\n";
my $db = new BerkeleyDB::Hash
-Filename => 'test1.db',
-Flags => DB_CREATE,
-Env => $env
or die "cannot open database: $BerkeleyDB::Error\n";
or this, if you use the tied interface
tie %hash, "BerkeleyDB::Hash",
-Filename => 'test2.db',
-Flags => DB_CREATE,
-Env => $env
or die "cannot open database: $BerkeleyDB::Error\n";
Apart from that you don't need to do anything -- Berkeley DB handles the
locking for you behind the scenes.
Paul
------------------------------
Date: 23 Feb 2005 00:14:51 -0800
From: "junnuthala" <junnuthula@yahoo.com>
Subject: Comparing huge XML Files
Message-Id: <1109146491.730966.318020@o13g2000cwo.googlegroups.com>
Hello,
Can someone please suggest me a Perl module for comparing huge XML
Files.
I tried XML::SemanticDiff, but it is taking a lots and lots of time to
load the XML File nodes, elements and attributes to the Hash.
Any suggestions would be really appreciated.
Thank you
-Venkat
------------------------------
Date: 23 Feb 2005 09:36:19 +0100
From: Arndt Jonasson <do-not-use@invalid.net>
Subject: Re: cubic root subroutine
Message-Id: <yzdoeebzn98.fsf@invalid.net>
"A. Sinan Unur" <1usa@llenroc.ude.invalid> writes:
> Arndt Jonasson <do-not-use@invalid.net> wrote in
> news:yzdsm3ozohc.fsf@invalid.net:
>
> >
> > "A. Sinan Unur" <1usa@llenroc.ude.invalid> writes:
>
> >> >> Arndt Jonasson wrote:
> >> > Yes, I meant "comes back from the cube root subroutine". But it is
> >> > a problem on my machine:
> >> >
> >> > perl -e 'printf "%d\n", int(64**(1/3))'
> >> > 3
> >>
> >> int EXPR
> >> int Returns the integer portion of EXPR. If EXPR is omitted,
> >> uses $_. You should not use this function for rounding:
>
> ...
>
> >> These calculations necessary to calculate the power of a number are
> >> performed in floating point by Perl. If you are going to use the
> >> number in other calculations, you should leave it as it is instead
> >> of jumping through a bunch of hoops.
> >>
> >> On the other hand, if you just wanted to report results in integers:
> >>
> >> D:\> perl -e "printf q{%.0f}, ((64)**(1/3))"
> >> 4
> >
> > Call me dense, but I'm not sure if you're taking issue with my
> > statement, or just providing additional information.
>
> I am taking issue with your statement "it is a problem on my machine".
> You seem to think there is a problem when in actuality, the behavior you
> are observing is only due to the fact that you used the '%d' format for
> printf instead of the more appropriate '%.0f' format.
>
> There is nothing you can do about the fact that:
>
> perl -e "printf q{%.16f}, ((64)**(1/3))"
>
> will print something like
>
> 3.9999999999999996
>
> i.e. it is impossible to:
>
> <quoted from another message of yours>
> ... it may be worth making sure that the cube of an integer always
> comes back as an integer, and not with a little rounding-error,
> </quoted from another message of yours>
>
> For values used in interim calculations, you should not bother "fixing"
> anything. For values that are printed, you should use the appropriate
> printf format.
I think you are misunderstanding what I perceive as the problem. I
stand by my original warning (and did not use the word "fixing", so
your quotation marks are not warranted). "It may be worth" was to be
read in the sense that you are fully entitled to consider it not worth
it, if the results are good enough for you - not that the results are
wrong. My print statement only showed that the suggested cube root
calculation is not what you want if you want the cube root of the cube
of an integer to be the original integer. If printing out was all I
wanted, there is no problem. But you cut out the end of my warning,
which was something like "depending on the application". If I remember
correctly (which I maybe don't), the original poster didn't say what
he wanted to use the cube root for.
(Seeing it from another angle: if I had just come into the group with
my "problem" as the original posting, your reply would be 100%
appropriate. Thank you.)
A "fix" would be an actual integer cube root routine (one that returns
$x when given $x**3 as input, $x being an integer). We haven't seen
one yet, but it's left as an exercise for the interested reader.
------------------------------
Date: Wed, 23 Feb 2005 01:52:43 -0700
From: Scott Bryce <sbryce@scottbryce.com>
Subject: Re: cubic root subroutine
Message-Id: <v46dneECKqfG2YHfRVn-1g@comcast.com>
Arndt Jonasson wrote:
> A "fix" would be an actual integer cube root routine (one that returns
> $x when given $x**3 as input, $x being an integer). We haven't seen
> one yet, but it's left as an exercise for the interested reader.
Did I miss something? I thought I posted one.
------------------------------
Date: Wed, 23 Feb 2005 10:01:27 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: cubic root subroutine
Message-Id: <Xns9606331D860E7asu1cornelledu@127.0.0.1>
Arndt Jonasson <do-not-use@invalid.net> wrote in
news:yzdoeebzn98.fsf@invalid.net:
>
> "A. Sinan Unur" <1usa@llenroc.ude.invalid> writes:
...
>> For values used in interim calculations, you should not bother
>> "fixing" anything. For values that are printed, you should use the
>> appropriate printf format.
...
> (and did not use the word "fixing", so your quotation marks are not
> warranted).
In this instance, I did not use the quotation marks to indicate I was
quoting you, but to qualify the word.
Sinan
------------------------------
Date: Sun, 20 Feb 2005 09:59:21 -0800
From: David Eppstein <eppstein@ics.uci.edu>
Subject: Re: exercise: partition a list by equivalence
Message-Id: <eppstein-2D7D22.09592120022005@news.service.uci.edu>
In article <1108895373.013257.192310@l41g2000cwc.googlegroups.com>,
"John Machin" <sjmachin@lexicon.net> wrote:
> > it would be nice if the two working programs do not use some package.
> > This problem shouldn't need to.
>
> Look at the newsgroup again. By my count there are apparently-working
> versions from SIX people: Reinhold, bear.+, Brian Beck, David Eppstein,
> yourself, and me. Only David's uses stuff that's not in the Python 2.4
> off-the-shelf distribution.
Where "stuff" means a single 62-line file that I linked to in my post.
--
David Eppstein
Computer Science Dept., Univ. of California, Irvine
http://www.ics.uci.edu/~eppstein/
------------------------------
Date: 23 Feb 2005 00:24:07 -0800
From: "Xah Lee" <xah@xahlee.org>
Subject: Re: exercise: partition a list by equivalence
Message-Id: <1109147047.707182.269960@l41g2000cwc.googlegroups.com>
I started to collect i believe the 4 or so solutions by different
people... but seems it's gonna take some an hour or more... So far the
only other one i've run and find alright is Reinhold Birkenfeld's
original. Others worth noting i'm aware of is David Epsteinn, improved
versions from Reinhold Birkenfeld, the one using graphs by bearophile
...
since many of you have already collected and tested these... i wonder
if anyone'd be interested to put together all the (working) code in a
single message? (or even a webpage.)
thanks.
Xah
xah@xahlee.org
http://xahlee.org/PageTwo_dir/more.html
------------------------------
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.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 7815
***************************************