Hey every body
Thank you for any advice you could gave me. I need write a program from scratch which seems particularly difficult to me (I have just started learning Perl....).
So the problem is I have 2 data files (quite huge basically 1 GB). I need to retrive some data on file 2 using a list created on file 1. Basically file 1 is a txt wih different info on it from which I need to get a list of values (basically the values are separated by tab or by colon). I wrote a code which is :
#!/usr/bin/perl -w
use strict;
my$line;
my@fields;
my@output;
open (FILE, 'XXXX.txt') or die "can't open the file: $!";
open (FD, '>XXXX.txt') or die "can't open the file: $!";
while (defined ($line= <FILE>)) {
my@fields= split (/\s/ ,$line);
my@output = grep /rs\d{5,}\b/ ,@fields;
my$rs = join (':' , @output);
$rs=~ s/:/\n/g;
print FD "$rs";
}
close FILE;
close FD;
This was just to look at the result
The values I need to search from the file 1 are now in the array my@output. Now for each of these elements I would like to search a second txt file and grab the string that contains the element. DO you think grep can work on that? If not you have a better idea?
Thanks for the help
Micky
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.