CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions:
regex not working

 



aggrohit
stranger

Oct 23, 2001, 5:08 AM

Post #1 of 4 (5992 views)
regex not working Can't Post

hi everybody,
i am new to perl,i am getting this problem in regular expression....

$b='Universal Resource Locator, I
think \?\?\?\?';

if ($b =~/$b/)
{
print "Condition True";
}
else
{
print "Condition False";
}

i am getting this " Codition False".
if i make

$b='Universal Resource Locator, I
think ????';

then it gives this error:-

/Universal Resource Locator, I think ????/: nested *?+ in regexp at te
st.pl line 7.

i want to know how to compare strings having meta characters.

thanks in advance,
rohit



mhx
Enthusiast

Oct 23, 2001, 5:47 AM

Post #2 of 4 (5990 views)
Re: regex not working [In reply to] Can't Post

Either use eq:

Code
#!/bin/perl -w 

$b='Universal Resource Locator, I
think ????';

if ($b eq $b)
{
print "Condition True";
}
else
{
print "Condition False";
}

or escape all metacharacters:

Code
#!/bin/perl -w 

$b='Universal Resource Locator, I
think ????';

if ($b =~ /\Q$b\E/)
{
print "Condition True";
}
else
{
print "Condition False";
}

However, comparing $b with $b seems rather useless to me, but I assume here that you're about to do something that makes more sense... Wink

-- Marcus


Code
s$$ab21b8d15c3d97bd6317286d$;$"=547269736;split'i',join$,,map{chr(($*+= 
($">>=1)&1?-hex:hex)+0140)}/./g;$"=chr$";s;.;\u$&;for@_[0,2];print"@_,"



aggrohit
stranger

Oct 23, 2001, 6:03 AM

Post #3 of 4 (5989 views)
Re: regex not working [In reply to] Can't Post

i want to do like this

$a='http://newmediarepublic.com/guestbook/Universal Resource Locator, I%2
??*?&,http://yahoo.com,http.hotmail.com';

$b='http://newmediarepublic.com/guestbook/Universal Resource Locator, I%2
??*?&';

if ($a =~/$b/)
{
print "Condition True";
}
else
{
print "Condition False";
}

i have $a in which there are hundered of urls appended by "," now what i want to do is to get one url in $b and then compare it with $a wether it exists in $a.

there are number of errors occuring due to meta characters present in URLS. as i am fetching these urls from net and appending it in $a.but i append only that URL in $a which does not exist in $a.
that is why i am comparing first it with $a variable.



Jean
User


Nov 28, 2001, 11:16 PM

Post #4 of 4 (5959 views)
Re: regex not working [In reply to] Can't Post

Not the best solution, so it's up to you whether to use the offer...

You could create a hash with URLs, like
my %URLs;
$URLs{$b} = 1 unless exists $URLs{$b};
Yyou could even count the number of time specific URL has been used:
$URLs{$b}++; # Without condition
In the end you can loop through all the URLs by
foreach ($key = keys(%URLs)) {}

Another option is to create an array with all the URLs and loop through the array with eq

Hopefully this will have some value to you...

Jean Spector
QA Engineer @ mSAFE Ltd.
jean.spector@softhome.net

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives