in reply to Build your array with push

As japhy so kindly pointed out, the following:

my @folk = qw(Hibbs Daglish Schwartz Vroom), "Node Reaper"; my @folk = map {s/_/ /g; $_} qw(Hibbs Daglish Schwartz Vroom Node_Reaper);

should have been written

my @folk = (qw(Hibbs Daglish Schwartz Vroom), "Node Reaper"); my @folk = map {(my $s=$_)=~s/_/ /g; $s} qw(Hibbs Daglish Schwartz Vroom Node_Reaper);

Thatll teach me not to be a smarty pants.

---
$world=~s/war/peace/g

Replies are listed 'Best First'.
Re^2: Build your array with push
by japhy (Canon) on Jan 31, 2006 at 15:39 UTC
    First one doesn't work, second one is grasping at straws.

    Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
    How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart

      Neither work. Second one has the dreaded can't modify read only string error. Which is a good example of the issues the OP was making I guess. Sigh, i should know better for both of these too. :-(

      I will quibble with the "grasping at straws" comment tho. I think this approach often is just fine for dealing with spaces in a qw() string.

      ---
      $world=~s/war/peace/g

        My problem with the second approach (apart from the "read only" snag) is that it turns constant data into something that requires computation. Certainly, there are times when computation is necessary with constant data, such as when you are constructing a data structure like an array of arrays: you take tab-separated data, split on the tabs, and produce array references. That's certainly easier and faster to write than producing the data structure in the code itself. But in this case, I think it was overkill.

        Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
        How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart