Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Is there a cleaner way to write this code below, which includes derferencing references, that themselves have to be dereferenced?

by Anonymous Monk
on May 06, 2022 at 14:08 UTC ( [id://11143628]=note: print w/replies, xml ) Need Help??


in reply to Is there a cleaner way to write this code below, which includes derferencing references, that themselves have to be dereferenced?

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.

  • Comment on Re: Is there a cleaner way to write this code below, which includes derferencing references, that themselves have to be dereferenced?
  • Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11143628]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-04-16 16:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found