Perl Tutorial by Code Examples


Command prompt tutorial for Perl running

1. What is command prompt

Command prompt is CUI programming execution environment in Windows. CUI is Character-based User Interface. you can run program by inputting command. You usually use command when you execute Perl on Windows.

2. Run command prompt

You can run command prompt from "Start" - "All Programs" - "Accessory" - "Command prompt". If you create shortcut icon of command prompt in desktop by right click drag-and-drop, it is useful.

3. Commands you should learn at first

cd <Directory name>

You can display files in current directory by dir command. You can change current directory by cd command. You can also change current directory to the above directory by "cd ..".

4. Execute Perl

perl sample.pl arg1 arg2

Perl script is saved with ".pl" extension. If you want to pass arguments to the script, You pass arguments separated by space.

5. Pass arguments which have space.

perl sample.pl "a i u"

If the argument contains space, it must be surrounded by double quote.

6. Change drive


You can change current drive by c:(C drive) or d:(D drive).

7. Get command history


You can see command histories by up and down key.

8. File name complement

Ctrl + f

You can complete file name if you input file name halfway and put Ctrl + f. If you want to use this feature, you change command prompt config as bellow description.

9. Display environment variable

(PATH environment variable)
echo %PATH% 

If you want to see environment variable, you command "echo %ENVIRONMENT_VARIABLE%".

10. Set environment variable

(Set environment variable DATE to 20080604 )
SET DATE=20080604

(Example: you use environment variable as a argument)
perl sample.pl %DATE% 

You can set environment variable by "SET ENVIRONMENT_VARIABLE=VALUE". You must not put space to left and right of =. If you want to use environment variable, you do %ENVIRONMENT_VARIABLE%.

Even if you set environment variable, the value of OS environment variable is not changed. It is only enable in current command prompt.

11. Command prompt useful settings

1. The way to change command prompt settings

If you create a shortcut on your desktop, you can change settings by right click "Property".

2. Working folder setting, and file name complement setting

You can change working folder setting and file name complement setting from "Shortcut" tab. Working directory is that current directory you run shortcut.

If you want to enable file name complement, You add :/f to end of command prompt path in "Link(T)". Space is needed before :. After this setting, "8. File name complement" command is enabled.

%SystemRoot%\system32\cmd.exe :/f on
3. Simple edit mode setting

You can set simple edit mode from "Option" tab. If you check this, you can copy and paste by right click.

4. Font size setting

You can set font size from "Font" tab. I think if you set font size a little smaller, it is readable .

5. Screen buffer size setting

You can set screen buffer size from "Layout" tab. You set "Height" item to max value. If you increase screen buffer size, even if screen is scrolled, you can keep outputs until screen buffer size.

12. End

If you learn above things, you will not have trouble to use command prompt.

Table of contents



トラックバック - http://d.hatena.ne.jp/perlcodesampleen/20080603/1212511009