Re: This is one of the things ...

2016-05-14 Thread Uri Guttman

On 05/14/2016 08:20 PM, lee wrote:

Uri Guttman  writes:


On 05/14/2016 07:11 PM, chace wrote:

Can you miss something you weren't aiming at? Thanks for the fun
fact, Uri :)

well, he asked about other langs with map like features which was the
target you aimed at. so missing lisp is worth noting! :)

Somehow I thought lisp might come up --- yet thinking of elisp, I fail
to imagine how a map-like function would fit in ... maybe as something
that somehow unwinds stuff rapidly and makes your program explode?

Is there an example in elisp?


just look for the functions that start with map.

uri


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: This is one of the things ...

2016-05-14 Thread lee
Uri Guttman  writes:

> On 05/14/2016 07:11 PM, chace wrote:
>> Can you miss something you weren't aiming at? Thanks for the fun
>> fact, Uri :)
>
> well, he asked about other langs with map like features which was the
> target you aimed at. so missing lisp is worth noting! :)

Somehow I thought lisp might come up --- yet thinking of elisp, I fail
to imagine how a map-like function would fit in ... maybe as something
that somehow unwinds stuff rapidly and makes your program explode?

Is there an example in elisp?

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: This is one of the things ...

2016-05-14 Thread Uri Guttman

On 05/14/2016 07:11 PM, chace wrote:
Can you miss something you weren't aiming at? Thanks for the fun fact, 
Uri :)


well, he asked about other langs with map like features which was the 
target you aimed at. so missing lisp is worth noting! :)


uri


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: This is one of the things ...

2016-05-14 Thread chace
Can you miss something you weren't aiming at? Thanks for the fun fact, 
Uri :)


On 05/14/2016 04:09 PM, Uri Guttman wrote:

On 05/14/2016 06:58 PM, Aaron Wells wrote:


Ha. Java has one... but it's not very pretty. Just like anything 
Java, it's bloated, overly verbose, and clunky. Java just discovered 
"lambdas" a couple years ago with jdk 8. But functional languages 
have had lambda syntax for years.


Ocaml: List.map((*) 2)[1;2;3;4;5]
Haskell: map (2*)[1,2,3,4,5]

And lots more examples here: http://c2.com/CGI/wiki?MapFunction

Then of course there's "whatever" syntax in Perl 6:
map * ** 2, [1,2,3,4,5]



but you missed the originator of map which is lisp.

uri





--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: This is one of the things ...

2016-05-14 Thread Uri Guttman

On 05/14/2016 06:58 PM, Aaron Wells wrote:


Ha. Java has one... but it's not very pretty. Just like anything Java, 
it's bloated, overly verbose, and clunky. Java just discovered 
"lambdas" a couple years ago with jdk 8. But functional languages have 
had lambda syntax for years.


Ocaml: List.map((*) 2)[1;2;3;4;5]
Haskell: map (2*)[1,2,3,4,5]

And lots more examples here: http://c2.com/CGI/wiki?MapFunction

Then of course there's "whatever" syntax in Perl 6:
map * ** 2, [1,2,3,4,5]



but you missed the originator of map which is lisp.

uri


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: This is one of the things ...

2016-05-14 Thread Aaron Wells
Ha. Java has one... but it's not very pretty. Just like anything Java, it's
bloated, overly verbose, and clunky. Java just discovered "lambdas" a
couple years ago with jdk 8. But functional languages have had lambda
syntax for years.

Ocaml: List.map((*) 2)[1;2;3;4;5]
Haskell: map (2*)[1,2,3,4,5]

And lots more examples here: http://c2.com/CGI/wiki?MapFunction

Then of course there's "whatever" syntax in Perl 6:
map * ** 2, [1,2,3,4,5]

On Sat, May 14, 2016, 3:42 PM lee  wrote:

