Re: String to Num (was Re: Numeric Literals (Summary))
[email protected] (Dave Storrs) Wed, 20 Nov 2002 11:01:56 -0800
| Newsgroups | perl.perl6.documentation |
|---|---|
| Message-ID | <[email protected]> |
Attributions getting confusing, so I have snipped and rewritten:
Dave Storrs writes:
> > Actually, this would be a good reason to have a function called
> > "literal" -- if it went both ways. So, I could do this:
> >
> > print literal(200+55):hex; # == print "0xff";
> > print literal("0xff)); # == print 255;
>
[email protected] wrote:
> why not str ?
>
> > print str( 200+55 :"format"=>"hex"); # == print "0xff";
> > print str("0xff"); # == print 255;
It's just a cognitive difference--in my example, literal() would
return a string if given a number and return a number if given a
string (in each case, the output would be precisely what you would get
had you written the input as a literal in the other format, hence the
'literal' name). In your example, str() does the same thing--but I
would suggest that a function named 'str' should always return a
string.
--Dks