Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Experimental push on scalar is now forbidden at indent2tree

Tags:

perl

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.

like image 348
MountainX Avatar asked Oct 31 '25 03:10

MountainX


1 Answers

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.

like image 169
ikegami Avatar answered Nov 06 '25 03:11

ikegami



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!