Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using sprintf - related to trailing spaces query ! 2

Status
Not open for further replies.

rab54

Programmer
Joined
Jan 28, 2004
Messages
112
Location
GB
Gurus -

my $new_postcode = sprintf "%-${$pcode_fixed_length}s", $postcode;

Why does the above not work - when postcode = H55 7UU

I am after

H55 7UU ,

but the spaces are not added !

any ideas ?

cheers

Rab
 
Your problem is, actually, that
[tt]${$pcode_fixed_length}[/tt]
should be
[tt]${pcode_fixed_length}[/tt]

The former is trying to take the contents of [tt]$pcode_fixed_length[/tt] as a scalar reference, and dereference it into the actual scalar. Since it's not, actually, a reference to a scalar, it's just giving you nothing. This is making your sprintf turn out to be:
[tt]sprintf "%-s", $postcode;[/tt]
 
Doh !

cheers mate !
 
Very informative rosenk...
you get a star.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top