use strict;

package MySequence;

our $EcoRI = 'ggatcc';

sub new {
   # when you make a method call on an OO module
   # the first argument is the class
   my $class = shift;

   my %args = @_;
   
   # create a new hash reference (i.e., a reference to a hash), 
   # which will store all the object data
   # it is the actual object you're calling this method from
   my $self = {};
   
   # stores object data in the hash reference $self
   foreach my $key (keys %args) {
      $self->{$key} = $args{$key};
   }

   # associate this new bit of memory with a class type
   # and turn the hashref into an object
   bless $self, $class;

   # return the newly created object
   return($self);

}

sub reversec {
   # when called in an object context, the object is 
   # automatically passed in at the first argument
   my $self = shift;

   my $sequence = shift;
   $sequence = reverse $sequence;
   $sequence =~ tr/gatcGATC/ctagCTAG/;
   return $sequence;
}

sub seqlen {
   # when called in an object context, the object is 
   # automatically passed in at the first argument
   my $self = shift;

   my $sequence = shift;
   $sequence =~ s/[^gatcnGATCN]//g;
   return length $sequence;
}

1;

# create a new sequence object
my $seq_obj = MySequence->new();

my $sequence = 'gattccggatttccaaagggttcccaatttggg';
my $complement = $seq_obj->reversec($sequence);

print "original = $sequence\n";
print "complement = $complement\n";

if ($complement =~ /$EcoRI/) {
   print "Contains an EcoRI site.\n";
} else {
   print "Doesn't contain an EcoRI site.\n";
}