Re: MLDBM adding records
Rus You can't use the concatenation character on hashes. It's for "str"."ings" only. >From what you've said, you just need to set each hash entry: $hash{1} = { url => "www.slashdot.org" , title => "News for nerds" , lastvisit =>" 10" }; $hash{2} = { url => "www.slashdot.org" , title => "News for nerds" , lastvisit =>" 10" }; But are you sure you shouldn't just be using an array? push @array, { url => "www.slashdot.org" , title => "News for nerds" , lastvisit =>" 10" }; push @array, { url => "www.slashdot.org" , title => "News for nerds" , lastvisit =>" 10" }; HTH. Rob - Original Message - From: "Rus Foster" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Tuesday, October 15, 2002 2:31 PM Subject: MLDBM adding records > Hi all, > I'm trying to do a proof of concept for myself using MLDBM of basically > trying to add two records to a hash. ATM I have the following code > > #!/usr/bin/perl > > use strict ; > use warnings ; > use MLDBM; > use Fcntl ; > > my %hash ; > my $filename = "/tmp/filt" ; > unlink $filename ; > > my $db = tie(%hash, 'MLDBM', $filename, O_RDRW|O_EXLOCK, 0640) or die > ("Cannot open $filename: $!\n"); > >%hash = ( '1' => { url => "www.slashdot.org" , title => "News for > nerds" , lastvisit =>" 10" } ); > %hash .= ( '2' => { url => "www.slashdot.org" , title => "News for > nerds" , lastvisit =>" 10" } ); > > > print Data::Dumper->Dump ( [\%hash ]); > undef $db; > untie %hash; > > and I'm getting > > Can't modify private hash in concatenation (.) or string at ./perldbm line > 15, near ");" > > As such what do I have to do to add entries to the hash (without defining > it all in one hash?) The reason is that I want to writ eaprorgam that will > add a hash each time it is run so just trying to do it on a simple prog > ATM > > Rus > -- > http://www.fsck.me.uk - My blog > http://shells.fsck.me.uk - Hosting how you want it. > > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: MLDBM adding records
From: Rus Foster <[EMAIL PROTECTED]> >%hash = ( '1' => { url => "www.slashdot.org" , title => "News for > nerds" , lastvisit =>" 10" } ); > %hash .= ( '2' => { url => "www.slashdot.org" , title => "News for > nerds" , lastvisit =>" 10" } ); > > and I'm getting > > Can't modify private hash in concatenation (.) or string at ./perldbm > line 15, near ");" What is the .= supposed to mean??? You can concatenate strings, not hashes! The coe should look like this: %hash = ( '1' => { url => "www.slashdot.org" , title => "News for nerds" , lastvisit =>" 10" } ); # here I set the whole hash to contain just those values $hash{'2'} = { url => "www.slashdot.org" , title => "News for nerds" , lastvisit =>" 10" }; # here I change only the value for the '2' key. HTH, Jenda=== [EMAIL PROTECTED] == http://Jenda.Krynicky.cz == When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
MLDBM adding records
Hi all, I'm trying to do a proof of concept for myself using MLDBM of basically trying to add two records to a hash. ATM I have the following code #!/usr/bin/perl use strict ; use warnings ; use MLDBM; use Fcntl ; my %hash ; my $filename = "/tmp/filt" ; unlink $filename ; my $db = tie(%hash, 'MLDBM', $filename, O_RDRW|O_EXLOCK, 0640) or die ("Cannot open $filename: $!\n"); %hash = ( '1' => { url => "www.slashdot.org" , title => "News for nerds" , lastvisit =>" 10" } ); %hash .= ( '2' => { url => "www.slashdot.org" , title => "News for nerds" , lastvisit =>" 10" } ); print Data::Dumper->Dump ( [\%hash ]); undef $db; untie %hash; and I'm getting Can't modify private hash in concatenation (.) or string at ./perldbm line 15, near ");" As such what do I have to do to add entries to the hash (without defining it all in one hash?) The reason is that I want to writ eaprorgam that will add a hash each time it is run so just trying to do it on a simple prog ATM Rus -- http://www.fsck.me.uk - My blog http://shells.fsck.me.uk - Hosting how you want it. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]