
KevinR
Veteran

May 30, 2008, 11:56 AM
Post #4 of 4
(1494 views)
|
|
Re: [supenguin] replacing part of a string with perl code embedded in regex
[In reply to]
|
Can't Post
|
|
OK, that got me to thinking a little bit moe and here is another suggestion:
use warnings; use strict; my $string = 'string041&42'; my @strings = split("&", $string); my( $L1, $L2) = (length $strings[0], length $strings[1]); my $new = $strings[0]; substr $strings[0], -$L2, $L2, $strings[1]; print "$new, $strings[0]"; This sould be very efficient, but your way is OK too. The amount of data involved is probably so little it really does not matter how you do it. If you are crunching through millions of strings to parse them into two strings it might matter, but for a few hundred or a few thousand the difference is not going to be overly dramatic. -------------------------------------------------
|