Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!mips!decwrl!ucbvax!iwarp.intel.com!news From: merlyn@iwarp.intel.com (Randal Schwartz) Newsgroups: comp.lang.perl Subject: Re: Is this a Bug? Summary: No. :-) Keywords: perl bug Message-ID: <1990Oct5.183751.9602@iwarp.intel.com> Date: 5 Oct 90 18:37:51 GMT References: <9134@cg-atla.UUCP> Sender: news@iwarp.intel.com Reply-To: merlyn@iwarp.intel.com (Randal Schwartz) Distribution: na Organization: Stonehenge; netaccess via Intel, Beaverton, Oregon, USA Lines: 38 In-Reply-To: white@cg-atla.UUCP (Frank ) In article <9134@cg-atla.UUCP>, white@cg-atla (Frank ) writes: | | I am using 'perl' PL18. Running the following script | causes "WORD WITH PARENS" to be printed. What's the difference? | ----------------- cut here ------------------------------------------- | #!/usr/local/bin/perl | | $_ = "This line contains a\nword beginning a line"; | if ( /^word/ ) { | print "WORD NO PARENS\n"; | } elsif ( /^(word)/ ) { | print "WORD WITH PARENS\n"; # I get this message !! | } Quoting from perl(1): By default, the ^ character is only guaranteed to match at the beginning of the string, the $ character only at the end (or before the newline at the end) and perl does certain optimizations with the assumption that the string contains only one line. The behavior of ^ and $ on embedded newlines ============================================ will be inconsistent. You may, however, wish to treat a ======================= string as a multi-line buffer, such that the ^ will match after any newline within the string, and $ will match before any newline. At the cost of a little more overhead, you can do this by setting the variable $* to 1. Setting it back to 0 makes perl revert to its old behavior. The "Fine" Manual says all. ++$*; $_ = "\nJust another Perl hacker,"; /^J.*/; print $& -- /=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\ | on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III | | merlyn@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn | \=Cute Quote: "Welcome to Portland, Oregon, home of the California Raisins!"=/