Why use dd to convert a string to an integer?

Hi All,

I am confused.

This line will convert a string into an integer, but
will print out and extra line with "(Int)" on it:

    $ p6 'my Str $x = "5"; my Int $y = dd +$x; say $y'
    5
    (Int)


This will convert as well, but no extra line:

    $ p6 'my Int $x; my Str $y = "5"; $x = "$y" + 0; say $x'
    5


Also, I can quote $x, and it still works:

    $ p6 'my Int $x; my Str $y = "5"; $x = "$y" + 0; say "$x"'
    5


But this tells me I have an uninitialized value, when all
I did was add quotes around $y, as in the above line.

    $ p6 'my Str $x = "5"; my Int $y = dd +$x; say "$y";'
    5
    Use of uninitialized value $y of type Int in string context.
    Methods .^name, .perl, .gist, or .say can be used to stringify
    it to something meaningful.


Why would I want to use "dd"?

Many thanks,
-T
0
ToddAndMargo
8/7/2018 7:16:11 AM
perl.perl6.users 1089 articles. 0 followers. Follow

4 Replies
27 Views

Similar Articles

[PageSpeed] 23

--00000000000069d7670572d336c7
Content-Type: text/plain; charset="UTF-8"

dd is the moarvm specific data dump command. You don't need it.

On Tue, 7 Aug 2018, 08:16 ToddAndMargo, <ToddAndMargo@zoho.com> wrote:

> Hi All,
>
> I am confused.
>
> This line will convert a string into an integer, but
> will print out and extra line with "(Int)" on it:
>
>     $ p6 'my Str $x = "5"; my Int $y = dd +$x; say $y'
>     5
>     (Int)
>
>
> This will convert as well, but no extra line:
>
>     $ p6 'my Int $x; my Str $y = "5"; $x = "$y" + 0; say $x'
>     5
>
>
> Also, I can quote $x, and it still works:
>
>     $ p6 'my Int $x; my Str $y = "5"; $x = "$y" + 0; say "$x"'
>     5
>
>
> But this tells me I have an uninitialized value, when all
> I did was add quotes around $y, as in the above line.
>
>     $ p6 'my Str $x = "5"; my Int $y = dd +$x; say "$y";'
>     5
>     Use of uninitialized value $y of type Int in string context.
>     Methods .^name, .perl, .gist, or .say can be used to stringify
>     it to something meaningful.
>
>
> Why would I want to use "dd"?
>
> Many thanks,
> -T
>
-- 
Simon Proctor
Cognoscite aliquid novum cotidie

--00000000000069d7670572d336c7
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

dd is the moarvm specific data dump command. You don&#39;t need it.<br><br>=
<div class=3D"gmail_quote"><div dir=3D"ltr">On Tue, 7 Aug 2018, 08:16 ToddA=
ndMargo, &lt;<a href=3D"mailto:ToddAndMargo@zoho.com">ToddAndMargo@zoho.com=
</a>&gt; wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:=
0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi All,<br>
<br>
I am confused.<br>
<br>
This line will convert a string into an integer, but<br>
will print out and extra line with &quot;(Int)&quot; on it:<br>
<br>
=C2=A0 =C2=A0 $ p6 &#39;my Str $x =3D &quot;5&quot;; my Int $y =3D dd +$x; =
say $y&#39;<br>
=C2=A0 =C2=A0 5<br>
=C2=A0 =C2=A0 (Int)<br>
<br>
<br>
This will convert as well, but no extra line:<br>
<br>
=C2=A0 =C2=A0 $ p6 &#39;my Int $x; my Str $y =3D &quot;5&quot;; $x =3D &quo=
t;$y&quot; + 0; say $x&#39;<br>
=C2=A0 =C2=A0 5<br>
<br>
<br>
Also, I can quote $x, and it still works:<br>
<br>
=C2=A0 =C2=A0 $ p6 &#39;my Int $x; my Str $y =3D &quot;5&quot;; $x =3D &quo=
t;$y&quot; + 0; say &quot;$x&quot;&#39;<br>
=C2=A0 =C2=A0 5<br>
<br>
<br>
But this tells me I have an uninitialized value, when all<br>
I did was add quotes around $y, as in the above line.<br>
<br>
=C2=A0 =C2=A0 $ p6 &#39;my Str $x =3D &quot;5&quot;; my Int $y =3D dd +$x; =
say &quot;$y&quot;;&#39;<br>
=C2=A0 =C2=A0 5<br>
=C2=A0 =C2=A0 Use of uninitialized value $y of type Int in string context.<=
br>
=C2=A0 =C2=A0 Methods .^name, .perl, .gist, or .say can be used to stringif=
y<br>
=C2=A0 =C2=A0 it to something meaningful.<br>
<br>
<br>
Why would I want to use &quot;dd&quot;?<br>
<br>
Many thanks,<br>
-T<br>
</blockquote></div>-- <br><div dir=3D"ltr" class=3D"gmail_signature" data-s=
martmail=3D"gmail_signature"><div dir=3D"ltr"><font size=3D"-1"><font color=
=3D"#888888">Simon Proctor<br>
Cognoscite aliquid novum cotidie</font></font></div></div>

