{"id":18728306,"url":"https://github.com/worthmine/arraytest","last_synced_at":"2025-06-29T00:35:04.966Z","repository":{"id":89224329,"uuid":"104747487","full_name":"worthmine/ArrayTest","owner":"worthmine","description":"Is it a bug on CORE::scalar?","archived":false,"fork":false,"pushed_at":"2017-09-27T05:41:27.000Z","size":40,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-19T20:31:48.913Z","etag":null,"topics":["array","perl","scalar"],"latest_commit_sha":null,"homepage":null,"language":"Perl","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/worthmine.png","metadata":{"files":{"readme":"README.md","changelog":"Changes","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-09-25T12:33:03.000Z","updated_at":"2023-03-05T00:12:10.000Z","dependencies_parsed_at":"2023-06-14T12:00:36.552Z","dependency_job_id":null,"html_url":"https://github.com/worthmine/ArrayTest","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/worthmine/ArrayTest","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/worthmine%2FArrayTest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/worthmine%2FArrayTest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/worthmine%2FArrayTest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/worthmine%2FArrayTest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/worthmine","download_url":"https://codeload.github.com/worthmine/ArrayTest/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/worthmine%2FArrayTest/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262518105,"owners_count":23323301,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["array","perl","scalar"],"created_at":"2024-11-07T14:20:32.230Z","updated_at":"2025-06-29T00:35:04.958Z","avatar_url":"https://github.com/worthmine.png","language":"Perl","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NAME\n\nArrayTest - perl CORE::scaler has strange specifications\n\n# SYNOPSIS\n\n`perl t/00_compile.t` will never succeed. Why not?\n\n# DESCRIPTION\n\nI wonder why do these tests fail.\n\n## what's the matter?\n\n`diff lib/ArrayTest.pm lib/ArrayTest2.pm` without POD is below:\n\n    1c1\n    \u003c package ArrayTest;\n    ---\n    \u003e package ArrayTest2;\n    16c16\n    \u003c     my @list = ( $self-\u003ezero(), @{ $self-\u003enum() } );\n    ---\n    \u003e     ( $self-\u003ezero(), @{ $self-\u003enum() } );\n\nThe joined value with ' ' is same,\nAnd trying to `note explain` succeeded, I got 10 references.\n\nSo there must be 10 references in what these return.\nBut CORE::scalar() returns 9 with ArrayTest2.pm.\n\nIt was too strange for me.\n\n## But it's the specifications\n\nAccording to [perldoc](http://perldoc.perl.org/perlop.html#Comma-Operator),\n\n    Comma Operator\n\n    Binary \",\" is the comma operator. In scalar context it evaluates its left\n    argument, throws that value away, then evaluates its right argument and\n    returns that value.\n    This is just like C's comma operator. In list context, it's just the list\n    argument separator, and inserts both its arguments into the list.\n    These arguments are also evaluated from left to right.\n\nnamely, `( $self-\u003ezero(), @{ $self-\u003enum() } )` and ifever, `return ( $self-\u003ezero(), @{ $self-\u003enum() } )` mean below:\n\n    $self-\u003ezero();\n    @{ $self-\u003enum() };\n\nSo they return only `@{ $self-\u003enum() }` **in scalar context**\n\nTo tell the truth, Moose is irrelevant. To say simply,\n\n    my $zero = 0;\n    my $num = [1..9];\n\n    sub list {\n       return( $zero, @$num );\n    }\n    \n    my ($x) = list();\n    my $y = scalar list();\n\nUnder the above, by perl's specifications, $x is 0(the first value of the list)\nand $y is 9(counting @$num), NOT 10! This is contrary to intuition!\n\nAnd to say more simply, `sub{}` is also irrelevant.\nIt's specification of `CORE::scalar`\n\n    my $zero = 0;\n    my $num = [1..9];\n\n    my ($x) = ( $zero, @$num );     # is 0\n    my $y = scalar( $zero, @$num ); # is 9\n\nI heard It's the specification affected from C.\nBut I think **it's almost bug**\n\n## how to avoid them\n\nJust use an Array, the Anonymous array or `map` like below:\n\n- by using a named Array\n\n        my @return = $self-\u003ezero(), @{ $self-\u003enum() };\n\n- by using an Anonymous Array\n\n        @{ [ $self-\u003ezero(), @{ $self-\u003enum() } ] };\n\n- by using `map`\n\n        map {$_} $self-\u003ezero(), @{ $self-\u003enum() };\n\n# SEE ALSO\n\n- [Why do I get the last value in a list in scalar context in perl? - stackoverflow](https://stackoverflow.com/questions/19689393/why-do-i-get-the-last-value-in-a-list-in-scalar-context-in-perl?newreg=b76291905c824a95a0fabaf5a539d0e0)\n- [Comma-Operator in perlop](http://perldoc.perl.org/perlop.html#Comma-Operator)\n- [日本語の記事を作成しました](https://qiita.com/worthmine/items/a632d124516743950c21)\n\n# LICENSE\n\nCopyright (C) Yuki Yoshida.\n\nThis library is free software; you can redistribute it and/or modify\nit under the same terms as Perl itself.\n\n# AUTHOR\n\nYuki Yoshida(worthmine) \u003cworthmine@gmail.com\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fworthmine%2Farraytest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fworthmine%2Farraytest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fworthmine%2Farraytest/lists"}