Perl is highly advanced programming language in order to process with strings. In this article, I have explained about the simplest way to split the key value pair string to Perl hash.
Source code for split key value pair string to hash
use warnings;
use strict;
use Data::Dumper;
### Sample input
my $input = "key1=value1&key2=value2&key3=value3&key4=value4&key5=value5";
### Spliting
my %hash_response = split /[&=]/, $input;
print Dumper(\%hash_response);
Output
$VAR1 = {
'key1' => 'value1',
'key2' => 'value2',
'key3' => 'value3',
'key4' => 'value4',
'key5' => 'value5'
};

Related Posts
How to check PERL hash is empty or notTo check given Perl Hash contains a value or not: Check by fetching keys from the hash: if(keys %myhash) { print "Values exist"; } else { print "Values not exist"; } keys, in scalar context returns the number of keys in the hash. Check by using a hash in scalar…
-
-
Find out what Perl modules already installed on Linux SystemUse 'instmodsh' command to get a complete list of installed Perl modules on your Linux system and it provides an interactive shell type interface to query details of locally installed Perl modules. Open your terminal and type the following command: instmodsh Now, you will get the list of available commands…
-
How to move a file in Perl (File::Copy)How to move a file in Perl? Methods “move” or “mv” implemented in the module “File::Copy” can be used. Both are able to move a file to a different filesystem or disk, by first making a copy, and then deleting the original file. The different between them is in that…
Converting date to epoch timestamp in Perl: str2time, strptimeUse Date::Parse to convert normal date string to epoch timestamp. Date::Parse provides two routines for parsing date strings into time values. str2time(DATE [, ZONE]) str2time parses DATE and returns a unix time value, or undef upon failure. ZONE, if given, specifies the timezone to assume when parsing if the date…
-
Generating Random String Using PHPGenerating random strings with custom specified length is most required functionality in every project. In this article, I described the easiest way to generate custom length random string. PHP program for Random String Generate: <?php /* * Function to generate random string * Default length 30 character */ function generateRandomString($length…
-
PHP: Convert JSON String to Array / Object using json_decodeHow to convert JSON String to Array / Object using json_decode? json_decode is inbuilt function in PHP. It will take a JSON string and converts it into a PHP array or object depends on arguments. Live demo: https://www.gtechhub.com/json-decode-online Convert JSON String to PHP Object: <?php $json_input = '{"array_key_1":"array_value_1","array_key_2":"array_value_2", "array_key_3":"array_value_3","array_key_4":"array_value_4","array_key_5":"array_value_5"}'; $json_result…
-
PHP: Create JSON String from Array / Object - json_encode()json_encode() function is an inbuilt PHP function which is used to convert PHP array or object into JSON representation. Encoding is used to bundle data with respect to a particular format. This process will be required to preserve data consistency. Convert array to JSON: <?php $input_ary = array(); $input_ary['array_key_1'] = 'array_value_1'; $input_ary['array_key_2']…
PHP Cheat SheetPHP code is usually processed on a web server by a PHP interpreter implemented as a module, a daemon or as a Common Gateway Interface (CGI) executable. On a web server, the result of the interpreted and executed PHP code — which may be any type of data, such as…