Hi,
V.Ramkumar <[EMAIL PROTECTED]> asked:
> My input xml file has,
> <citspn>246</citspn><delim>–</delim><citepn>52</citepn>
>
> I have to replace,
> <citspn>246</citspn><delim>–</delim><citepn>252</citepn>
>
> Similarly,
>
> 100-5 100-105
> 198-10 198-210.
>
> If anybody have logic for the above, please suggest.
Hope this helps:
#!/usr/bin/perl -w
$| = 1;
use strict;
sub correct_range {
my @args = @_; # nasty side effects if you map @_!
my( $from, $to ) = map { $_ = reverse $_ } @args;
substr( $from, 0, length $to ) = $to;
return reverse( $from );
}
while( my $line = <DATA> ){
my( $from, $to ) = split /\s+/, $line;
print "In: $from -- $to\n";
$to = correct_range( $from, $to );
print "Out: $from -- $to\n\n";
}
__DATA__
1 17
201 2
123 45
199 201
999 1002
HTH,
Thomas
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/