Ask a Question related to PERL Miscellaneous, Design and Development.
-
Naren #1
A newBie Query
Hello grp,
I am searching for a perfect match of a string in a line and want to
replace all occurances of the string with a new string and also want a count
of the replacements
What I mean by a perfect match is that it should not be a substring of any
other string,should be independent.
$a is my string to be searched
$cnt = ($line =~ s/$a\w+/$tobereplaceed)
I dont get a correct output.
PLz help
Thaanx in advance
Rgds,
Naren.
Naren Guest
-
Newbie about grouping query
In my mdb, the data is as below : ProductID Qty Name Month CID... -
datagrid query-newbie
i)How to set foucs to a datagrid programatically? Is there any method to do so? Can we redraw a datagrid ? I want to update a datagrid. But I... -
A newbie query about Soap4R and dot net web services
Can anyone help me with this Soap4r problem? I have created a simple web service in dot net using Visual studio and have modified a sample... -
[newbie] Array and query
Hi to all! :) This week i begin to learn php, but now i have a problem... I made a form in which there is the possibility of choosing some... -
Help ASP newbie with webhits query
I have been asked by my office to set up a Intranet site using ASP. (I know VB6, so it must be simple!). The basics are done, including using MS... -
Thens #2
Re: A newBie Query
On Wed, 17 Sep 2003 12:25:26 +0530
"Naren" <narendranath.ts@in.bosch.com> wrote:
# Hello grp,
# I am searching for a perfect match of a string in a line and want to
# replace all occurances of the string with a new string and also want a count
# of the replacements
#
# What I mean by a perfect match is that it should not be a substring of any
# other string,should be independent.
#
# $a is my string to be searched
# $cnt = ($line =~ s/$a\w+/$tobereplaceed)
$cnt = ( $line =~ s/\b$a\b/$tobereplaced/g )
^^ ^^ ^^
\b - asserts for a word boundary
g - to repeat the search and replace globally for the string.
Also, you might run into some problems when $a has some meta
characters like +, ?, (, ). Use Quotemeta to transform them.
perldoc perlre for more details.
Regards,
Thens.
Thens Guest
-
Tad McClellan #3
Re: A newBie Query
Naren <narendranath.ts@in.bosch.com> wrote:
> Subject: A newBie Query
Please put the subject of your article in the Subject of your article.
> I am searching for a perfect match of a string in a line and want to
> replace all occurances of the string with a new string and also want a count
> of the replacements
Use s///g;
> What I mean by a perfect match is that it should not be a substring of any
> other string,should be independent.
The count must always be one (or zero) if it is not a substring
of any other string, as whatever sub-part you match must necessarily
be a substring of the entire string being searched.
I think you've used the wrong terminology, but I can't divine
what term you were looking for...
> $a is my string to be searched
No it isn't. Your code below searches $line, not $a.
^^> $cnt = ($line =~ s/$a\w+/$tobereplaceed)
^^> I dont get a correct output.
A syntax error is never the correct output!
What output _do_ you get?
What output were you expecting to get?
Why were you expecting to get that?
> PLz help
We don't know what data is in $a.
We don't know what data is in $line.
We don't know what data is in $tobereplaceed.
We do not know what the input is.
We don't know what the code is.
We do not know what the output is intended to be.
Please help the helpers to help you by helpfully providing enough
information for the helpers to be _able_ to help you.
Have you seen the Posting Guidelines that are posted here frequently?
use PSI::ESP;
Maybe this is what you are looking for:
my $cnt = $line =~ s/\b$a\b/$tobereplaceed/g;
or maybe:
my $cnt = $line =~ s/\b\Q$a\E\b/$tobereplaceed/g;
--
Tad McClellan SGML consulting
[email]tadmc@augustmail.com[/email] Perl programming
Fort Worth, Texas
Tad McClellan Guest
-
Naren #4
Re: A newBie Query
Hello Grp,
Thanks for all the suggestions and advices.I could do the required
functionality.I shall specify the problems in a detailed manner in future.
Thanks again
Rgds,
Naren.
Naren Guest



Reply With Quote

