Validating user input in perl
In the long term this approach works out better for both customers and the developers, who must maintain the code.
This is especially true when we look at writing web services.
Web services have to deal with incoming data from a POST, PUT or PATCH request that are usually in the popular Java Script Object Notation (JSON) format.
Let’s look at a couple of approaches one can take to validate the incoming JSON.
To interactively execute any of the tutorial examples below, I recommend using this validator, which implements the fge/json-schema-validator code from Git Hub.
You’ll find that using this validator makes playing with a schema and trying out various validation scenarios quite simple.
Not all of these are as effective as one would hope: A better approach to validating JSON input is the use of a JSON schema.
This provides great power and flexibility in constructing a rock-solid contract for incoming JSON web service requests.
Each value can be either a number, a string, or a reference. Hashes, like other Perl variables, are declared using the ) sign.
Arrays are ordered, and you access an element of an array using its numerical index.
In this article of the Perl Tutorial we are going to learn about hashes, one of the powerful parts of Perl. It's a little mnemonic trick to help you remind about the key-value structure.
Some times called associative arrays, dictionaries, or maps; hashes are one of the data structures available in Perl. Some people think that hashes are like arrays (the old name 'associative array' also indicates this, and in some other languages, such as PHP, there is no difference between arrays and hashes.), but there are two major differences between arrays and hashes.