John and Bill Thanks very much for your replies,
Yes - map is indeed what I need. Works fine now. Many thanks Bill -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: 12 February 2006 16:24 To: Bill Stennett - compuserve Cc: activeperl mailing list Subject: Re: using grep and join to print a list 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
