Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't modify constant item in scalar assignment 2

Status
Not open for further replies.

JohnLucania

Programmer
Oct 10, 2005
96
US
What is this error about and how to fix?

Can't modify constant item in scalar assignment at line 16, near "}"


#! /usr/bin/perl

use strict;
use warnings;

package Protein;

our %attrib;

sub new {
my( $class , %attribs ) = ( @_ );
my $obj = {
_name = $attrib{name} || die "need 'name'!",
_manu = $attrib{manufacturer} || die "need 'manufacturer'!",
_seq = $attrib{sequence} || die "need 'sequence'!",
};
return bless $obj , $class;
}

my $prot = Protein->new(
name => 'BsrDI',
manufacturer => 'Boehringer Mannheim',
sequence => 'GGCCTACCCTGGGTAAGGGCCTGGAGCAGGA',
);

sub get_name {
my( $self ) = ( @_ );
return $self->{_name};
}
sub get_manu {
my( $self ) = ( @_ );
return $self->{_manu};
}
sub get_seq {
my( $self ) = ( @_ );
return $self->{_seq};
}

my $name = $prot->get_name;
my $manufacturer = $prot->get_manu;
my $sequence = $prot->get_seq;

print $name;
print $manufacturer;
print $sequence;

print "\n";

 
Hi

You are changing a constant

_name

you should use $name.....

dmazzini
GSM System and Telecomm Consultant

 
Try using the `=>' operator instead of `=' when setting up your hash. `=' is the assignment operator, so you're trying to assign a value to _name, which isn't a variable.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top