Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: ISOLATE 2 ASSOCIATED FIELDS IN A TEXT FILE, then CONVERT the first into another based on a table of definitions

by bichonfrise74 (Vicar)
on Oct 19, 2009 at 05:08 UTC ( [id://801933]=note: print w/replies, xml ) Need Help??


in reply to ISOLATE 2 ASSOCIATED FIELDS IN A TEXT FILE, then CONVERT the first into another based on a table of definitions

From how I understand your question, this should help you get started. Note that there are many ways of doing this.
#!/usr/bin/perl use strict; use Data::Dumper; my %temp_record; my $file_1 =<<FILE_1; 385#19126!NM_167210@[1103;1104] 2 386#19127!NM_167211@[1103;1104] 2 387#19128!NM_167212@[1103;1104] 2 438#1781!NM_135492@[1337] 1 442#1794!NM_001042886@[1349] 1 FILE_1 open( my $fh, '<', \$file_1 ) or die( "Cannot open $file_1" ); while (<$fh>) { my ($key, $value) = /\!(\w+)\@\S.*\s+(\d)/; $temp_record{$key} = $value; } close( $fh ); my %record; while (<DATA>) { my ($key, $value) = /(\S+)\s+(\S+)/; for my $i (keys %temp_record) { $record{$key} = $temp_record{$i} if ( $i eq $value ); } } print Dumper \%record; __DATA__ CG32694-RD NM_167211 CG32694-RC NM_167210 CG32694-RA NM_167209 CG32694-RB NM_167212 CG33557-RA NM_001014730
The output is:
$VAR1 = { 'CG32694-RD' => '2', 'CG32694-RB' => '2', 'CG32694-RC' => '2' };
  • Comment on Re: ISOLATE 2 ASSOCIATED FIELDS IN A TEXT FILE, then CONVERT the first into another based on a table of definitions
  • Select or Download Code

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-04-25 13:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found