i want to do some find and replace job in a text file. While the find text and replace with text are from a .mdb file.
The .mdb file contains a table with 2 column, 1st column is full(full name) and the second one is abb(abbreviated name).
In the text file i want to find the full text and replace it with the corresponding abbreviated text.
test.txt
This is an example section.
And the second line has structural science.
jabb.mdb
full | abb
-------------
example | eg
expand | exp
section | sect
science | sci
test.out (required output)
This is an eg sect.
And the second line has structural sci.
With the following code i have written, nothing is happening.
use Win32::ODBC;
open( IN, '<', 'test.txt' ) or die "Couldn't open infile.\n$!";
open( OUT, '>', 'test.out' ) or die "Couldn't open outfile.\n$!";
$dsn = "test_dsn";
$db = new Win32::ODBC($dsn);
die "ERROR: Failed to open database\n" if(!$db);
$sql = "SELECT * from jabb";
$db->Sql($sql);
while ($db->FetchRow()) {
($full, $abb) = $db->Data("full", "abb");
while(IN){
s!$full!$abb!g;
print $_;
print OUT $_;
}
close(OUT);
}
$db->Close();
please help me in looping through the files.
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.