in reply to What does [=;] mean

the square brackets in the regular expression in split's first argument denotes that a match should be made for each of the characters within the brackets. So, split(/[=;]/, $has); splits the contents of string $has whenever it sees a = or a ;.

The result is an array: ('GFG', '1', 'GEEKS', '2','PROGEEK', '3')

But you insist on creating a hash from split's output when you write (note: %spl): my %spl = split(/[=;]/, $has);. That's not a problem for Perl. It will create a hash for you. And you know a hash consists of (key,value) pairs. So your array's odd-indexed elements are the keys and even-indexed elements are the values (assuming zero-based arrays like Perl's) even-indexed elements (e.g. 0,2,4) are your KEYS and odd-indexed elements (e.g. 1,3,5) are your values. And so your hash is (CFG => 1, GEEKS=>2, PROGEEK=>3) (hash notation is (key => value, ...))

So, now you have the hash you wanted, though you created it using a shortcut. I say "shortcut" because the logic in creating that hash from that string, in another language say Java, would be to mark your position, then look for a =, that would be the key. Then mark your position and look for a ;. That would be your value. Insert into hash and repeat till the end of string. But Perl allows you the shortcut of converting an even-size array to a hash automatically. And that is what you do because split returns back an array. And your my %spl coerces that array into a hash.

The last part of the code is printing that hash. And, being Perl, it speaks for itself. You seem confused by print "$i:$spl{$i}\n";. It just says to print the key ($i) and then print a colon and then print the value ($spl{$i}).

The example code you cited should have concentrated either on split or on hashes but (the year being 2019 and money has to be made from anything...) it makes a mess of it by mixing concepts. More confusion = more hits = more advertisments. But that's my inference. In any event, thanks Knuth Perlmonks exists.

bw, bliako