codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  string match / replace across files  zoroastr at 00:38 on Sunday, October 26, 2008
 

Hi...
TOTAL n00b question: I started coding what I hope will end up as a useful sccriptlet. It should:

* take strings from File A
* find same strings in File B
* append prefix to File B strings

here's what I have so far. It grabs the strings I want no problem, and I think I've succeeded in opening the second file and storing its lines in an array. Now I just have to match my File A strings with similar strings in File B and append my own string to the beginning of each.

Caveat: File B is not formatted like File A..so I might need a regex to make the match. The strings are actually IP addys, and the only reason I could get away with grabbing them from File A in the way I did was that they are left-justified and have no preceding chars, and I only needed the first 10 chars to uniquely id them.

Thanks Gurus!!!!


!/usr/bin/perl
use strict;
use warnings;

#------------------------------------------------------------
# WHAT: A simple script to perform string swaps between files
# WHO: me
# USAGE: not yet...
#------------------------------------------------------------

my @lines;
my $string;
my @morlines;

# get lines from the File A

open(FILE1,"list") || die "Error: $!\n";
@lines = <FILE1>;

foreach $string(@lines) {
$string=substr($string, 0, 11);
}


# Open File B and get corn-fuzed...

use Tie::File;

tie @morlines, 'Tie::File', "/forum/test1.txt" or die;

for (@morlines) {

do stuff...;

}









CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums
//








Recent Forum Threads
•  string match / replace across files
•  How to make connection string for database connectivity?
•  TIESCALAR problem while using Tie::InsertOrderHash
•  errors in my program.. need help
•  Source Edit in IE7, 8
•  Change what user is looking at
•  Re: shut down computer
•  Re: Help with key/value pairs
•  how to create a paying sytem in 7 eleven using java


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2008