develooper Front page | perl.perl6.users | Postings from October 2021

Re: how do I turn a real into and array of Integers?

Thread Previous | Thread Next
From:
Alice
Date:
October 31, 2021 07:14
Subject:
Re: how do I turn a real into and array of Integers?
Message ID:
CALUE4B+Qoi+Gk-i0ArhKDYhh9hhTjQTrjvt2WHY0=MvB6sRhjg@mail.gmail.com
--0000000000000a17ba05cfa0cfe9
Content-Type: text/plain; charset="UTF-8"

Hello

Try this one:

use strict;

use Data::Dumper;


my $x = sqrt 2;

my @li= grep{/\d+/} split//,$x;


print Dumper \@li;



$ perl t1.pl

$VAR1 = [

          '1',

          '4',

          '1',

          '4',

          '2',

          '1',

          '3',

          '5',

          '6',

          '2',

          '3',

          '7',

          '3',

          '1'

        ];


Regards

Alice

On Sun, Oct 31, 2021 at 2:58 PM ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> Hi All,
>
> Without going into why (it is a secret), how do I turn
>
>  > my $x = sqrt 2
> 1.4142135623730951
>
> into an array of integers?
> @y[0] = 1
> @y[1] = 4
> @y[2] = 1
> @y[3] = 4
> @y[4] = 2
> @y[5] = 1
>
> etc.
>
>
> Many thanks,
> -T
>
>
>

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

<div dir=3D"ltr">Hello<div><br></div><div>Try this one:</div><div><br></div=
><div>





<p class=3D"gmail-p1" style=3D"margin:0px;font-variant-numeric:normal;font-=
variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:no=
rmal;font-family:Menlo;color:rgb(0,0,0)"><span class=3D"gmail-s1" style=3D"=
font-variant-ligatures:no-common-ligatures">use strict;</span></p>
<p class=3D"gmail-p1" style=3D"margin:0px;font-variant-numeric:normal;font-=
variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:no=
rmal;font-family:Menlo;color:rgb(0,0,0)"><span class=3D"gmail-s1" style=3D"=
font-variant-ligatures:no-common-ligatures">use Data::Dumper;</span></p>
<p class=3D"gmail-p2" style=3D"margin:0px;font-variant-numeric:normal;font-=
variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:no=
rmal;font-family:Menlo;color:rgb(0,0,0);min-height:13px"><span class=3D"gma=
il-s1" style=3D"font-variant-ligatures:no-common-ligatures"></span><br></p>
<p class=3D"gmail-p1" style=3D"margin:0px;font-variant-numeric:normal;font-=
variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:no=
rmal;font-family:Menlo;color:rgb(0,0,0)"><span class=3D"gmail-s1" style=3D"=
font-variant-ligatures:no-common-ligatures">my $x =3D sqrt 2;</span></p>
<p class=3D"gmail-p1" style=3D"margin:0px;font-variant-numeric:normal;font-=
variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:no=
rmal;font-family:Menlo;color:rgb(0,0,0)"><span class=3D"gmail-s1" style=3D"=
font-variant-ligatures:no-common-ligatures">my @li=3D grep{/\d+/} split//,$=
x;</span></p>
<p class=3D"gmail-p2" style=3D"margin:0px;font-variant-numeric:normal;font-=
variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:no=
rmal;font-family:Menlo;color:rgb(0,0,0);min-height:13px"><span class=3D"gma=
il-s1" style=3D"font-variant-ligatures:no-common-ligatures"></span><br></p>
<p class=3D"gmail-p1" style=3D"margin:0px;font-variant-numeric:normal;font-=
variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:no=
rmal;font-family:Menlo;color:rgb(0,0,0)"><span class=3D"gmail-s1" style=3D"=
font-variant-ligatures:no-common-ligatures">print Dumper \@li;</span></p><p=
 class=3D"gmail-p1" style=3D"margin:0px;font-variant-numeric:normal;font-va=
