Hi All,
Hello,
The code below does what I want to do, but it takes 3 lines and a temporary array (yuck).
It does? Could you please explain what exactly you want to do? Just going by your subject line, this will work (assuming $_ contains the data.)
s/(.*)-/$1/;
I can't come up with a one line regex substitution. Anyone got one?
my $tmp = reverse split //, $_; $tmp =~ s/-//; $_ = reverse split //, $tmp;
There is no temporary array there but there is a list created by split() however reverse() works just fine with scalars so:
my $tmp = reverse split //, $_;
And:
my $tmp = reverse $_;
Do the same thing but in the second one reverse does not have a list to concatenate. In some cases reversing a string to do a substitution is more efficient but that depends on your data.
And of course (TMTOWTDI) you can accomplish the same thing without using regular expressions:
# note: using the global variable $a as a temp substr $_, $a, 1, '' if ( $a = rindex $_, '-' ) >= 0;
John -- use Perl; program fulfillment
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>