Thanks Bob, Andrea and Members ! For those who did not follow my previous post, what I want is to have an expression that matches something but not an empty string.
> From: "Bob Showalter" > Hmm, why do you want to use a regex? (1) Of course, I could use if ($key==$cid) {}; However, I just wanted to understand more about regular expressions, and the reason why $key (having a value of 1234) matches an empty string. Andrea have given me an explanation on why $key (having a value of 1234) matches an empty string but I still need some clarification, Members please see further down. > Anyway, you need: > $key =~ /^$cid$/ > But you need to be careful about what characters $cid > might contain, so you're better to say: > $key =~ /^\Q$cid\E$/; > which is equivalent to the much more straightforward: > $key eq $cid; (2) Precisely, this is what I want ! A much more straightforward expression equivalent to $key eq $cid; [I copy & paste here] > From Andrea Holstein <[EMAIL PROTECTED]> > $cid is an empty string. > So in reality there's written $key =~/\b\b/. (3) I understand so far. > \b stands for a word boundary and has a length of 0. (4) Is this boundary \b equivalent to an empty string? What is the meaning of 0 length? Is 0 lenght = empty string? > In $key there are two word boundary, > before the 1 and after the 4. (5) Therefore are you saying that $key is equivalent to \b1234\b and when match with an empty string, obviously they matched. Have I read you correctly? Hmmmm ! very interesting. (6) So what must I do so that $key match something but not an empty value/string? (7) I read Bob's expression of $key =~ /^$cid$/ as :- look for a string $cid and that the line-of-input must only contain the string $cid. Given $key = 1234; and $cid = ''; Bob's expression of $key =~ /^$cid$/ do not match. However, based on Andrea's explanation (which I could have misread him) in para(5), the expression $key =~ /^$cid$/ should match an empty string too. I say so because (based on Andrea's explanation) $key has an equivalent of \b1234\b and if \b is equivalent to an empty string. And if \b is not equivalent to an empty string, then this expression $key =~ /$cid/ or $key =~ /\b$cid\b/ should not match an empty string which it does. By the way, I noted that without the border \b, $key =~ /$cid/; ## match an empty string too and I could understand the reason based on Andrea's explanation. > So of course, where one word boundary is, > there are two or three or million ones. > (They all have a length of 0) > > Greetings, > Andrea All help and explanations appreciated. Thank You. --- end of msg ---- my original post below ----- ----- Original Message ----- From: "Bob Showalter" <[EMAIL PROTECTED]> To: "'Leon'" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> > > -----Original Message----- > > From: Leon [mailto:[EMAIL PROTECTED]] > > Without using $key == $cid, > > How to construct a pattern so that $key match $cid. > > I do not understand why in the undermentioned script, $key match $cid. > > All explanations would be very much appreciated. > > Thanks > > > > use strict; > > my $cid = ''; > > my $key = '1234'; > > if ($key=~/\b$cid\b/) { > > print 'true'; > > }else {print 'false'}; _________________________________________________________ Do You Yahoo!? Get your free @yahoo.com address at http://mail.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]