develooper Front page | perl.perl6.language | Postings from June 2001

Re: Coupla Questions

Thread Previous | Thread Next
From:
Damian Conway
Date:
June 6, 2001 13:08
Subject:
Re: Coupla Questions
Message ID:
200106062008.GAA44594@indy05.csse.monash.edu.au
   > Should properties interpolate in regular expressions? (and/or strings)

Do you mean property look-ups via the pseudo-method syntax?
In that case, yes they should


   > I don't suppose they should, because we don't expect subroutines to. 
   > (if $foo =~ /bar($baz,$quux)/;? Urgh, maybe we need m//e)

Err. I *would* expect sub call iterpolation in regexes, since they will
interpolate in qq{...} contexts, and that's what a regex basically is.

But what you showed is not the syntax for it:

     /bar($baz,$quux)/;		# match bar then match-and capture
				# matches of interpolated value of $baz,
				# a comma, interpolated value of $quux

     /&bar($baz,$quux)/;	# match interpolated value of call to
				# bar with two args


   > What should $foo = (1,2,3) do now? Should it be the same as what 
   > $foo = [1,2,3]; did in Perl 6? (This is assuming that $foo=@INC does what
   > $foo = \@INC; does now.) Putting it another way: does a list in scalar
   > context turn into a reference, or is it just arrays that do that?

Just arrays, I believe.
   
   > Currently I have:
   > 
   > % ./perl -l 
   >     printf "This is Perl version %vd\n", $^V; 
   >     %foo = (test=>"ok 1", test2=>"ok 3"); 
   >     print %foo{test}; 

Yes

   >     print "ok 2" if ref ($a=%foo); 

Yes. Though C<ref($a=%foo) eq 'HASH'> would be a better test

   >     print $a->{test2}; 

die "Unexpected > after subtraction operation. Did you mean $a.{test2}???"

   >     print "ok 4" if ref @INC; 

Yes

   >     print "ok 5" unless ref ($a=(1,2,3))'

No. Equivalent to ref($a=3), I believe

   > Does that look right?

60% right, at least. ;-)

 
   > >     print $a->{test2}; 
   > 
   > Oh, hrm. Shouldn't it be $a{test2}?

Yes. Or $a.{test}
   
   > That works too, at any rate.
   > Does that mean that arrow between variable and subscript is optional,

<Zuul voice>There is no arrow. Only dot.</Zuul voice>

And yes, it's optional anywhere the dot acts like a /\b/ boundary:

        $ref.[1]        can be          $ref[1]
        $ref.{a}        can be          $ref{a}
        $ref.(@args)    can be          $ref(@args)
        $ref.meth()     CAN'T be        $refmeth()


Disclaimer: Rules #1 and #2 apply to all of the above.

Damian

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