develooper Front page | perl.perl6.language | Postings from March 2005

using Rules with undefined values (was Re: some misc Perl 6questions)

Thread Previous | Thread Next
Darren Duncan
March 9, 2005 15:46
using Rules with undefined values (was Re: some misc Perl 6questions)
Message ID:
At 9:08 AM -0800 3/9/05, Larry Wall wrote:
>My other quibble is that you seem to be prone to stating things in the
>negative for at least two of your three tests here:
>     subtype KeyName of Str where { $_.defined and $_ ne '' and $_ !~ m/\W/ }
>and it seems to me that you could simplify all that to just
>     subtype KeyName of Str where { m/^\w+$/ }
>If that succeeds, you know it's defined and non-null.  You might argue that
>the m/\W/ short-circuits, but I would counter-argue that failure is
>supposed to be the exceptional case, and in every successful call you have
>to scan the whole string anyway.  Plus it's just easier to understand.
>And it lets you write the constraint without explicit reference to $_,
>which I will admit was my first motivation in wanting to rewrite your
>constraint.  The negatives and redundancies I only noticed later.

Okay, I have gone and replaced the "$_ ne '' and $_ !~ m/\W/" with a 

However, unless Perl 6 is different than Perl 5 in its treatment of 
undefined values, I still need the ".defined" part, meaning I end up 

   subtype KeyName of Str where { .defined and m/^\w+$/ }

In Perl 5, running something like the un-gated "$msg_key =~ m/^\w+$/" 
gives this warning:

   Use of uninitialized value in pattern match (m//) at 
Locale/ line 85.

To avoid that, I do "defined( $msg_key ) and $msg_key =~ m/^\w+$/" in Perl 5.

You have mentioned before that Perl 6 still treats the use of 
undefined values other than in boolean context as an error.  So would 
applying a Rule against an undefined value produce a warning in Perl 
6 or not?  (A quick scan of S12 didn't say.)

-- Darren Duncan

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About