bigup401 has asked for the wisdom of the Perl Monks concerning the following question:

am really confused the script removes first 4 digits

Bareword found where operator expected at 11.pl line 17, near 1586iY2v +SfT5EeuQTMYj6kwnbfN255KX2T <Missing operator before iY2vSfT5EeuQTMYj6kwnbfN255KX2T?> syntax error at 11.pl line 17 near, "1586iY2vSfT5EeuQTMYj6kwnbfN255KX2 +T"
my $req = HTTP::Request->new(GET => 'https://blockchain.info/balance?a +ctive=1586iY2vSfT5EeuQTMYj6kwnbfN255KX2T'); $req->content_type('application/json'); my $res = $ua->request($req); $respns = JSON::XS->new->decode ($res->content); $k= $respns->{1586iY2vSfT5EeuQTMYj6kwnbfN255KX2T}->{n_tx}; print $k;

Replies are listed 'Best First'.
Re: syntax error
by Corion (Patriarch) on Jun 20, 2017 at 15:03 UTC

    You get a syntax error from Perl because 1586iY2vSfT5EeuQTMYj6kwnbfN255KX2T is not a hash key you can use unquoted. That's why Perl says it found a "bareword".

    Quote your hash key and the error goes away.

      I never realized that auto-quoting of keys depends on identifier rules.

      Identifiers are not allowed to start with digits, like it's not allowed to call a

      sub 1586i { ... }

      UPDATE:

      though it's possible to have a pure digit key (?)

      DB<113> p $h{1586}++ 1 DB<114> p $h{1586}++ 2

      strange ...

      Update

      so I couldn't find it documented, but the rule seems to be:

      In order to autoquote a hash key it has to be a legal identifier or a number.

      in this case the number is found and Perl thinks an operator is missing to separate it from the bareword.

      from perlglossary

      identifier

      A legally formed name for most anything in which a computer program might be interested. Many languages (including Perl) allow identifiers to start with an alphabetic character, and then contain alphabetics and digits. Perl also allows connector punctuation like the underscore character wherever it allows alphabetics. (Perl also has more complicated names, like qualified names.)

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)
      Je suis Charlie!

        See my post here for a lot of examples and explanation :-) In short, from perldata:

        ... a simple identifier within such curlies is forced to be a string, and likewise within a hash subscript. Neither need quoting. ... This means for example that $version{2.0}++ is equivalent to $version{2}++, not to $version{'2.0'}++.

        $h{1586} works because it's interpreted as an integer, so something like $h{0+1586}, which stringifies to "1586".

      thanks it worked when i added quote

Re: syntax error
by hippo (Archbishop) on Jun 20, 2017 at 15:03 UTC
    Bareword found where operator expected at 11.pl line 17

    Your script doesn't have 17 lines. This isn't the script you are attempting to compile.

      maybe i made space

      line 17

      $k= $respns->{1586iY2vSfT5EeuQTMYj6kwnbfN255KX2T}->{n_tx};
Re: syntax error
by LanX (Saint) on Jun 20, 2017 at 15:04 UTC
    > syntax error at 11.pl line 17

    Why don't you show us line 17 of file 11.pl?

    Cheers Rolf
    (addicted to the Perl Programming Language and ☆☆☆☆ :)
    Je suis Charlie!