> Uri Guttman  writes:
>
> > On 05/12/2016 08:04 PM, lee wrote:
> >> ... I appreciate perl for:
> >>
> >>
> >> $dbh->do("INSERT INTO $T_ENTRIES (" .
> >>   join(', ', map($dbh->quote_identifier($_), $cgi->param)) . ')
> VALUES (' .
> >>   join(', ', map($dbh->quote($_), map($cgi->param($_),
> $cgi->param))) . ')')
> >>if(scalar($cgi->param) == 111);
> >>
> > not bad but i have a few improvements that you may like.
> >
> > i would not call $cgi->param so often. easy enough to use arrays.
> >
> > my @cgi_params = $cgi->param() ;
> > my @cgi_values = $cgi->param( @cgi_params ) ;
>
> Oh, I didn't know you can do
> 'my @cgi_values = $cgi->param(@cgi_params);', thanks!
>
> How does that play out?
>
> my @cgi_values = $cgi->param($cgi->param);
>
> And hence:
>
> $dbh->do("INSERT INTO $T_ENTRIES (" .
>  join(', ', map($dbh->quote_identifier($_), $cgi->param)) . ')
> VALUES (' .
>  join(', ', map($dbh->quote($_), $cgi->param($cgi->param))) . ')')
>if(scalar($cgi->param) == 111);
>
> ?
>
> You could make that:
>
>
> if (scalar($cgi->param) == 111) {
>   my $i = join(', ', map($dbh->quote_identifier($_), $cgi->param));
>   my $v = join(', ', map($dbh->quote($_), $cgi->param($cgi->param)));
>
>   $dbh->do("INSERT INTO $T_ENTRIES ($i) VALUES ($v)");
> }
>
>
> Would that work?
>
> > i like to build up the sql parts outside of the call and to use ?
> > placeholders which are quoted for you.
> >
> > my $holders = join ',', ('?') x @cgi_params ;
> >
> > and i like here docs for sql so i can see the sql and not need all
> > those quotes and noise. also assigning the sql  to a scalar so i can
> > print it out for debugging
> >
> > my $sql = < > INSERT INTO $T_ENTRIES ( $holders ) VALUES ( $holders )
> > SQL
> >
> > my $sth = $dbh->prepare( $sql ) ;
> > $sth->execute( @cgi_params, @cgi_values ) ;
>
> Don't you need (properly quoted) identifiers rather than place holders
> where the identifiers go?
>
>
> if (scalar($cgi->param) == 111) {
>   my @cgi_params = $cgi->param();
>   my @cgi_values = $cgi->param( @cgi_params );
>   @cgi_params = map($dbh->quote_identifier($_), @cgi_params);
>
>   unless (scalar(@cgi_params) != scalar(@cgi_values)) {
> my $identifiers = join(', ', @cgi_params);
> my $holders = join(', ', ('?') x scalar(@cgi_values));
>
> my $sql = < INSERT INTO $T_ENTRIES ( $identifiers ) VALUES ( $holders )
> SQL
>
> my $sth = $dbh->prepare( $sql );
> $sth->execute(@cgi_values);
> $sth->finish();
>   } else {
> print $cgi->p('ERROR: perhaps do something') . "/n";
>   }
> }
>
>
> Which version is better for performance?
>
> > it may look longer but it is easier to read, debug and reuse this
> > way. it can be made into a sub with other options (selecting or where
> > clauses, etc.).
> >
> > i didn't add in the if condition but that can be put in front of this
> code.
>
> I guess I just happened to finally learn the 'map()' function and
> immediately found it extremely useful and elegant :)
>
> Are there other programming languages having the same, or an equivalent?
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>


Re: This is one of the things ...

2016-05-14 Thread lee
"Walker, Michael E"  writes:

> Hi,
>
> What framework are you all using for database development? When tracking this 
> thread back to the original message, I thought, "Nice syntax." I am overall 
> new to Perl, but am learning it for ETL at work.

http://dbi.perl.org/

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: This is one of the things ...

2016-05-14 Thread lee
Uri Guttman  writes:

> On 05/12/2016 08:04 PM, lee wrote:
>> ... I appreciate perl for:
>>
>>
>> $dbh->do("INSERT INTO $T_ENTRIES (" .
>>   join(', ', map($dbh->quote_identifier($_), $cgi->param)) . ') VALUES 
>> (' .
>>   join(', ', map($dbh->quote($_), map($cgi->param($_), $cgi->param))) . 
>> ')')
>>if(scalar($cgi->param) == 111);
>>
> not bad but i have a few improvements that you may like.
>
> i would not call $cgi->param so often. easy enough to use arrays.
>
> my @cgi_params = $cgi->param() ;
> my @cgi_values = $cgi->param( @cgi_params ) ;

Oh, I didn't know you can do
'my @cgi_values = $cgi->param(@cgi_params);', thanks!

How does that play out?

my @cgi_values = $cgi->param($cgi->param);

And hence:

$dbh->do("INSERT INTO $T_ENTRIES (" .
 join(', ', map($dbh->quote_identifier($_), $cgi->param)) . ') VALUES 
(' .
 join(', ', map($dbh->quote($_), $cgi->param($cgi->param))) . ')')
   if(scalar($cgi->param) == 111);

?

You could make that:


if (scalar($cgi->param) == 111) {
  my $i = join(', ', map($dbh->quote_identifier($_), $cgi->param));
  my $v = join(', ', map($dbh->quote($_), $cgi->param($cgi->param)));

  $dbh->do("INSERT INTO $T_ENTRIES ($i) VALUES ($v)");
}


Would that work?

> i like to build up the sql parts outside of the call and to use ?
> placeholders which are quoted for you.
>
> my $holders = join ',', ('?') x @cgi_params ;
>
> and i like here docs for sql so i can see the sql and not need all
> those quotes and noise. also assigning the sql  to a scalar so i can
> print it out for debugging
>
> my $sql = < INSERT INTO $T_ENTRIES ( $holders ) VALUES ( $holders )
> SQL
>
> my $sth = $dbh->prepare( $sql ) ;
> $sth->execute( @cgi_params, @cgi_values ) ;

Don't you need (properly quoted) identifiers rather than place holders
where the identifiers go?


if (scalar($cgi->param) == 111) {
  my @cgi_params = $cgi->param();
  my @cgi_values = $cgi->param( @cgi_params );
  @cgi_params = map($dbh->quote_identifier($_), @cgi_params);

  unless (scalar(@cgi_params) != scalar(@cgi_values)) {
my $identifiers = join(', ', @cgi_params);
my $holders = join(', ', ('?') x scalar(@cgi_values));

my $sql = execute(@cgi_values);
$sth->finish();
  } else {
print $cgi->p('ERROR: perhaps do something') . "/n";
  }
}


Which version is better for performance?

> it may look longer but it is easier to read, debug and reuse this
> way. it can be made into a sub with other options (selecting or where
> clauses, etc.).
>
> i didn't add in the if condition but that can be put in front of this code.

I guess I just happened to finally learn the 'map()' function and
immediately found it extremely useful and elegant :)

Are there other programming languages having the same, or an equivalent?

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




RE: Start a New Thread for a New Question (WAS: This is one of the things ...)

2016-05-13 Thread Walker, Michael E
Thank you for letting me know.

-Original Message-
From: Shawn H Corey [mailto:shawnhco...@gmail.com] 
Sent: Friday, May 13, 2016 10:01 AM
To: beginners@perl.org
Subject: Re: Start a New Thread for a New Question (WAS: This is one of the 
things ...)

On Fri, 13 May 2016 13:20:15 +
"Walker, Michael E"  wrote:

> Hi,
> 
> What framework are you all using for database development? When 
> tracking this thread back to the original message, I thought, "Nice 
> syntax." I am overall new to Perl, but am learning it for ETL at work.
> 
> Thanks,
> Mike

Hi Mike,

FYI: To get as many responses as possible, you should start a new thread for a 
new question. If you tack onto a existing thread, some people will read just 
the subject and skip it as not interesting. Starting a new thread will get more 
people to read it. :)


--
Don't stop where the ink does.
Shawn

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, 
e-mail: beginners-h...@perl.org http://learn.perl.org/





--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Start a New Thread for a New Question (WAS: This is one of the things ...)

2016-05-13 Thread Shawn H Corey
On Fri, 13 May 2016 13:20:15 +
"Walker, Michael E"  wrote:

> Hi,
> 
> What framework are you all using for database development? When
> tracking this thread back to the original message, I thought, "Nice
> syntax." I am overall new to Perl, but am learning it for ETL at work.
> 
> Thanks,
> Mike

Hi Mike,

FYI: To get as many responses as possible, you should start a new thread
for a new question. If you tack onto a existing thread, some people will
read just the subject and skip it as not interesting. Starting a new
thread will get more people to read it. :)


