For Programmers: Free Programming Magazines  


Home > Archive > PERL Programming > March 2004 > Find the String "house[1]" in Another String?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Find the String "house[1]" in Another String?
Faethon

2004-03-29, 4:39 am

I know that "[" and "]" are special characetrs for
Perl/CGI. However, I need to find the strings, say,
house[1] and house[2] in a given text file.
Naturally, "house[1], "house[2]" do not work.
But "house\[1\]", "house\[2\]" do not work either.
What strings should I actually use to look for them?
Thanks.

Faethon

Faethon

2004-03-29, 5:32 am

On Mon, 29 Mar 2004 03:20:28 -0500, Faethon <at dot com> wrote:

>I know that "[" and "]" are special characetrs for
>Perl/CGI. However, I need to find the strings, say,
>house[1] and house[2] in a given text file.
>Naturally, "house[1], "house[2]" do not work.
>But "house\[1\]", "house\[2\]" do not work either.
>What strings should I actually use to look for them?
>Thanks.
>
>Faethon


Well,

I figured it out after several hours!
I look for "\Qhouse[1]\E" and "\Qhouse[2]\E".
Thanks!

Faethon

Gunnar Hjalmarsson

2004-03-29, 5:32 am

Faethon wrote:
> I know that "[" and "]" are special characetrs for Perl/CGI.


Do you? What has CGI to do with it?

Those are special characters in Perl regular expressions.

> However, I need to find the strings, say, house[1] and house[2] in
> a given text file. Naturally, "house[1], "house[2]" do not work.
> But "house\[1\]", "house\[2\]" do not work either.


Yes, they do.

Show us the code that made you draw that incorrect conclusion.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Dave Cross

2004-03-29, 8:32 am

On Mon, 29 Mar 2004 03:50:44 -0500, Faethon wrote:

> On Mon, 29 Mar 2004 03:20:28 -0500, Faethon <at dot com> wrote:
>
>
> Well,
>
> I figured it out after several hours!
> I look for "\Qhouse[1]\E" and "\Qhouse[2]\E".


But all that does is convert them into "house\[1\]" and "house\[2\]" -
which you already said _didn't_ work[1].

$ perl -le 'print "\Qhouse[1]\E"'
house\[1\]

Dave...

[1] But I strongly suspect that you were wrong to say that.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com