home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / perl / 7970 < prev    next >
Encoding:
Internet Message Format  |  1993-01-24  |  1.5 KB

  1. Path: sparky!uunet!olivea!sgigate!odin!sierra.corp.sgi.com!stantz
  2. From: stantz@sierra.corp.sgi.com (Mark Stantz)
  3. Newsgroups: comp.lang.perl
  4. Subject: Newbie question from an old hand: ?? vs //
  5. Message-ID: <1993Jan24.011910.10654@odin.corp.sgi.com>
  6. Date: 24 Jan 93 01:19:10 GMT
  7. Sender: news@odin.corp.sgi.com (Net News)
  8. Organization: Silicon Graphics, Inc.
  9. Lines: 42
  10. Nntp-Posting-Host: sierra.corp.sgi.com
  11.  
  12.  
  13.     The Camel book says:
  14.  
  15.         ?PATTERN?[i][o]
  16.  
  17.         This is just like the /PATTERN/ search, except that it matches
  18.         only once between calls to the reset operator, so it finds the
  19.         first occurrence of something rather than the last.
  20.  
  21.     Two years ago, I apparently misread this as:
  22.  
  23.         This is just like the /PATTERN/ search, except that it finds the
  24.         first occurrence of something rather than the last.
  25.  
  26.     Consequently I would have expected the following program:
  27.  
  28.         #!/usr/local/bin/perl
  29.         $f = "perl.is.great";
  30.  
  31.         $f =~ /\./;
  32.         print "$` $'\n";
  33.         $f =~ ?\.?;
  34.         print "$` $'\n";
  35.  
  36.     to print:
  37.  
  38.         perl is.great
  39.         perl.is great
  40.  
  41.     But instead I get:
  42.  
  43.         perl is.great
  44.         perl is.great
  45.  
  46.     Okay, so I was confused.  What's the correct behavior?  Well, after
  47. having read over the documentation for //, ?? and reset, I can't seem to make 
  48. // and ?? do anything differently, and have decided that I don't really 
  49. understand what the Camel book is trying to tell me.  Can someone post a code 
  50. fragment that shows // and ?? doing different things?  Everything I've tried 
  51. gives me the same behavior for both of them.  I've also checked the FAQ.
  52.  
  53.     -Mark
  54.