Come for the quick hacks, stay for the epiphanies. | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Because this is Perl, There Is More Than One Way To Do It (whatever "It" happens to be.) Another way to build the query string is: my $dbCommand = do { local $" = ','; "select @ticketsFields ..."; }; The $" variable determines what gets put between elements when you interpolate an array. If you use English; you can spell this $LIST_SEPARATOR. No matter which spelling you use you should localize the value to avoid spooky action at a distance, since this variable is global. The do block limits the scope of the local change to $". I do not present this as a better way to build the query string, simply as another way. Nitpick (or maybe not): Unless variables like @ticketsFields actually need to be visible outside your module, you could (and probably should) specify them as my rather than our. This may actually have practical consequences in the case of @ticketsRecords. Since you declared it our, there is only one instance of it. So if you do something like my $rec_1 = getTicketsRecords( ... ); my $rec_2 = getTicketsRecords( ... ); $rec_1 and $rec_2 refer to the same array, and contain the same data -- the results of the most recent call to getTicketRecords(). If you say my @ticketsRecords, each call returns a reference to a different array. In reply to Re: Is there a cleaner way to write this code below, which includes derferencing references, that themselves have to be dereferenced?
by Anonymous Monk
|
|