Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
There's more than one way to do things
 
PerlMonks  

Buggy smartmatch on tied array?

by CardinalNumber (Prior)
on Oct 05, 2013 at 16:13 UTC ( #1057045=perlquestion: print w/ replies, xml ) Need Help??
CardinalNumber has asked for the wisdom of the Perl Monks concerning the following question:

Still working through old reported issues and think I have another upstream bug. Take this:

use Tie::Array; tie my @array_t, 'Tie::StdArray'; my @array = @array_t = qw[aaa bbb ccc ddd eee]; print "plain smatch: " . (/a/ ~~ @array) . "\n"; print "plain grep: " . (grep {/a/} @array) . "\n"; print "tied smatch: " . (/a/ ~~ @array_t) . "\n"; print "tied grep: " . (grep {/a/} @array_t) . "\n";

When run on my v5.16.3 install, the smartmatch doesn't correctly match against the magically tied @array_t. Devel::Trace shows that it calls the array's FETCHSIZE method just like the tied grep but never bothers to FETCH the correct values. So, I end up with output that looks like:

Use of uninitialized value in pattern match (m//) at bugs.t line 6. Use of uninitialized value in pattern match (m//) at bugs.t line 6. Use of uninitialized value in pattern match (m//) at bugs.t line 6. Use of uninitialized value in pattern match (m//) at bugs.t line 6. Use of uninitialized value in pattern match (m//) at bugs.t line 6. plain smatch: 1 plain grep: 1 tied smatch: tied grep: 1

The warnings are obviously from smartmatch trying to match against undefined values. Can anyone verify that I'm not 'doing it wrong' before I submit a bug report to p5p?

Update: Reported as RT#120122.

Comment on Buggy smartmatch on tied array?
Select or Download Code
Re: Buggy smartmatch on tied array?
by davido (Archbishop) on Oct 05, 2013 at 16:42 UTC

    I can at least verify that it's an issue on 5.18. And the code looks reasonable to me. Of course on 5.18 I also get:

    Smartmatch is experimental at ./mytest.pl line 4. Smartmatch is experimental at ./mytest.pl line 6.

    You might search the bug queue for issues related to smartmatch to see if it's already been reported. If not, go for it. I think the operator is in a state of flux, but it would be a shame for little things like this to not get fixed if the operator ever has its experimental designation removed again.


    Dave

      It's probably a trivial thing to fix, and it will be. Smart match is experimental because it has major design issues.
Re: Buggy smartmatch on tied array?
by kcott (Abbot) on Oct 05, 2013 at 18:00 UTC

    G'day CardinalNumber,

    On 5.18.1 (current version):

    $ cat junk #!/usr/bin/env perl use strict; use warnings; no if $] >= 5.018, warnings => 'experimental::smartmatch'; use Tie::Array; tie my @array_t, 'Tie::StdArray'; my @array = @array_t = qw[aaa bbb ccc ddd eee]; print "plain smatch: " . (/a/ ~~ @array) . "\n"; print "plain grep: " . (grep {/a/} @array) . "\n"; print "tied smatch: " . (/a/ ~~ @array_t) . "\n"; print "tied grep: " . (grep {/a/} @array_t) . "\n";
    $ junk plain smatch: 1 plain grep: 1 Use of uninitialized value in pattern match (m//) at ./junk line 12. Use of uninitialized value in pattern match (m//) at ./junk line 12. Use of uninitialized value in pattern match (m//) at ./junk line 12. Use of uninitialized value in pattern match (m//) at ./junk line 12. Use of uninitialized value in pattern match (m//) at ./junk line 12. tied smatch: tied grep: 1

    -- Ken

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1057045]
Approved by NetWallah
Front-paged by NetWallah
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2014-04-19 23:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (485 votes), past polls