Bill Stennett - compuserve wrote:

> Hi All,
> 
> Just a quick question if I may. What am I doing wrong here?
> 
> use strict;
> use warnings;
> 
> my $sortedstring = '';
> my @sortedline = (1,3,7,9,12,45);
> 
> # attempt build a string of every number from the sortedline array with
> # a leading zero to make up to two digits as appropriate
> $sortedstring = join( ', ', grep( sprintf('%02d',$_ ), @sortedline ) );

Maybe you want 'map' instead of 'grep' ???

> #display the result
> print $sortedstring;
> 
> The fragment above was intended to print out the list '@sortedline' comma
> seperated and with a leading zero added to make each number to two digits.
> 
> It doesn't work as I had hoped and, while it does print a comma seperated
> list the leading zeros do not appear.
> 
> The program output is: 1, 3, 7, 9, 12, 45
> 
> Can anyone tell me what I'm missing here please?
> 
> If this is just the wrong way to go about this then alternative suggestions
> greatly received
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to