--00000000000069d7670572d336c7--
0
simon
8/7/2018 7:19:09 AM
>> On Tue, 7 Aug 2018, 08:16 ToddAndMargo, <ToddAndMargo@zoho.com 
>> <mailto:ToddAndMargo@zoho.com>> wrote:
>> 
>>     Hi All,
>> 
>>     I am confused.
>> 
>>     This line will convert a string into an integer, but
>>     will print out and extra line with "(Int)" on it:
>> 
>>          $ p6 'my Str $x = "5"; my Int $y = dd +$x; say $y'
>>          5
>>          (Int)
>> 
>> 
>>     This will convert as well, but no extra line:
>> 
>>          $ p6 'my Int $x; my Str $y = "5"; $x = "$y" + 0; say $x'
>>          5
>> 
>> 
>>     Also, I can quote $x, and it still works:
>> 
>>          $ p6 'my Int $x; my Str $y = "5"; $x = "$y" + 0; say "$x"'
>>          5
>> 
>> 
>>     But this tells me I have an uninitialized value, when all
>>     I did was add quotes around $y, as in the above line.
>> 
>>          $ p6 'my Str $x = "5"; my Int $y = dd +$x; say "$y";'
>>          5
>>          Use of uninitialized value $y of type Int in string context.
>>          Methods .^name, .perl, .gist, or .say can be used to stringify
>>          it to something meaningful.
>> 
>> 
>>     Why would I want to use "dd"?
>> 
>>     Many thanks,
>>     -T
>> 

On 08/07/2018 12:19 AM, Simon Proctor wrote:
> dd is the moarvm specific data dump command. You don't need it.
> 
> -- 
> Simon Proctor
> Cognoscite aliquid novum cotidie

Thank you!

What is "moarvm"
0
ToddAndMargo
8/7/2018 7:32:04 AM
--00000000000026daac0572d4f891
Content-Type: text/plain; charset="UTF-8"

Moarvm is the Perl6 Virtual Machine that is one of the targets Rakudo
compiles to (the JVM is another).

Basically at the moment when people talk about Perl6 that mostly mean Perl6
compiled with Rakudo running on MoarVM.

(As I understand it).

the dd bit was not in the example as part of string -> int conversion but
to demonstrate the result.

On Tue, 7 Aug 2018 at 08:32 ToddAndMargo <ToddAndMargo@zoho.com> wrote:

> >> On Tue, 7 Aug 2018, 08:16 ToddAndMargo, <ToddAndMargo@zoho.com
> >> <mailto:ToddAndMargo@zoho.com>> wrote:
> >>
> >>     Hi All,
> >>
> >>     I am confused.
> >>
> >>     This line will convert a string into an integer, but
> >>     will print out and extra line with "(Int)" on it:
> >>
> >>          $ p6 'my Str $x = "5"; my Int $y = dd +$x; say $y'
> >>          5
> >>          (Int)
> >>
> >>
> >>     This will convert as well, but no extra line:
> >>
> >>          $ p6 'my Int $x; my Str $y = "5"; $x = "$y" + 0; say $x'
> >>          5
> >>
> >>
> >>     Also, I can quote $x, and it still works:
> >>
> >>          $ p6 'my Int $x; my Str $y = "5"; $x = "$y" + 0; say "$x"'
> >>          5
> >>
> >>
> >>     But this tells me I have an uninitialized value, when all
> >>     I did was add quotes around $y, as in the above line.
> >>
> >>          $ p6 'my Str $x = "5"; my Int $y = dd +$x; say "$y";'
> >>          5
> >>          Use of uninitialized value $y of type Int in string context.
> >>          Methods .^name, .perl, .gist, or .say can be used to stringify
> >>          it to something meaningful.
> >>
> >>
> >>     Why would I want to use "dd"?
> >>
> >>     Many thanks,
> >>     -T
> >>
>
> On 08/07/2018 12:19 AM, Simon Proctor wrote:
> > dd is the moarvm specific data dump command. You don't need it.
> >
> > --
> > Simon Proctor
> > Cognoscite aliquid novum cotidie
>
> Thank you!
>
> What is "moarvm"
>
-- 
Simon Proctor
Cognoscite aliquid novum cotidie

