bjorn@mips.com (Bjorn Satdeva - /sys/admin Inc) (03/19/91)
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).
Any ideas?
Bjorn Satdeva
markb@agora.rain.com (Mark Biggar) (03/19/91)
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