Loading ...
Sorry, an error occurred while loading the content.

Re: [PBML] neat perl stuff

Expand Messages
  • J.E. Cripps
    Brad L s 3rd or so example 1 # real world example 2 my %tablefields = ( name = brad , age = 23 ); 3 my $insert = insert into person ( . 4 join( , ,
    Message 1 of 4 , Nov 27, 2003
    • 0 Attachment
      Brad L's 3rd or so example

      1> # real world example
      2> my %tablefields = ( name => 'brad', age => 23 );

      3> my $insert = 'insert into person (' .
      4> join(',', sort keys %tablefields) .
      5> ') values (' .
      6> join(',', map { '?' } keys %tablefields);
      7> ')';
      8> my $sth = $dbh->prepare($insert);
      9> $sth->execute(@tablefields{sort keys %tablefields});


      An extra ";" in line 6, and a missing " . "
      Or so I think. Umm, where did that "prepare()" come from?


      > # Abusing list context;
      > # How many times have you written something like this:

      > my @array = functionThatReturnsALargeList();

      > # only to use 3 or four elements from that list.
      > # force the return value into list context and just pull out the indexes
      > # you need:
      > my ($size,$uid) = (stat $filename)[7,4]

      Neat indeed.
    Your message has been successfully submitted and would be delivered to recipients shortly.