>
>
>
> -----Original Message-----
> From: Owen [mailto:rc...@pcug.org.au]
> Sent: Wednesday, April 15, 2009 3:16 PM
> To: Gowri Chandra Sekhar Barla, TLS, Chennai
> Subject: RE: Reg:Regular expression
>
>>
>>
>>
>> -----Original Message-----
>> From: Owen [mailto:rc...@pcug.org.au]
>> Sent: Wednesday, April 15, 2009 2:52 PM
>> To: Gowri Chandra Sekhar Barla, TLS, Chennai
>> Subject: RE: Reg:Regular expression
>>
>>
>>> Hi owen,
>>> Please find the test.txt in theattachments.
>>> Thanks and regards,
>>> Gowri
>>> -----Original Message-----
>>> From: Owen [mailto:rc...@pcug.org.au]
>>> Sent: Wednesday, April 15, 2009 2:19 PM
>>> To: Gowri Chandra Sekhar Barla, TLS, Chennai
>>> Cc: Perl Beginners
>>> Subject: RE: Reg:Regular expression
>>>> Hi owen,
>>>> Please help me in resolving errors in the following script
>>>> open(INPUT,"<Test.txt");
>>>> open(OUTPUT,">new.txt");
>>>> $temp = \/user\/gowri\/remote2;
>>>> while ( <INPUT> ) {
>>>> $_ =~ s{\\/user\\/cce\\/g_tool}{$temp};
>>>> print OUTPUT $_;
>>>> }
>>> Well, I can try.
>>> But why don't you help me by sending a few lines of your Test.txt
> There are a few things you might want to try first;
>>>  a. place immediately under the #!/usr/bin/perl line
>>>      use strict;
>>>      use warnings;
>>>  b. Change
>>>      $temp = \/user\/gowri\/remote2; to
>>>      my $temp = "\/user\/gowri\/remote2";
>>>  (Note the inverted commas around the variable)
>>> Now have another go
>>
>>
>>
>>
>> It is best if when replying to emails, to do the response at the end
> of the message. It makes the reading easier
>>
>> So, thanks for the Test.txt, did you have another go at running it
> after the corrections suggested?
>>
>> What was the result?
>>
>> There are a few other things you should do, but you tell me how you
> went first
>>
>>
>>
>> --
>>
>>
>>
>> Owen
>>
>>
>> Script:
>>
>> use strict;
>> use warnings;
>>
>> open(INPUT,"<Test.txt");
>> open(OUTPUT,">new.txt");
>> my $temp = "\/user\/gowri\/remote2";
>> while ( <INPUT> ) {
>> $_ =~ s{\/user\/cce\/g_tool}{$temp};;
>> print OUTPUT $_ ;
>> }
>>
>> No errors but in output it is not substituting .please check the
> output
>> in attachments(new.txt) same as test.txt
>
>
>
> Well not on my machine, note that when opening a file you should
> always check that it happened, see below
>
> ===================================================
> #!/usr/bin/perl
>
> use strict;
> use warnings;
>
> open( INPUT,  "<Test.txt" ) or die "Unable to open Test.txt for
> reading $!\n";
> open( OUTPUT, ">new.txt" )  or die "Unable to write to new.txt $!\n";
> my $temp = "\/user\/gowri\/remote2";
> while (<INPUT>) {
>     $_ =~ s{\\/user\\/cce\\/g_tool}{$temp};
>     print OUTPUT $_;
> }
>
> =====================================================
>
>
> o...@owen-desktop:$ cat Test.txt
>
> \/user\/cce\/g_tool
> \/user\/cce\/g_tool
> \/user\/cce\/g_tool
> \/user\/cce\/g_tool
> \/user\/cce\/g_tool
> \/user\/cce\/g_tool
> \/user\/cce\/g_tool
>
> o...@owen-desktop:$ cat new.txt
>
> /user/gowri/remote2
> /user/gowri/remote2
> /user/gowri/remote2
> /user/gowri/remote2
> /user/gowri/remote2
> /user/gowri/remote2
> /user/gowri/remote2
>
>
>
>
> So are you sure you have the same output as input?
> --
>
>
>
> Owen
>
>
>
> Thanks  owens,
>
> But the output is not exactly same what I expecting
>
> Output should be :
>
> \/user\/Gowri\/remote2.
>
> I don't why it not replacing what is declared in $temp.




Then try changing the value of $temp to

my $temp = "\\/user\\/gowri\\/remote2";


and see what happens


-- 



Owen


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to