Tim, Here are the results from @array = qw(one two three 4); 'one','two','three' 'one','two','three''one','two','three',4 Pretty close on the second one. Your first one certainly sorted it for the strings. Thanks Gus ----- Original Message ----- From: Timothy Johnson <tjohnson@sandisk.com> To: 'Angus Laycock' <angus.laycock@tesco.net>; <beginners@perl.org> Sent: Wednesday, February 27, 2002 10:24 PM Subject: RE: Creating a string with quotes and delimiters from an Array > > Oops. I meant: > > foreach(@array){ > if($_ !~ /^\d+$/){ > $scalar .= "\'$_\',"; # append the variable surrounded by single > quotes > }else{ > $scalar .= "$_,"; > } > } > chop scalar; #get rid of the last comma > > > -----Original Message----- > From: Timothy Johnson > Sent: Wednesday, February 27, 2002 2:23 PM > To: 'Angus Laycock'; beginners@perl.org > Subject: RE: Creating a string with quotes and delimiters from an Array > > > > You could try something like this: > > foreach(@array){ > unless($_ =~ /^\d+$/){ > $scalar .= "\'$_\',"; # append the variable surrounded by single > quotes > } > } > chop scalar; #get rid of the last comma > > It's a little messy, but it should work. > > -----Original Message----- > From: Angus Laycock [mailto:angus.laycock@tesco.net] > Sent: Tuesday, February 26, 2002 10:08 AM > To: beginners@perl.org > Subject: Creating a string with quotes and delimiters from an Array > > > Hi, > > I have an array ----> @array = qw(alf bert charlie 4) > > and I want a string that contains this value < 'alf','bert','charlie','4' > > with the single quotes and commas. > > I know I can do this $string = join ( ',' , @array); which gives me this > ----> < one|two|three|four> but how do I get the single quotes around each > word. > > > Also, how can I check if one of the values is numeric so I dont put quotes > around it? So the result is like this ---> < 'alf','bert','charlie',4 > > > Thanks > > > Gus > > > -------------------------------------------------------------------------- ------ > This email may contain confidential and privileged > material for the sole use of the intended recipient. > If you are not the intended recipient, please contact > the sender and delete all copies. >Thread Previous | Thread Next