Help needed with Perl array push/map
Posted: Mon Apr 25, 2011 6:49 am
Hey guys!
I am begginer when speaking of Perl programming language, so i need your help.
Can please someone tell me what exactly this piece of code does?
There is SQL SELECT query executed just before this piece of code; $sth is result object
I know that @res is an array, and i also know that this while loop does this 'push' into array thing for every affected row, but i do not understand
this part:
Can please someone help? 
Also, can someone please explain use of colon sign in this context:
Also, need to know what this subroutine does, so if anybody can help...
I am begginer when speaking of Perl programming language, so i need your help.
Can please someone tell me what exactly this piece of code does?
Code: Select all
my @res;
while ( my @r = $sth -> fetchrow() ) {
push @res, [ map { 'ARRAY' eq ref $_ ? [ @$_ ] : $_ } @r ];
}
I know that @res is an array, and i also know that this while loop does this 'push' into array thing for every affected row, but i do not understand
this part:
Code: Select all
[ map { 'ARRAY' eq ref $_ ? [ @$_ ] : $_ } @r ]
Also, can someone please explain use of colon sign in this context:
Code: Select all
$sth = $DBH -> prepare ( " SELECT * FROM table WHERE some_column = :1 AND another_column = :2 " );
Code: Select all
sub ntype {
{ x => 1, y => 2 } -> { shift -> { z } }
}