-- 
Don't stop where the ink does.
Shawn

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




RE: This is one of the things ...

2016-05-13 Thread Walker, Michael E
Hi,

What framework are you all using for database development? When tracking this 
thread back to the original message, I thought, "Nice syntax." I am overall new 
to Perl, but am learning it for ETL at work.

Thanks,
Mike

-Original Message-
From: Shawn H Corey [mailto:shawnhco...@gmail.com] 
Sent: Friday, May 13, 2016 7:16 AM
To: beginners@perl.org
Subject: Re: This is one of the things ...

On Fri, 13 May 2016 00:11:57 -0400
Uri Guttman  wrote:

> i stick to using fat comma ( => ) only for key/value pairs. it has the 
> side effect of quoting a bareword to the left which makes those pairs 
> easier to read. so i never use it just for a comma though i have seen 
> it used like that. this is definitely a matter of taste and i know 
> mine is better than most! :)
> 
> as for q{} i stick to using it when there are quote chars in the 
> string. i haven't had trouble reading '' (vs "" vs q{}) as the null 
> string. pick a better font if you have trouble! :) also context (not 
> perl but code in general) should make it easier to know when a null 
> string is being used.

Another method is to use `constant` since it creates constant subs which perl 
replaces with the literal.

$ cat quotes.pl
#!/usr/bin/env perl

