develooper Front page | perl.perl6.users | Postings from July 2017

Why is my class rejecting new()?

Thread Next
From:
Mark Carter
Date:
July 20, 2017 09:51
Subject:
Why is my class rejecting new()?
Message ID:
cef03c2e-2a9e-ee1d-9938-7bf9a8ac2b6a@gmail.com
I have a class definition:

class Etran {
         has $.dstamp is rw;
         has $.folio is rw;
         has $.ticker is rw;
         has $.qty is rw;
         has $.amount is rw;
         has $.desc is rw;

         method new($line) {
                 my ($cmd, $dstamp, $folio, $ticker, $qty, $amount, $way, $desc) = shlex-fields $line;
                 $!dstamp = $dstamp;
                 $!folio = $folio;
                 $!ticker = $ticker;
                 $!qty = $way == "B" ?? $qty !! - $qty;
                 $!amount = $amount;
                 $!desc = $desc;
         }

}**
which I instantiate with
	my $e = Etran.new($line);

However, it gives an error message:
	Cannot look up attributes in a Etran type object
at the line
	$!dstamp = $dstamp;

Why that, and how do I fix it?

Also, I don't really understand the difference between using the twigils "." and using "!",
and have yet to see an explanation that I understand.


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About