Perl Language: How To Create Directory in Perl Program

in #perl5 years ago

Learn How To Create Directory in Perl language. Check out the below video to learn how to use if and else statement in perl.

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.

How to create a directory on desktop using Perl Language?

So like most of the programming languages you can use the perl language to create directory and work with the files. File handling is pretty much easy with the perl language. It is a bit complicated but it's something one can do pretty easily.

Here the process works something like this.

  1. Create a directory
  2. Have name of the directory
$dirname ="D:/temp/";

Here as you can see we have managed to have a name for directory as temp. And in next line we are going to make a call to create the directory on the hard disk.

mkdir $dirname,  0755;

That is pretty much it for creating the simple directory on the windows desktop. It should work on linux as well considering the file permission options are 755. You can also add some sort of the try catch blocks or unless and die block for the code so that it can properly execute it for creating directory.

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 63348.66
ETH 2668.99
USDT 1.00
SBD 2.78