use constant {
qSPACE=> q{ },
qCOMMA=> q{,},
qQUESTION => q{?},
};

my $holders = join qCOMMA, (qQUESTION) x @cgi_params;

$ perl -MO=Deparse ./quotes.pl
use constant ({'qSPACE', ' ', 'qCOMMA', ',', 'qQUESTION', '?'}); my $holders = 
join(',', ('?') x @cgi_params); ./quotes.pl syntax OK


Notice in the join that qCOMMA and qQUESTION were replaced with the
literal.


-- 
Don't stop where the ink does.
Shawn

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/





--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: This is one of the things ...

2016-05-13 Thread Shawn H Corey
On Fri, 13 May 2016 00:11:57 -0400
Uri Guttman  wrote:

> i stick to using fat comma ( => ) only for key/value pairs. it has
> the side effect of quoting a bareword to the left which makes those
> pairs easier to read. so i never use it just for a comma though i
> have seen it used like that. this is definitely a matter of taste and
> i know mine is better than most! :)
> 
> as for q{} i stick to using it when there are quote chars in the
> string. i haven't had trouble reading '' (vs "" vs q{}) as the null
> string. pick a better font if you have trouble! :) also context (not
> perl but code in general) should make it easier to know when a null
> string is being used.

Another method is to use `constant` since it creates constant subs
which perl replaces with the literal.

$ cat quotes.pl 
#!/usr/bin/env perl

use constant {
qSPACE=> q{ },
qCOMMA=> q{,},
qQUESTION => q{?},
};

my $holders = join qCOMMA, (qQUESTION) x @cgi_params;

$ perl -MO=Deparse ./quotes.pl 
use constant ({'qSPACE', ' ', 'qCOMMA', ',', 'qQUESTION', '?'});
my $holders = join(',', ('?') x @cgi_params);
./quotes.pl syntax OK


Notice in the join that qCOMMA and qQUESTION were replaced with the
literal.


-- 
Don't stop where the ink does.
Shawn

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: This is one of the things ...

2016-05-12 Thread Uri Guttman

On 05/12/2016 11:00 PM, SSC_perl wrote:

On May 12, 2016, at 7:10 PM, Shawn H Corey wrote:


my $holders = join ',', ('?') x @cgi_params;

PBP recommends that you put short strings that are all punctuation in
q{}, so they will be easier to read.

my $holders = join q{,}, (q{?}) x @cgi_params;

I realize stuff like this is subjective, and coding styles can be very 
personal, but this looks cleaner to me:

my $holders = join ',' => ('?') x @cgi_params;

Since I found the fat comma, I use it all the time now - especially 
when two commas are so close together.  I'm kind of surprised PBP would say 
that q{} is easier to read in this situation.  IMHO, it seems to just adds 
noise.