riant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:norm=
al;font-family:Menlo;color:rgb(0,0,0)"><span class=3D"gmail-s1" style=3D"fo=
nt-variant-ligatures:no-common-ligatures"><br></span></p><p class=3D"gmail-=
p1" style=3D"margin:0px;font-variant-numeric:normal;font-variant-east-asian=
:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:M=
enlo;color:rgb(0,0,0)"><span class=3D"gmail-s1" style=3D"font-variant-ligat=
ures:no-common-ligatures"><br></span></p><p class=3D"gmail-p1" style=3D"mar=
gin:0px;font:11px Menlo;color:rgb(0,0,0)"><span class=3D"gmail-s1" style=3D=
"font-variant-ligatures:no-common-ligatures">$ perl <a href=3D"http://t1.pl=
">t1.pl</a><span class=3D"gmail-Apple-converted-space">=C2=A0</span></span>=
</p><p class=3D"gmail-p1" style=3D"margin:0px;font:11px Menlo;color:rgb(0,0=
,0)"><span class=3D"gmail-s1" style=3D"font-variant-ligatures:no-common-lig=
atures">$VAR1 =3D [</span></p><p class=3D"gmail-p1" style=3D"margin:0px;fon=
t:11px Menlo;color:rgb(0,0,0)"><span class=3D"gmail-s1" style=3D"font-varia=
nt-ligatures:no-common-ligatures"><span class=3D"gmail-Apple-converted-spac=
e">=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 </span>&#39;1&#39;,</span></p><p clas=
s=3D"gmail-p1" style=3D"margin:0px;font:11px Menlo;color:rgb(0,0,0)"><span =
class=3D"gmail-s1" style=3D"font-variant-ligatures:no-common-ligatures"><sp=
an class=3D"gmail-Apple-converted-space">=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
 </span>&#39;4&#39;,</span></p><p class=3D"gmail-p1" style=3D"margin:0px;fo=
nt:11px Menlo;color:rgb(0,0,0)"><span class=3D"gmail-s1" style=3D"font-vari=
ant-ligatures:no-common-ligatures"><span class=3D"gmail-Apple-converted-spa=
ce">=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 </span>&#39;1&#39;,</span></p><p cla=
ss=3D"gmail-p1" style=3D"margin:0px;font:11px Menlo;color:rgb(0,0,0)"><span=
 class=3D"gmail-s1" style=3D"font-variant-ligatures:no-common-ligatures"><s=
pan class=3D"gmail-Apple-converted-space">=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 </span>&#39;4&#39;,</span></p><p class=3D"gmail-p1" style=3D"margin:0px=
;font:11px Menlo;color:rgb(0,0,0)"><span class=3D"gmail-s1" style=3D"font-v=
ariant-ligatures:no-common-ligatures"><span class=3D"gmail-Apple-converted-=
space">=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 </span>&#39;2&#39;,</span></p><p =
class=3D"gmail-p1" style=3D"margin:0px;font:11px Menlo;color:rgb(0,0,0)"><s=
pan class=3D"gmail-s1" style=3D"font-variant-ligatures:no-common-ligatures"=
><span class=3D"gmail-Apple-converted-space">=C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 </span>&#39;1&#39;,</span></p><p class=3D"gmail-p1" style=3D"margin:=
0px;font:11px Menlo;color:rgb(0,0,0)"><span class=3D"gmail-s1" style=3D"fon=
t-variant-ligatures:no-common-ligatures"><span class=3D"gmail-Apple-convert=
ed-space">=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 </span>&#39;3&#39;,</span></p>=
<p class=3D"gmail-p1" style=3D"margin:0px;font:11px Menlo;color:rgb(0,0,0)"=
><span class=3D"gmail-s1" style=3D"font-variant-ligatures:no-common-ligatur=
es"><span class=3D"gmail-Apple-converted-space">=C2=A0 =C2=A0 =C2=A0 =C2=A0=
 =C2=A0 </span>&#39;5&#39;,</span></p><p class=3D"gmail-p1" style=3D"margin=
