in reply to Re^3: Quote-like operators in a hash
in thread Quote-like operators in a hash

Your reply got me thinking on the right track. for some reason, when I did,
print $key." : ".sqlExecute($value);

something went wrong and it returned 1's instead of the query result. It seems like Perl didn't like the concatenations. I re-did the print to,
print "\t\t".$key." : "; print sqlExecute($value); print "\n";

I'm not sure why that changed things, but it did. If anyone knows why, I would like to hear it. Thanks to all who helped. I wouldn't have figured it out with your help.

Replies are listed 'Best First'.
Re^5: Quote-like operators in a hash
by kyle (Abbot) on Jan 05, 2009 at 19:10 UTC

    The difference is that print imparts a list context, but the dot operator creates a scalar context. Your sqlExecute() ends with "return @result". An array in a scalar context evaluates to the number of items in the array, but in a list context, it's all the elements of the array.

    Update: Here are a couple ways to get what you want without three lines:

    • Use commas: print "\t\t".$key." : ", sqlExecute($value), "\n";
    • Interpolate an anonymous array reference: print "\t\t$key : @{[ sqlExecute($value) ]}\n";

    The first is better for print, but the second can be useful in other places where you want to interpolate a function call.

      Wow, that makes so much sense. Thank you! This is why I love perlmonks. Everyone is so helpful and friendly.
      So, in other words, the root answer is the same as for the previous question at the gates today: Concatenate printing a string and array

      Wow. Co-incidence? I think not - there's something afoot in 2009. I think we should expect many more arrays being concatenated with strings before the year is out...

      --
      use JAPH;
      print JAPH::asString();