Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Best way to search file

by choroba (Cardinal)
on Apr 15, 2015 at 16:26 UTC ( [id://1123525]=note: print w/replies, xml ) Need Help??


in reply to Best way to search file

Store the mapping of social numbers to identifiers in a hash:
#! /usr/bin/perl use warnings; use strict; my %alphanum; open my $COMMA, '<', 'file2.in' or die $!; while (<$COMMA>) { my ($social, $id) = (split /,/)[1, 2]; $alphanum{$social} = $id; } open my $VBAR, '<', 'file1.in' or die $!; while (<$VBAR>) { chomp; my $social = (split /\|/)[1]; if (exists $alphanum{$social}) { print "$_|$alphanum{$social}"; } else { print "$_\n"; } }

The input files I used:
file1.in

John|123 Jane|456 John|123 Jane|456 Jack|789

file2.in
John Doe,123,a0 Jane Smith,456,b1
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1123525]
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-04-19 03:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found