--00000000000026daac0572d4f891
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>Moarvm is the Perl6 Virtual Machine that is one of th=
e targets Rakudo compiles to (the JVM is another).</div><div><br></div><div=
>Basically at the moment when people talk about Perl6 that mostly mean Perl=
6 compiled with Rakudo running on MoarVM. <br></div><div><br></div><div>(As=
 I understand it).</div><div><br></div><div>the dd bit was not in the examp=
le as part of string -&gt; int conversion but to demonstrate the result. <b=
r></div></div><br><div class=3D"gmail_quote"><div dir=3D"ltr">On Tue, 7 Aug=
 2018 at 08:32 ToddAndMargo &lt;<a href=3D"mailto:ToddAndMargo@zoho.com">To=
ddAndMargo@zoho.com</a>&gt; wrote:<br></div><blockquote class=3D"gmail_quot=
e" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">=
&gt;&gt; On Tue, 7 Aug 2018, 08:16 ToddAndMargo, &lt;<a href=3D"mailto:Todd=
AndMargo@zoho.com" target=3D"_blank">ToddAndMargo@zoho.com</a> <br>
&gt;&gt; &lt;mailto:<a href=3D"mailto:ToddAndMargo@zoho.com" target=3D"_bla=
nk">ToddAndMargo@zoho.com</a>&gt;&gt; wrote:<br>
&gt;&gt; <br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0Hi All,<br>
&gt;&gt; <br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0I am confused.<br>
&gt;&gt; <br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0This line will convert a string into an integer=
, but<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0will print out and extra line with &quot;(Int)&=
quot; on it:<br>
&gt;&gt; <br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 $ p6 &#39;my Str $x =3D &quot;5&=
quot;; my Int $y =3D dd +$x; say $y&#39;<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 5<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (Int)<br>
&gt;&gt; <br>
&gt;&gt; <br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0This will convert as well, but no extra line:<b=
r>
&gt;&gt; <br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 $ p6 &#39;my Int $x; my Str $y =
=3D &quot;5&quot;; $x =3D &quot;$y&quot; + 0; say $x&#39;<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 5<br>
&gt;&gt; <br>
&gt;&gt; <br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0Also, I can quote $x, and it still works:<br>
&gt;&gt; <br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 $ p6 &#39;my Int $x; my Str $y =
=3D &quot;5&quot;; $x =3D &quot;$y&quot; + 0; say &quot;$x&quot;&#39;<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 5<br>
&gt;&gt; <br>
&gt;&gt; <br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0But this tells me I have an uninitialized value=
, when all<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0I did was add quotes around $y, as in the above=
 line.<br>
&gt;&gt; <br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 $ p6 &#39;my Str $x =3D &quot;5&=
quot;; my Int $y =3D dd +$x; say &quot;$y&quot;;&#39;<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 5<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Use of uninitialized value $y of=
 type Int in string context.<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Methods .^name, .perl, .gist, or=
 .say can be used to stringify<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 it to something meaningful.<br>
&gt;&gt; <br>
&gt;&gt; <br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0Why would I want to use &quot;dd&quot;?<br>
&gt;&gt; <br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0Many thanks,<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0-T<br>
&gt;&gt; <br>
<br>
On 08/07/2018 12:19 AM, Simon Proctor wrote:<br>
&gt; dd is the moarvm specific data dump command. You don&#39;t need it.<br=
>
&gt; <br>
&gt; -- <br>
&gt; Simon Proctor<br>
&gt; Cognoscite aliquid novum cotidie<br>
<br>
Thank you!<br>
<br>
What is &quot;moarvm&quot;<br>
</blockquote></div>-- <br><div dir=3D"ltr" class=3D"gmail_signature" data-s=
martmail=3D"gmail_signature"><div dir=3D"ltr"><font size=3D"-1"><font color=
=3D"#888888">Simon Proctor<br>
Cognoscite aliquid novum cotidie</font></font></div></div>

--00000000000026daac0572d4f891--
0
simon
8/7/2018 9:24:54 AM
On 08/07/2018 02:24 AM, Simon Proctor wrote:
> Moarvm is the Perl6 Virtual Machine that is one of the targets Rakudo 
> compiles to (the JVM is another).
> 
> Basically at the moment when people talk about Perl6 that mostly mean 
> Perl6 compiled with Rakudo running on MoarVM.
> 
> (As I understand it).
> 
> the dd bit was not in the example as part of string -> int conversion 
> but to demonstrate the result.

Thank you!
0
ToddAndMargo
8/7/2018 9:40:44 AM
Reply: