rahulgsp83 has asked for the wisdom of the Perl Monks concerning the following question:
I want to replace IDENT=US-x with IDENT=UK-x in all files ,only the value x is different in al files. I am trying to use the following code for it but I am not able to do it :-<value>javascript:var x=window.op +en('http://v3vi.click4assistance.co.uk/c4a.aspx?AccNo=Inter12109& +IDENT=US-x&Target=General&Country=Singapore','_blank','menuba +r=no,location=no,resizable=yes,scrollbars=no,status=no');</value> + </item> "
basically i am able to replace us with UK and store it in $orig variable but with the next line "$filedata$i = $1.$2."$orig".$4.$5; " the entire line gets deleted except "IDENT=US-x&Target=General&Country=Singapore'" ,so how to really get the combined output ,i am bit new to perl so may be i am making a simple mistake ,i request the experts to pls guide regarding this issue , thanks in advance#!/usr/bin/perl use strict; use File::Find; use Tie::File; my $input="C://data"; my $logfile="C:\log.txt"; find(\&filenames, $input); sub filenames() { if (-f $File::Find::name) { my $file=$File::Find::name; if($file=~m/\/data\//) { open(FILE, "$file"); my @filedata=<FILE>; close(FILE); my $datalength = scalar(@filedata); my $DCRContent=""; for (my $i=0;$i<$datalength; $i++) { if($filedata[$i]=~/(.*)(http:\/\/v3vi.click4assistance +.co.uk\/c4a.aspx\?AccNo=Inter12109&IDENT=)(.*)(','_blank)(.*)/i) { print "$3 \n"; my $orig=$3; print "$orig \n"; $orig=~ s/US/UK/; print "The resulting value is : $orig \n"; $filedata[$i] = $1.$2."$orig".$4.$5; open(FILEOUTS,">>$logfile") or die("Opening file failed"); print FILEOUTS $file."\t"."\n"; close(FILEOUTS); } } open(FILEOUT,">$file") or die("Opening file failed"); print FILEOUT @filedata; close FILEOUT; } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: regex issue
by JavaFan (Canon) on Dec 11, 2009 at 15:26 UTC | |
by ack (Deacon) on Dec 11, 2009 at 17:49 UTC | |
by JavaFan (Canon) on Dec 12, 2009 at 11:44 UTC | |
|
Re: regex issue
by Anonymous Monk on Dec 11, 2009 at 15:45 UTC | |
by rahulgsp83 (Novice) on Dec 11, 2009 at 17:56 UTC |