Re: external hashtable

2002-03-19 Thread Peter_Farrar


The book from O'Reilly, Perl DBI, chapter 2, has a good look at
Data::Dumper and other approaches that could work here.



   
 
Jonathan E.   
 
PatonTo: [EMAIL PROTECTED]   
 
jonathanpaton@   cc:  
 
yahoo.comSubject: Re: external hashtable  
 
   
 
03/18/2002 
 
10:41 AM   
 
   
 
   
 




 Ok, I'm on a Linux box here. and I do have
 Data::Dumper.

:)

 So how would the solution with Dumper work?
 There is not very much documentation on Dumber
 in the camel...

s/Dumber/the smarter way/;

I suggest you search via your favourite search
engine, or if you don't mind reading a little:

perldoc Data::Dumper

To output:

print FILE Data::Dumper-Dump(\%hash);

Reading might be the same as I showed, don't
know.

Jonathan Paton

__
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

--
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]




external hashtable

2002-03-18 Thread Martin A. Hansen

hi

i have some files of the format:

{
'key1' = 'value2',
'key2' = 'value3',
'key3' = 'value4',
'key4' = 'value5',
'key5' = 'value6',
}

the values are large huge chunks of text.

how can i import such a file into a perl script as a hash?
and how can i write the hash to a new file (same format as above)?

best :)

martin

-- 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: external hashtable

2002-03-18 Thread Jonathan E. Paton

 If it's that big you might want to 'tie' the hash
 to a DB file.  But it's too early in morning for
 me to go into explaining how. anyone want to jump
 in on this?

Don't know enough to be able to implement something
that works for him.  Platform etc.

I suggest Data::Dumper, which can do exactly this
function.

 how can I import such a file into a perl script
 as a hash?

my %data;
{
local @ARGV = 'file.data';
local $\ = undef;
eval '%data = ' . ;
}
# Untested

  and how can I write the hash to a new
 file (same format as above)?

print FILE {\n;
while (my ($key, $value) = each %data) {
print FILE $key . = . $value;
}
print FILE }\n;
# Untested

Jonathan Paton

__
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: external hashtable

2002-03-18 Thread Martin A. Hansen

ok, im on a linux box here. and i do have Data::Dumper.

so how would the solution with Dumper work? theres not very much documentation on 
Dumber in the camel...

martin

 I suggest Data::Dumper, which can do exactly this
 function.
 

-- 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: external hashtable

2002-03-18 Thread Jonathan E. Paton

 Ok, I'm on a Linux box here. and I do have
 Data::Dumper.

:)

 So how would the solution with Dumper work?
 There is not very much documentation on Dumber
 in the camel...

s/Dumber/the smarter way/;

I suggest you search via your favourite search
engine, or if you don't mind reading a little:

perldoc Data::Dumper

To output:

print FILE Data::Dumper-Dump(\%hash);

Reading might be the same as I showed, don't
know.

Jonathan Paton

__
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




how do i utilize an external hashtable?

2002-01-28 Thread Martin A. Hansen


hi

if i have a file called table.hash looking like this:


{
'HEADLINE' = 'Carcinoma in Situ',

'SUBHEADLINE' =
'
the precursor cell for testicular germ cell cancer in adolescents and young adults
',

'BODYTEXT' =
'
This site provides information on research, diagnosis and management
of early forms of testicular cancer and is directed to physicians,
researchers and patients.
The site has been developed by members of the CIS  Testis Cancer
Research Group led by Professor Niels E. Skakkebæk, MD at the
Department of Growth  Reproduction in collaboration with the Danish
Cancer Society, Copenhagen, Denmark.
'
}


how do i access the hashtable with a key and return the appropriate
value?


martin


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: how do i utilize an external hashtable?

2002-01-28 Thread Casey West

On Mon, Jan 28, 2002 at 06:13:26PM +0100, Martin A. Hansen wrote:
:hi
:
:if i have a file called table.hash looking like this:
:
[ snipped hash data ]
:
:how do i access the hashtable with a key and return the appropriate
:value?

Hey martin, in order to use the file that you showed us, use the
following code as an example:

  my $hashfile = 'file';

  # open the file and slurp it all up into $hashdata
  open HF, $hashfile or die $!;
  my $hashdata = do { local $/; HF };  # perldoc perlvar for $/
  close HF;

  # eval the $hashdata as a hash reference.. turns this into
  # 'my $hash = { ... };
  my $hash = eval $hashdata;   # perldoc -f eval
  die $@ if $@;# perldoc perlvar for $@

  # now just use the hash reference
  print $hash-{one}\n;


Enjoy!

  Casey West

-- 
Considering the flames and intolerance, shouldn't USENET be spelled
ABUSENET? 
 -- Michael Meissner

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]