Re: using variable in search and replace
- From: Gunnar Hjalmarsson <noreply@xxxxxxxxx>
- Date: Sat, 29 Apr 2006 12:44:41 +0200
swamy455@xxxxxxxxx wrote:
I am trying to search for a string in FILE1 and then split it and then
use the result to search FILE2
#!/usr/bin/perl
print "This is test perl program\n";
print "so of course I enable strictures and warnings:\n";
use strict;
use warnings;
open ( FILE1,"</test/file1.pl") or die "cannot open $?:$!";
while (<FILE1>){
$i= s/apple/APPLE/;
#just replacing apple with APPLE
#this works fine
if($i){
$test1=$_;
}
}
close FILE1;
print "test1 =$test1\n";
#this has the the whole line which is of #the form a b
($a,$b)=split(/\s/,$test1,2);
print "b=$b\n";
Replace that line with
print "b=[$b]\n";
and consider the result.
open (FILE2,"</temp/file2.pl") or die "cannot open $?:$!";--------
while (<FILE2>){
$i= s/$b/MANGO/e;
Enable strictures, and avoid such mistakes!
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
.
- References:
- using variable in search and replace
- From: swamy455
- using variable in search and replace
- Prev by Date: using variable in search and replace
- Next by Date: Re: Detecting filehandles
- Previous by thread: using variable in search and replace
- Next by thread: extract variables from expression
- Index(es):
Relevant Pages
|