CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Advanced:
How to store in file complex hash?

 



woffs
New User

Nov 12, 2003, 10:46 AM

Post #1 of 7 (1297 views)
How to store in file complex hash? Can't Post

Hello!

How to store in file complex hash?


noslenj123
New User

Nov 12, 2003, 9:17 PM

Post #2 of 7 (1293 views)
Re: [woffs] How to store in file complex hash? [In reply to] Can't Post

What would be the purpose?

Otherwise maybe:

open (IN,"<myfile") || die "Can't open myfile, $!";
$hash{file} = @{<IN>};
close (IN);

Wink


woffs
New User

Nov 13, 2003, 12:23 AM

Post #3 of 7 (1288 views)
Re: [noslenj123] How to store in file complex hash? [In reply to] Can't Post

need something like this:


Code
$hash{"key"} = [$val1, $val2];

need to save this hash in file and restore for future use. how?


kencl
User

Nov 13, 2003, 1:05 AM

Post #4 of 7 (1286 views)
Re: [woffs] How to store in file complex hash? [In reply to] Can't Post

Choose a delimiter that is guaranteed not to be used in any key or in val1. I'll use TAB (\t) for this example:

Storing the file:

for (keys $hash) { print FILE "$_\t$hash{$_}[0]\t$hash{$_}[1]\n"; }

Reading the file:

while ($line = <FILE>) {
chomp($line);
my ($key, $val1, $val2) = split(/\t/, $line, 3);
$hash{$key} = [$val1, $val2];
}

>> If you can't control it, improve it, correlate it or disseminate it with PERL, it doesn't exist!


davorg
Thaumaturge / Moderator

Nov 13, 2003, 1:42 AM

Post #5 of 7 (1284 views)
Re: [woffs] How to store in file complex hash? [In reply to] Can't Post


In Reply To
Hello!

How to store in file complex hash?


You'll need to serialise the hash first using either Data::Dumper or (better) Storable.

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


woffs
New User

Nov 13, 2003, 1:57 AM

Post #6 of 7 (1282 views)
Re: [davorg] How to store in file complex hash? [In reply to] Can't Post


In Reply To

In Reply To
Hello!

How to store in file complex hash?


You'll need to serialise the hash first using either Data::Dumper or (better) Storable.


Yes, but i'm need in this case module both for *NIX && Windows


woffs
New User

Nov 13, 2003, 2:23 AM

Post #7 of 7 (1281 views)
Re: [woffs] How to store in file complex hash? [In reply to] Can't Post

tnx!

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives