Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Concerning your code ... TL;DR ... sorry!


> This code is working. But I would be interested in your opinion. What could I do better?

dualvar means fiddling with internals, especially if you need to tie it with even more magic, too.

I'd reserve this approach for really hard to achieve stuff or temporary tricks (like for debugging)

IMHO using OOP together with overload for stringification and numification (see overload# String, numeric, boolean, and regexp conversions ) offers a much better interface and is easier to maintain. (untested!)

HTH! :)

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery FootballPerl is like chess, only without the dice


) see Cookbook section in overload for an example

# Two-face Scalars # Put this in in your Perl library directory: package two_face; # Scalars with separate string and # numeric values. sub new { my $p = shift; bless [@_], $p } use overload '""' => \&str, '0+' => \&num, fallback => 1; sub num {shift->[1]} sub str {shift->[0]} # Use it as follows: require two_face; my $seven = two_face->new("vii", 7); printf "seven=$seven, seven=%d, eight=%d\n", $seven, $seven+1; print "seven contains 'i'\n" if $seven =~ /i/; # (The second line creates a scalar which has both a string value, and + a numeric value.) This prints: seven=vii, seven=7, eight=8 seven contains 'i'

In reply to Re: Dualvar via table by LanX
in thread Dualvar via table by Dirk80

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others imbibing at the Monastery: (7)
    As of 2021-04-17 00:42 GMT
    Find Nodes?
      Voting Booth?

      No recent polls found