I've googled the error (stated in the Question title) and can't find anything relevant.
#!/usr/bin/perl
use strict;
my %cc;
my @cc => (3,4,5,6,6,7,7);
$cc{key} = \@cc;
$0 = $cc{key}[0] * 2;
$1 = $cc{key}[1] * 1; #error here
my $total = $0 + $1;
print "$1";
print "$total";
line 11 is my error...
$0
and $1
are special variables in Perl (see perldoc perlvar). $1
is a read only variable.
Also, you should enable warnings to see many more problems with your code.
My guess is that you want something like this:
use strict;
use warnings;
my @cc = (3,4,5,6,6,7,7);
my %cc;
$cc{key} = \@cc;
my $k0 = $cc{key}[0] * 2;
my $k1 = $cc{key}[1] * 1;
my $total = $k0 + $k1;
print "$k1\n";
print "$total\n";
perldoc perldiag has more information on the error message: "Modification of a read-only value attempted".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With