Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!uakari.primate.wisc.edu!sdd.hp.com!elroy.jpl.nasa.gov!jpl-devvax!lwall From: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Newsgroups: comp.lang.perl Subject: Re: affectation to $1 Message-ID: <10479@jpl-devvax.JPL.NASA.GOV> Date: 20 Nov 90 18:51:06 GMT References: Reply-To: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Organization: Jet Propulsion Laboratory, Pasadena, CA Lines: 37 In article stef@zweig.sun (Stephane Payrard) writes: : : : using perl level 36 on a Sun 4/110 running SunOS 4.1: : : I want to convert to lower case a string I have : matched. I want to do it in place (in $1); : I discover that I can't write to $1; : Is this a bug or a known/justified feature? $1, $2, etc. are readonly currently. What would it mean to say this? $x = 'foo'; $x =~ /(fo*)/; $x = 'bar'; $1 =~ y/a-z/A-Z/; : demonstrated by the following script. : : #! /usr/local/bin/perl : $_='A'; : m/(.*)/; : $1 =~ y/A-Z/a-z/; : print "I expect 'a'; I get '$1'\n"; : $1='B'; : print "I expect 'b'; I get '$1'\n"; There are two ways to do this. s#(.*)#($tmp = $1) =~ y/A-Z/a-z/, $tmp#e; or /.*/ && substr($_, length($`), length($&)) =~ y/A-Z/a-z/; Larry