develooper Front page | perl.perl6.users | Postings from December 2018

Exactly what is type match?

Thread Next
From:
ToddAndMargo via perl6-users
Date:
December 20, 2018 20:42
Subject:
Exactly what is type match?
Message ID:
ce293dd5-5b6c-d8da-e75c-2ef326fefdc4@zoho.com
Hi All,

Exactly what is type "Match"?

Here I want $D0..$D3 to only be strings.  And it throws a match error.

$ p6 'my $x="11.2.3.4"; my Str $D0; my Str $D1; my Str $D2; my Str $D3; 
$x~~m{ (<:N>) [.] (\d+) [.] (\d+) [.] (\d+) }; $D0 = $0; $D1 = $1; $D2 = 
$2; $D3 = $3; print "$D0 $D1 $D2 $D3\n";'

Type check failed in assignment to $D0; expected Str but got Match 
(Match.new(from => 1, made ...)
   in block <unit> at -e line 1

Here is my work around:

$ p6 'my $x="11.2.3.4"; my Str $D0; my Str $D1; my Str $D2; my Str $D3; 
$x~~m{ (<:N>+) [.] (\d+) [.] (\d+) [.] (\d+) }; $D0 = $0.Str; $D1 = 
$1.Str; $D2 = $2.Str; $D3 = $3.Str; print "$D0 $D1 $D2 $D3\n";'
11 2 3 4


Many thanks,
-T

-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
A computer without Microsoft is like
a chocolate cake without the mustard
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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