Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!cs.utexas.edu!uunet!littlei!intelhf!agora!markb From: markb@agora.rain.com (Mark Biggar) Newsgroups: comp.lang.perl Subject: Re: Repeated patterns Message-ID: <1991Mar19.065550.17156@agora.rain.com> Date: 19 Mar 91 06:55:50 GMT References: <1103@spim.mips.COM> Organization: Open Communications Forum Lines: 23 In article <1103@spim.mips.COM> bjorn@mips.com (Bjorn Satdeva - /sys/admin Inc) writes: >I have a humble hunch, that the following can be done more simple: > if ( $Bar =~ /some pattern/ ) { > ($Foo = $Bar ) =~ s/some pattern//; > $FooBar{$Foo}++; > next ; > } >I have a program which does the above for a number of patterns, and >I wonder if there is a way to _not_ write each pattern twice (the code >inside the if statment varies enhough that a subroutine is not >atractive, even if it looks like from the example). if (($Foo = $Bar) =~ s/some pattern//) { $FooBar{$Foo}++; next; } should work fine as long as you don't care that $Foo gets clobbered -- Perl's Maternal Uncle Mark Biggar markb@agora.rain.com