3

I realize similar questions have been asked. However, in this case I wish to use this open source perl script:

https://github.com/bAndie91/tools/blob/master/usr/bin/indent2tree

This line is producing the error Experimental push on scalar is now forbidden at /usr/local/bin/indent2tree line 43, near "};"

push $ForkPoint->{subtree}, {data=>$data, parent=>$ForkPoint, subtree=>[]};

I am not very familiar with Perl. I did check several questions on this topic and I tried to fix the issue a few different ways without success.

For example:

push @ForkPoint->{subtree}, {data=>$data, parent=>$ForkPoint, subtree=>[]};

That still produces the error.

Since my goal here is to just use the tool, maybe someone who is familiar with Perl can share the solution. I opened a bug at the project issue page.

MountainX
  • 6,217
  • 8
  • 52
  • 83

1 Answers1

6

You need

push @{ $ForkPoint->{subtree} }, ...

Whenever you can use the name of a variable, you can use a block that evaluates to a reference instead. That means the following are valid syntax for specifying an array:

@NAME    # If you have the name
@BLOCK   # If you have a reference

That means that the following two snippets are equivalent:

push @arary, ...

my $ref = \@array;
push @{ $ref }, ...

While not relevant in this case, you can omit the curlies when the only thing in the block is a simple scalar ($NAME or $BLOCK).

push @$ref, ...

See Perl Dereferencing Syntax.

ikegami
  • 367,544
  • 15
  • 269
  • 518