"Shishir K. Singh" wrote:
> 
> Thanks to Mark, John, David and Timothy....!! I get the results if I use the 
>combination of
> 
> eg $myVar = 'ABCDEFGHIJKLMNOP';
> $newVar = pack('A10',$myVar);
> $newVar should have 'ABCDEFGHIJ'; # Works and faster than sprintf
> 
> eg $myVar = 'ABCD';
> $newVar = pack('A10',$myVar);
> $newVar should have 'ABCD      '; # Works and faster than sprintf
> 
> eg $myVar = 'ABCD'; (Right Aligned, padded with spaces)
> $newVar = sprintf("%-10.10s, $myVar);
> $newVar should have '      ABCD'; # Works. Have to use sprintf as nothing available 
>for right justify in pack.
> 
> Think pack is an elegant way of truncating a string.

That is what substr() was created for.  :-)

my $myVar = 'ABCDEFGHIJKLMNOP';

print substr( $myVar, 0, 10 ); # prints ABCDEFGHIJ
print substr( $myVar, -10 );   # prints GHIJKLMNOP


John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to