The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Perl Programming
|
Match entires and seaprate by bracket before writing
Discuss Match entires and seaprate by bracket before writing in the Perl Programming forum on Dev Shed. Match entires and seaprate by bracket before writing Perl Programming forum discussing coding in Perl, utilizing Perl modules, and other Perl-related topics. Perl, the Practical Extraction and Reporting Language, is the choice for many for parsing textual information.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

August 16th, 2012, 08:23 AM
|
|
Contributing User
|
|
Join Date: May 2012
Posts: 60
Time spent in forums: 10 h 42 m 3 sec
Reputation Power: 2
|
|
|
Match entires and seaprate by bracket before writing
Hi all,
I have a big file like this kind of data in two columns
Quote: Code:
benzene blood disorders
nitrozen air disease |
I have another file like this in different columns
Code:
Quote: AXY benzene, nitrogen, oxygen, not available, sulfur
VTY nitrogen, notavailable, sulfur
I want from second columnonwards of second file it should match the first column of first file so that and if mathced right in fornt of it whatever is written. |
Exoected output is
Quote: Code:
AXY benzene (blood disorders), nitrogen (air disease), oxygen, not available, sulfur.
VTY nitrogen (air disease), notavailable, sulfur |
|

August 23rd, 2012, 05:13 PM
|
 |
'fie' on me, allege-dly
|
|
Join Date: Mar 2003
Location: in da kitchen ...
|
|
|
what do you expect to happen here?
__________________
--Ax
without exception, there is no rule ...
Handmade Irish Jewellery
Targeted Advertising Cookie Optout (TACO) extension for Firefox
The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones
 
09 F9 11 02
9D 74 E3 5B
D8 41 56 C5
63 56 88 C0
Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems. -- Jamie Zawinski
Deta vil - the devil is in the detail, allegedly, and I use the term advisedly, allegedly ... oh, no, wait I did ...
BIT COINS ANYONE
|

August 24th, 2012, 12:45 AM
|
|
Contributing User
|
|
Join Date: May 2012
Posts: 60
Time spent in forums: 10 h 42 m 3 sec
Reputation Power: 2
|
|
|
Request to check
Hi
Thanks for reply.
I am looking for guidance regarding writing a perl program for such a question as I m novice in Perl programming as I am from Life science background and I need this for some science research.
Mani
|

August 24th, 2012, 10:19 AM
|
|
|
|
Hello Mani,
We would be happy to help you with the troubleshooting of your code, however, based on your prior postings that I've read, you're looking for someone to write your entire script for you or at least the vast majority of it. If that's the case, then it would be best to hire a Perl programmer. If I'm wrong, then please post your script and a specific question on the part that is giving you trouble. Once we have that info, we can begin to give help.
|

August 24th, 2012, 11:36 AM
|
|
|
I was needing a diversion from my own work, so I went ahead and worked up a minimal script for you.
Code:
use strict;
use warnings;
my $file1 = 'file1.txt';
my $file2 = 'file2.txt';
open my $f1_fh, '<', $file1 or die "failed to open $file1 $!";
open my $f2_fh, '<', $file2 or die "failed to open $file2 $!";
my %data;
while ( my $line = <$f1_fh> ) {
chomp $line;
my ($key, $value) = split /\s+/, $line, 2;
$data{$key} = $value;
}
close $f1_fh;
while ( my $line = <$f2_fh> ) {
chomp $line;
my ($key, $value) = split /\s+/, $line, 2;
my @parts = map { $data{$_} ? "$_ ($data{$_})" : $_ } split /, /, $value;
printf "%s\t%s\n", $key, join(', ', @parts);
}
close $f2_fh;
|

August 25th, 2012, 04:45 AM
|
|
Contributing User
|
|
Join Date: May 2012
Posts: 60
Time spent in forums: 10 h 42 m 3 sec
Reputation Power: 2
|
|
|
Request to check
Hi
Thanks for the reply.
I used this programm. May be I m doing soemthign worng with file 1 and file2 naming as I named my input files as file 1 and file 2 itself
or
May be I have to run the programm in differnet way
and it shows such errors as well.
Quote: Use of uninitialized value in hash element at pharmgkbtest.pl line 15, <$f1_fh> line 65525.
Use of uninitialized value in hash element at pharmgkbtest.pl line 15, <$f1_fh> line 65526.
Use of uninitialized value in hash element at pharmgkbtest.pl line 15, <$f1_fh> line 65527.
Use of uninitialized value in hash element at pharmgkbtest.pl line 15, <$f1_fh> line 65528.
Use of uninitialized value in hash element at pharmgkbtest.pl line 15, <$f1_fh> line 65529.
Use of uninitialized value in hash element at pharmgkbtest.pl line 15, <$f1_fh> line 65530.
Use of uninitialized value in hash element at pharmgkbtest.pl line 15, <$f1_fh> line 65531.
Use of uninitialized value in hash element at pharmgkbtest.pl line 15, <$f1_fh> line 65532.
Use of uninitialized value in hash element at pharmgkbtest.pl line 15, <$f1_fh> line 65533.
Use of uninitialized value in hash element at pharmgkbtest.pl line 15, <$f1_fh> line 65534.
Use of uninitialized value in hash element at pharmgkbtest.pl line 15, <$f1_fh> line 65535. |
|

August 25th, 2012, 08:12 AM
|
|
|
|
Obviously one or both of your data files is not formatted as you've presented to us.
Please post both of your scripts as attachments, not copy/pasted inline, so that we can see the precise format.
|

August 25th, 2012, 10:22 AM
|
|
|
You probably have empty lines (or lines not having two fields) at the end of your file 1.
If this is the case, you can fix it by changing the relevant line:
Perl Code:
Original
- Perl Code |
|
|
|
$data{$key} = $value if defined $value;
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|