develooper Front page | perl.beginners | Postings from February 2002

Re: Creating a string with quotes and delimiters from an Array

Thread Previous | Thread Next
From:
Angus Laycock
Date:
February 27, 2002 15:31
Subject:
Re: Creating a string with quotes and delimiters from an Array
Message ID:
003501c1bef9$e1a67040$f7448cd4@mralaycock
I'll try this in the morning.

Thanks

Gus
----- Original Message -----
From: Timothy Johnson <tjohnson@sandisk.com>
To: Timothy Johnson <tjohnson@sandisk.com>; 'Angus Laycock'
<angus.laycock@tesco.net>; Tanton Gibbs <thgibbs@deltafarms.com>;
<beginners@perl.org>
Sent: Wednesday, February 27, 2002 11:11 PM
Subject: RE: Creating a string with quotes and delimiters from an Array


>
> I guess I should have put this:  !~ /^[-+]{0,1}\d+(.\d+){0,1}$/ since
> there's really no time that you will need more than one positive or
negative
> in one number.
>
> -----Original Message-----
> From: Timothy Johnson [mailto:tjohnson@sandisk.com]
> Sent: Wednesday, February 27, 2002 3:05 PM
> To: 'Angus Laycock'; Tanton Gibbs; beginners@perl.org
> Subject: RE: Creating a string with quotes and delimiters from an Array
>
>
>
> maybe you can replace =~ /\D/ with "!~ /^[-+]?\d+(.\d+){0,1}$/"   *whew*
>
> which means "does not equal:
>
>    start with zero or more - or +   # ^[-+]?
>    followed by one or more digits   # \d+
>    followed by zero or one sets of a period followed by one or more digits
> at the end of the string  # (.\d+){0,1}$
>
> -----Original Message-----
> From: Angus Laycock [mailto:angus.laycock@tesco.net]
> Sent: Tuesday, February 26, 2002 10:41 AM
> To: Tanton Gibbs; beginners@perl.org
> Subject: Re: Creating a string with quotes and delimiters from an Array
>
>
> What about on negative numbers like -1? They come up with quotes, any
ideas?
>
> Thanks
>
> Gus
> ----- Original Message -----
> From: Tanton Gibbs <thgibbs@deltafarms.com>
> To: Angus Laycock <angus.laycock@tesco.net>; <beginners@perl.org>
> Sent: Wednesday, February 27, 2002 10:53 PM
> Subject: Re: Creating a string with quotes and delimiters from an Array
>
>
> > I apologize for not stating it earlier...mea culpa (and if I didn't have
> the
> > time, I shouldn't post to the beginners list anyway!)
> >
> > the ? : operator is like an if else statement
> > if actually expands to (sort of)
> >
> > if( /\D/ ) {
> >   $string .= "'$_',";
> > }
> > else {
> >   $string .= "$_,";
> > }
> >
> > The regular expression /\D/ matches anything that is not a digit.  Since
> we
> > do not provide a variable for it to operate on, it chooses the default
> > variable $_ which is set by the preceeding foreach loop.  The .= is the
> > string concatenation operator with assignment...it actually expands to
> > $string = $string . "'$_',";
> >
> > Hope this helps!
> > Tanton
> > ----- Original Message -----
> > From: "Angus Laycock" <angus.laycock@tesco.net>
> > To: <beginners@perl.org>
> > Sent: Tuesday, February 26, 2002 1:33 PM
> > Subject: Re: Creating a string with quotes and delimiters from an Array
> >
> >
> > > I know I now have the result but how does it do it?
> > >
> > > $string .= /\D/ ? "'$_'," : "$_,";
> > >
> > > If you have the time.
> > >
> > > Thanks again
> > >
> > > Gus
> > >
> > >
> > > ----- Original Message -----
> > > From: Tanton Gibbs <thgibbs@deltafarms.com>
> > > To: Angus Laycock <angus.laycock@tesco.net>; <beginners@perl.org>
> > > Sent: Wednesday, February 27, 2002 10:30 PM
> > > Subject: Re: Creating a string with quotes and delimiters from an
Array
> > >
> > >
> > > > Your best bet is to do this with a foreach loop
> > > >
> > > > my $string = '';
> > > > my @array = qw( alf bert charlie 4 )
> > > > foreach( @array ) {
> > > >   $string .= /\D/ ? "'$_'," : "$_,";
> > > > }
> > > > ----- Original Message -----
> > > > From: "Angus Laycock" <angus.laycock@tesco.net>
> > > > To: <beginners@perl.org>
> > > > Sent: Tuesday, February 26, 2002 1:07 PM
> > > > 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
> > > >
> > > >
> > > >
> > > > --
> > > > To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> > > > For additional commands, e-mail: beginners-help@perl.org
> > > >
> > > >
> > >
> > >
> > > --
> > > To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> > > For additional commands, e-mail: beginners-help@perl.org
> > >
> >
> >
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
>
>
> --------------------------------------------------------------------------
--
> ----
> 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.
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
>
>
> --------------------------------------------------------------------------
------
> 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.
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
>
>


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About