Perl gem
-
I know you don't get these very often, so please enjoy :). And hi to everyone - forums look great these days.
my $select = ""; my (@fields) = ("field1", "field2", "field3", "field4", "field5", "field6", "field7", "field8", "field9", "field10", "field11", "field12", "field13", "field14", "field15", "field16", "field17", "field18"); foreach my $f (@fields) { $select .= "$f,"; } chop $select;
For those unfamiliar, @name= array variable, $name = scalar variable. 'chop' is interpreted as a function call with the intentional side effect of removing the last character from the scalar you pass it. As a bonus, plaintext strings surrounded by double quotes must be parsed by the interpreter (this is Perl) and variable names within them are replaced with values.
-
I know you don't get these very often, so please enjoy :). And hi to everyone - forums look great these days.
my $select = ""; my (@fields) = ("field1", "field2", "field3", "field4", "field5", "field6", "field7", "field8", "field9", "field10", "field11", "field12", "field13", "field14", "field15", "field16", "field17", "field18"); foreach my $f (@fields) { $select .= "$f,"; } chop $select;
For those unfamiliar, @name= array variable, $name = scalar variable. 'chop' is interpreted as a function call with the intentional side effect of removing the last character from the scalar you pass it. As a bonus, plaintext strings surrounded by double quotes must be parsed by the interpreter (this is Perl) and variable names within them are replaced with values.
That is, he creates one big string containing the values of $field1 to $field18 separated by a comma?
-
I know you don't get these very often, so please enjoy :). And hi to everyone - forums look great these days.
my $select = ""; my (@fields) = ("field1", "field2", "field3", "field4", "field5", "field6", "field7", "field8", "field9", "field10", "field11", "field12", "field13", "field14", "field15", "field16", "field17", "field18"); foreach my $f (@fields) { $select .= "$f,"; } chop $select;
For those unfamiliar, @name= array variable, $name = scalar variable. 'chop' is interpreted as a function call with the intentional side effect of removing the last character from the scalar you pass it. As a bonus, plaintext strings surrounded by double quotes must be parsed by the interpreter (this is Perl) and variable names within them are replaced with values.
He made a perfect example of code reuse! Spared 17 times the $ sign!!!
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
-
I know you don't get these very often, so please enjoy :). And hi to everyone - forums look great these days.
my $select = ""; my (@fields) = ("field1", "field2", "field3", "field4", "field5", "field6", "field7", "field8", "field9", "field10", "field11", "field12", "field13", "field14", "field15", "field16", "field17", "field18"); foreach my $f (@fields) { $select .= "$f,"; } chop $select;
For those unfamiliar, @name= array variable, $name = scalar variable. 'chop' is interpreted as a function call with the intentional side effect of removing the last character from the scalar you pass it. As a bonus, plaintext strings surrounded by double quotes must be parsed by the interpreter (this is Perl) and variable names within them are replaced with values.
I was half expecting a musical reference... :doh:
Wrong is evil and must be defeated. - Jeff Ello[^]
-
I was half expecting a musical reference... :doh:
Wrong is evil and must be defeated. - Jeff Ello[^]
-
That is, he creates one big string containing the values of $field1 to $field18 separated by a comma?
Not quite... the
"$f,"
only interpolates the value of thef
scalar... so the result is the single string:'field1,field2,field3,field4,field5,field6,field7,field8,field9,field10,field11,field12,field13,field14,field15,field16,field17,field18'
Seriously pointless!