Path: utzoo!attcan!uunet!aplcen!uakari.primate.wisc.edu!zaphod.mps.ohio-state.edu!sdd.hp.com!ucsd!ucbvax!iwarp.intel.com!news From: merlyn@iwarp.intel.com (Randal Schwartz) Newsgroups: comp.lang.perl Subject: Re: Substitution shortcut? Message-ID: <1990Sep7.165410.24392@iwarp.intel.com> Date: 7 Sep 90 16:54:10 GMT References: Sender: news@iwarp.intel.com Reply-To: merlyn@iwarp.intel.com (Randal Schwartz) Distribution: comp Organization: Stonehenge; netaccess via Intel, Beaverton, Oregon, USA Lines: 34 In-Reply-To: Mike.McManus@FtCollins.NCR.com (Mike McManus) In article , Mike.McManus@FtCollins (Mike McManus) writes: | | If I have something like this: | | $a = "hello"; | $b = $a; | $b =~ s/ello/i/; | | ...is there a "short" way to write this? Something like: | | $a = "hello"; | $b = ($a ~ s/ello/i/); | | Seems silly to have to say $b = $a first, but if I gotta, so be it. Just | curious if I've been missing something. Pretty durn close. ($b = $a) =~ s/ello/i; # copy $a to $b, and then change $b I use this idiom all the time, as in: while (<>) { ($upper = $_) = y/a-z/A-Z/; # now $upper has an uppercase version of line, with $_ still original ... } ($_ = "Just another") =~ s/$/ Perl hacker,/; 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!"=/