in reply to Legacy code question

Is there any advantage to using an array over a string here?

I guess it depends on how the variable is used afterwards - if there are additional values being pushed onto the array, it might make sense. It's just assigning a single value to the array; personally I would have written my @sqltt = (<<EOF); to make it explicit that yes, I meant to assign a single value to this array. But if the code then goes on to use $sqltt[0] everywhere, and especially if it doesn't add elements to the array, then it would definitely have been better to just use a plain scalar in the first place.

use warnings; use strict; use Data::Dump; my @sqltt = <<EOF; Hello, World! EOF dd @sqltt; __END__ "Hello,\nWorld!\n"

Minor update to wording.

Replies are listed 'Best First'.
Re^2: Legacy code question
by Zenzizenzizenzic (Pilgrim) on May 13, 2019 at 14:23 UTC
    Nothing is added to it, only use is as \@sqltt. I'm thinking this is a "do not do" thing. Thank you!
      Nothing is added to it, only use is as \@sqltt. I'm thinking this is a "do not do" thing.

      It still depends on the surrounding code - if it's being passed to a function that expects an arrayref, then some form of such is required, either my @sqltt = (<<EOF); ... func(\@sqltt), my $sqltt = [<<EOF]; ... func($sqltt), or my $sqltt = <<EOF; ... func([$sqltt]) would be needed (which one is a matter of taste), and "do not do" wouldn't necessarily apply. Context matters :-)