Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!bcm!convex!usenet From: tchrist@convex.COM (Tom Christiansen) Newsgroups: comp.lang.perl Subject: Re: Patterns vs Strings Message-ID: <1991Feb07.210023.8308@convex.com> Date: 7 Feb 91 21:00:23 GMT References: <121642@uunet.UU.NET> Sender: usenet@convex.com (news access account) Reply-To: tchrist@convex.COM (Tom Christiansen) Organization: CONVEX Software Development, Richardson, TX Lines: 36 Nntp-Posting-Host: pixel.convex.com From the keyboard of rbj@uunet.UU.NET (Root Boy Jim): :Are patterns a semi data type in their own right? :Are they replacable with strings? :The manual/book never addresses this explicitly. : :My experiments lead me to belive that :whenever a "pattern" is expected, slashes :are "promoted" to double quotes, as if "qq" :had been stuck in front. A semi-data type? I'm not sure what a real data type is. I think by the most stringent criteria (you can have anonymous temporaries), only atoms, oops I mean scalars :-), and lists are real data types, and everything else is just some magic operation you perform on them, like regexp matching, hashed array lookups, code evals, and indirect function calls and i/o. But I don't really tell people that (often). Usually I consider anything that you can pass around and has its own name space is a real data type. I believe your observations to be correct. I think Larry once explained that if ($a =~ $b) is legal, and counts as if ($a =~ /$b/) but it may be somehow less efficient. Certainly it's fair to use variables in pattern patching operations. Various tricks (like //, /$foo//o, eval, ...) can be used to speed up the operation. Note that if you use alternate delims on the match, like m#bar#, it still gets qq// interpolated, unless you should use m'bar', in which case you get q// action. I'm not sure I've ever seen this written down in the man page or the book. I don't think you can use m`bar` for qx// action, but neither can I think of why you'd ever want it to. --tom -- "All things are possible, but not all expedient." (in life, UNIX, and perl)