:0px;font:11px Menlo;color:rgb(0,0,0)"><span class=3D"gmail-s1" style=3D"fo=
nt-variant-ligatures:no-common-ligatures"><span class=3D"gmail-Apple-conver=
ted-space">=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 </span>&#39;6&#39;,</span></p=
><p class=3D"gmail-p1" style=3D"margin:0px;font:11px Menlo;color:rgb(0,0,0)=
"><span class=3D"gmail-s1" style=3D"font-variant-ligatures:no-common-ligatu=
res"><span class=3D"gmail-Apple-converted-space">=C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 </span>&#39;2&#39;,</span></p><p class=3D"gmail-p1" style=3D"mar=
gin:0px;font:11px Menlo;color:rgb(0,0,0)"><span class=3D"gmail-s1" style=3D=
"font-variant-ligatures:no-common-ligatures"><span class=3D"gmail-Apple-con=
verted-space">=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 </span>&#39;3&#39;,</span>=
</p><p class=3D"gmail-p1" style=3D"margin:0px;font:11px Menlo;color:rgb(0,0=
,0)"><span class=3D"gmail-s1" style=3D"font-variant-ligatures:no-common-lig=
atures"><span class=3D"gmail-Apple-converted-space">=C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 </span>&#39;7&#39;,</span></p><p class=3D"gmail-p1" style=3D"=
margin:0px;font:11px Menlo;color:rgb(0,0,0)"><span class=3D"gmail-s1" style=
=3D"font-variant-ligatures:no-common-ligatures"><span class=3D"gmail-Apple-=
converted-space">=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 </span>&#39;3&#39;,</sp=
an></p><p class=3D"gmail-p1" style=3D"margin:0px;font:11px Menlo;color:rgb(=
0,0,0)"><span class=3D"gmail-s1" style=3D"font-variant-ligatures:no-common-=
ligatures"><span class=3D"gmail-Apple-converted-space">=C2=A0 =C2=A0 =C2=A0=
 =C2=A0 =C2=A0 </span>&#39;1&#39;</span></p><p class=3D"gmail-p1" style=3D"=
margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-=
stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rg=
b(0,0,0)"><span class=3D"gmail-s1" style=3D"font-variant-ligatures:no-commo=
n-ligatures">





















</span></p><p class=3D"gmail-p1" style=3D"margin:0px;font-variant-numeric:n=
ormal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;lin=
e-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span class=3D"gmail-s1=
" style=3D"font-variant-ligatures:no-common-ligatures"><span class=3D"gmail=
-Apple-converted-space">=C2=A0 =C2=A0 =C2=A0 =C2=A0=C2=A0</span>];</span></=
p><p class=3D"gmail-p1" style=3D"margin:0px;font-variant-numeric:normal;fon=
t-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:=
normal;font-family:Menlo;color:rgb(0,0,0)"><span class=3D"gmail-s1" style=
=3D"font-variant-ligatures:no-common-ligatures"><br></span></p><p class=3D"=
gmail-p1" style=3D"margin:0px;font-variant-numeric:normal;font-variant-east=
-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-fa=
mily:Menlo;color:rgb(0,0,0)"><span class=3D"gmail-s1" style=3D"font-variant=
-ligatures:no-common-ligatures">Regards</span></p><p class=3D"gmail-p1" sty=
le=3D"margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal=
;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;co=
lor:rgb(0,0,0)"><span class=3D"gmail-s1" style=3D"font-variant-ligatures:no=
-common-ligatures">Alice</span></p></div></div><br><div class=3D"gmail_quot=
e"><div dir=3D"ltr" class=3D"gmail_attr">On Sun, Oct 31, 2021 at 2:58 PM To=
ddAndMargo via perl6-users &lt;<a href=3D"mailto:perl6-users@perl.org">perl=
6-users@perl.org</a>&gt; wrote:<br></div><blockquote class=3D"gmail_quote" =
style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);pa=
dding-left:1ex">Hi All,<br>
<br>
Without going into why (it is a secret), how do I turn<br>
<br>
=C2=A0&gt; my $x =3D sqrt 2<br>
1.4142135623730951<br>
<br>
into an array of integers?<br>
@y[0] =3D 1<br>
@y[1] =3D 4<br>
@y[2] =3D 1<br>
@y[3] =3D 4<br>
@y[4] =3D 2<br>
@y[5] =3D 1<br>
<br>
etc.<br>
<br>
<br>
Many thanks,<br>
-T<br>
<br>
<br>
</blockquote></div>

--0000000000000a17ba05cfa0cfe9--

Thread Previous | 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