Skip to content
This repository has been archived by the owner on Jan 9, 2024. It is now read-only.

Perl scalar annotations #2

Closed
makafre opened this issue Jul 30, 2018 · 3 comments
Closed

Perl scalar annotations #2

makafre opened this issue Jul 30, 2018 · 3 comments

Comments

@makafre
Copy link

makafre commented Jul 30, 2018

Hello,
I noticed that the Perl code gives an error when ran so I am putting the corrected version here:

    while ((scalar @hashes) > 1) {
            my @joinedHashes;
            while (my @pair = splice @hashes, 0, 2) {
                    push @joinedHashes, $pair[1] ? (sha256_hex @pair) : $pair[0];
            }
            @hashes = @joinedHashes;
    }
    $dailyhash = $hashes[0];

The issue is that it was using @pair[1] instead of $pair[1] , etc.
Otherwise , it works well, thanks for sharing this algo.
-m

@lukechampine
Copy link
Owner

Interesting. I don't get an error, and both versions produce the same result. I'm using Perl v5.22.1. Can you provide more information about how to reproduce the error?

@makafre
Copy link
Author

makafre commented Jul 30, 2018

To reproduce it just add the following two lines:

use warnings;
use strict;

..since they were not there Perl loosely accepted the code without complaining :)
Here are the errors when present:

perl -c ./test.pl
Scalar value @pair[1] better written as $pair[1] at ./test.pl line 20.
Scalar value @pair[0] better written as $pair[0] at ./test.pl line 20.
Scalar value @Hashes[0] better written as $hashes[0] at ./test.pl line 24.
Global symbol "$segment" requires explicit package name at ./test.pl line 12.
Global symbol "$segment" requires explicit package name at ./test.pl line 13.
./test.pl had compilation errors.

Cheers

-m

@lukechampine
Copy link
Owner

ah, good old Perl. Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants