Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: remove first and last character of string (updated)

by haukex (Archbishop)
on Oct 14, 2020 at 06:48 UTC ( [id://11122811]=note: print w/replies, xml ) Need Help??


in reply to remove first and last character of string

i have a script that calls an URL, and returns characters like this "654321_1111" (quotes are part of the return).

Many web APIs return JSON. If that is the case here, you can use decode_json from one of the JSON modules, such as Cpanel::JSON::XS, or JSON::PP has been in core since Perl 5.14.

Update: In JSON::PP versions before 4.0, that is, those distributed with Perl 5.28 and before, the allow_nonref option must be set to decode a string. That is, instead of decode_json(q{"654321_1111"}), one has to write JSON::PP->new->allow_nonref->decode(q{"654321_1111"}).

Replies are listed 'Best First'.
Re^2: remove first and last character of string (updated)
by Anonymous Monk on Oct 14, 2020 at 19:44 UTC
    ... and if the response is JSON, then you absolutely should not try to do anything with it until you have "decoded" it. Apply your regex-magic only to members of the resulting data structure.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11122811]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2024-04-25 05:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found