i stick to using fat comma ( => ) only for key/value pairs. it has the 
side effect of quoting a bareword to the left which makes those pairs 
easier to read. so i never use it just for a comma though i have seen it 
used like that. this is definitely a matter of taste and i know mine is 
better than most! :)


as for q{} i stick to using it when there are quote chars in the string. 
i haven't had trouble reading '' (vs "" vs q{}) as the null string. pick 
a better font if you have trouble! :) also context (not perl but code in 
general) should make it easier to know when a null string is being used.


thanx,

uri

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: This is one of the things ...

2016-05-12 Thread SSC_perl
On May 12, 2016, at 7:10 PM, Shawn H Corey wrote:

>> my $holders = join ',', ('?') x @cgi_params;
> PBP recommends that you put short strings that are all punctuation in
> q{}, so they will be easier to read.
> 
>my $holders = join q{,}, (q{?}) x @cgi_params;

I realize stuff like this is subjective, and coding styles can be very 
personal, but this looks cleaner to me:

my $holders = join ',' => ('?') x @cgi_params;

Since I found the fat comma, I use it all the time now - especially 
when two commas are so close together.  I'm kind of surprised PBP would say 
that q{} is easier to read in this situation.  IMHO, it seems to just adds 
noise.

Frank
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: This is one of the things ...

2016-05-12 Thread Shawn H Corey
On Thu, 12 May 2016 21:35:02 -0400
Uri Guttman  wrote:

>  my $holders = join ',', ('?') x @cgi_params ;
> 
> and i like here docs for sql so i can see the sql and not need all
> those quotes and noise.

PBP recommends that you put short strings that are all punctuation in
q{}, so they will be easier to read.

my $holders = join q{,}, (q{?}) x @cgi_params ;


-- 
Don't stop where the ink does.
Shawn

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: This is one of the things ...

2016-05-12 Thread Uri Guttman

On 05/12/2016 08:04 PM, lee wrote:

... I appreciate perl for:


$dbh->do("INSERT INTO $T_ENTRIES (" .
 join(', ', map($dbh->quote_identifier($_), $cgi->param)) . ') VALUES 
(' .
 join(', ', map($dbh->quote($_), map($cgi->param($_), $cgi->param))) . 
')')
   if(scalar($cgi->param) == 111);


not bad but i have a few improvements that you may like.

i would not call $cgi->param so often. easy enough to use arrays.

my @cgi_params = $cgi->param() ;
my @cgi_values = $cgi->param( @cgi_params ) ;

i like to build up the sql parts outside of the call and to use ? 
placeholders which are quoted for you.


my $holders = join ',', ('?') x @cgi_params ;

and i like here docs for sql so i can see the sql and not need all those 
quotes and noise. also assigning the sql  to a scalar so i can print it 
out for debugging


my $sql = execute( @cgi_params, @cgi_values ) ;

it may look longer but it is easier to read, debug and reuse this way. 
it can be made into a sub with other options (selecting or where 
clauses, etc.).


i didn't add in the if condition but that can be put in front of this code.

thanx,

uri





--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: This is one of the things ...

2016-05-12 Thread Aaron Wells
Thank you Lee. I had forgotten about that use case. I tried to do dibasic
query building once upon a time with JavaScript before discovering the
goodness of Perl. Ended up leaning on a library. It made things better, but
it didn't make them Perl.

On Thu, May 12, 2016, 5:06 PM lee  wrote:

>
> ... I appreciate perl for:
>
>
> $dbh->do("INSERT INTO $T_ENTRIES (" .
>  join(', ', map($dbh->quote_identifier($_), $cgi->param)) . ')
> VALUES (' .
>  join(', ', map($dbh->quote($_), map($cgi->param($_),
> $cgi->param))) . ')')
>   if(scalar($cgi->param) == 111);
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>


This is one of the things ...

2016-05-12 Thread lee

... I appreciate perl for:


$dbh->do("INSERT INTO $T_ENTRIES (" .
 join(', ', map($dbh->quote_identifier($_), $cgi->param)) . ') VALUES 
(' .
 join(', ', map($dbh->quote($_), map($cgi->param($_), $cgi->param))) . 
')')
  if(scalar($cgi->param) == 111);

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/