Thread Experimental push on scalar is now forbidden (21 answers)
Opened by hlubenow at 2023-08-20 16:35

rosti
 2023-08-21 15:09
#195288 #195288
User since
2011-03-19
3472 Artikel
BenutzerIn
[Homepage]
user image
Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
    sub pushOnRef {
        # Geht das nicht besser?
        my $self = shift;
        my $ref = shift;
        my $val = shift;
        my @temp = @{$ref};
        push(@temp, $val);
        $ref = \@temp;
        return $ref;
    }


Ja, geht. Bedenke daß manchmal auch mehrere Werte zu pushen sind. Also nimm einfach @_

Code (perl): (dl )
1
2
3
4
5
sub push{
   my $self = shift;
   my $ref  = shift;
   push @$ref, @_;    # fertig
} 

View full thread Experimental push on scalar is now forbidden