Re: Converting a list join to a scaler/string

From: J. Gleixner (glex_nospam_at_qwest.invalid)
Date: 11/06/03


Date: Thu, 06 Nov 2003 10:34:45 -0600

sdfgsd wrote:
> "Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
> news:bodl1l$n2$1@mamenchi.zrz.TU-Berlin.DE...
>
>>sdfgsd <footnipple@indiatimes.com> wrote in comp.lang.perl.misc:
>
>
> <snip>
>
>>>The comma could not be stripped from the string produced by the join
>>
>>Of course not. Remember how you built the string? The parts were
>>
>> my @quoted = map {"'$_', "} @fields;
>>
>>These all end with a comma *and a blank*, and so does the joined string
>>you build from them. No mystery at all.
>>
>>Anno
>>
>
>
> OH Jeez!! Thanks.

Now that you've stated you're trying to build SQL, there are better ways
to do what you want. Read a few of the many articles at:

http://www.perl.com/search/index.ncsp?sp-q=dbi&submit=Search

For instance:

http://www.perl.com/pub/a/2001/03/dbiokay.html

my $fields = join(', ', @fields);
my $values = join(', ', map { $dbh->quote($_) } @formdata{@fields});
my $sql = "INSERT into $table ($fields) values ($values)";

Can also use placeholders, and not have to worry about calling quote
directly, to make things even nicer. That's also covered in that article.



Relevant Pages

  • Re: Converting a list join to a scaler/string
    ... Remember how you built the string? ... No mystery at all. ... OH Jeez!! ...
    (comp.lang.perl.misc)
  • Re: Hash Code Compression
    ... just for String -- is a Java int, ... My hash table is made up of an array of n LinkedLists (where n is a ... fact the hashTable is an array of LinkedLists is so that it handles ... Because i am currently building the dictionary file by trawling news articles each word I pull from an article needs to be checked in the dictionary to see if we already have it. ...
    (comp.lang.java.programmer)
  • Re: passing stl through dll
    ... The difference to things written in the articles is that I design a string class that is directly derived from std::string and does not have any other STL members (beside the traits and allocator that basic_string has itself. ... int GetLengthconst; ... For the last line I get error C2949 on EXPIMP_STL: explicit instantiation; auto and extern can't be used on same level of template specialization. ...
    (microsoft.public.vc.stl)
  • Re: Dynamically create Drawing.Pens color?
    ... Try Int32.Parse or TryParse to convert from string to a 32 bit value and then use that in the FromArgb. ... Find great Windows Forms articles in Windows Forms Tips and Tricks ... Answer those GDI+ questions with the GDI+ FAQ ... > Dim strFore As String ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: a nice little perl utility
    ... Use of uninitialized value in concatenation or string at jabba5.pl ... How did this have to do with the print statement? ... # Fetch overview information for the articles ...
    (comp.lang.perl.misc)