Perl Language: How To Use Hash in Perl Program

in #perl5 years ago

Learn How To Use Hash in Perl language.

If you like this video then Do share the video in the article to your friends or in your social media accounts. You can also subscribe to the youtube channel.

I recommend checking out Learning Perl book. You can get a lot of answers to your questions. Plus the new edition of the book can cover some of the latest topics too.

What are hashes in Perl?

When you learn about the collections in Perl or any language. You may notice that most of the languages have the hashes in it. And it can be pretty interesting to learn about them. So here we are going to check out some of the simple things about hashes in perl.

  1. A hash is a key value pair.
  2. A hash variable starts with the % sign.
  3. You can get individual element in the hash using the $ symbol.

You can check the below example for the perl hash. So hopefully the below example helps you.

%data =  ('1, 'hey',2, 'hello', 3, 'world');

You can get the output of the hash using simple call.

% data

Here the name of our hash is the data. So you can name it anything else if you want. This is pretty much the simple tutorial you can get for the perl hashes.

I hope that this tutorial article helped.

If you haven't checked out the first video in the series. Check how to run program in Perl .

Also do check out the second video on the Variables in Perl language.

Tips for Running Perl Code

You can check the installation of the perl by typing the following code if you are on unix or linux, in case of windows you have to check the path if perl bin folder is added there.

which perl

Perl code requires you to have the code stored in the .perl file extension file. This way when you run the perl code say it's in the file named helloworld . pl

You can run the perl file on command prompt like this.

perl helloworld . pl

That's it. You can now execute the perl code on your computer.

If you are interested in modern language, try Go Language Tutorials.

I hope the information here helps you. I'd appreciate if you like the video and share it with others.

Coin Marketplace

STEEM 0.19
TRX 0.15
JST 0.029
BTC 63330.55
ETH 2645.93
USDT 1.00
SBD 2.82