Perl Monk, Perl Meditation | |
PerlMonks |
Re: Class / package weak associationby cavac (Parson) |
on Jun 08, 2021 at 10:57 UTC ( [id://11133652]=note: print w/replies, xml ) | Need Help?? |
If you think that Perl has not a most generic approach to objects, you'd probably haven't looked into the "huh, this is possible?" corner enough. Take a look at this:
This blesses a scalar, an array and a hash with a class that we didn't even create beforehand. AFTER it does that, it modifies the class and adds a "stringify" method, which in turn modifies all the objects of that class. Then we stringify all objects with this newly created method. Result:
If that is not generic and flexible, i don't know what is. SCNR
perl -e 'use Crypt::Digest::SHA256 qw[sha256_hex]; print substr(sha256_hex("the Answer To Life, The Universe And Everything"), 6, 2), "\n";'
In Section
Meditations
|
|