Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: adding text from different txt file into hash

by Limbic~Region (Chancellor)
on Apr 20, 2005 at 15:51 UTC ( [id://449639] : note . print w/replies, xml ) Need Help??


in reply to adding text from different txt file into hash

MrChat,
The following code is a starting point. You need to modify it accordingly to your given situation (how to handle files of difference number of lines, duplicates, or preserving order for instance).
#!/usr/bin/perl use strict; use warnings; open(FILE1, '<', 'file1.txt') or die $!; open(FILE2, '<', 'file2.txt') or die $!; open(FILE3, '>', 'file3.txt') or die $!; my %hash; while ( <FILE1> ) { chomp; my $val = <FILE2>; chomp $val; $hash{ $_ } = $val; } print FILE3 "$_ = $hash{ $_ }\n" for keys %hash;

Cheers - L~R

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://449639]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-02-06 04:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found