You can write a Perl script in a single file. If your script is very simple and it doesn't have any re-usable code, then it is the right choice. But if you have some piece of code, which can be re-used in other scripts or by other persons and still it is single file, then it is called a naive script.
Write the reusable code as modules and 'use' that module in your script and encourage others to use it. In this post I'll demonstrate how to create Perl module with a simple example and how to package it, such a way that, it can be installed like any CPAN perl modules.
Problem Statement:
Write a script which either
1) Accepts a Binary number and converts it into Decimal number
2) Accepts a Decimal number and converts it into Binary number
Write Decimal and Binary converter functions in a separate module and 'use' it in a controller script.
Know-how: Perl modules
*) How to create Perl modules? Learn about EXPORT, EXPORT_OK, etc
Sample invocation
$ ./converter.pl
Welcome to Slice Off Codes number converter
A Utility to convert Binary to Decimal number
and Decimal to Binary number
Press 1: to select Binary to Decimal Converter
Press 2: to select Decimal to Binary Converter
Press 3: to quit
Choice : 1
Enter Binary number
101
Decimal value of Binary number 101 = 5
Press 1: to select Binary to Decimal Converter
Press 2: to select Decimal to Binary Converter
Press 3: to quit
Choice : 2
Enter Decimal number
6
Binary value of Decimal number 6 = 110
Press 1: to select Binary to Decimal Converter
Press 2: to select Decimal to Binary Converter
Press 3: to quit
Choice : 3
Source code
Write the reusable code as modules and 'use' that module in your script and encourage others to use it. In this post I'll demonstrate how to create Perl module with a simple example and how to package it, such a way that, it can be installed like any CPAN perl modules.
Problem Statement:
Write a script which either
1) Accepts a Binary number and converts it into Decimal number
2) Accepts a Decimal number and converts it into Binary number
Write Decimal and Binary converter functions in a separate module and 'use' it in a controller script.
Know-how: Perl modules
*) How to create Perl modules? Learn about EXPORT, EXPORT_OK, etc
Sample invocation
$ ./converter.pl
Welcome to Slice Off Codes number converter
A Utility to convert Binary to Decimal number
and Decimal to Binary number
Press 1: to select Binary to Decimal Converter
Press 2: to select Decimal to Binary Converter
Press 3: to quit
Choice : 1
Enter Binary number
101
Decimal value of Binary number 101 = 5
Press 1: to select Binary to Decimal Converter
Press 2: to select Decimal to Binary Converter
Press 3: to quit
Choice : 2
Enter Decimal number
6
Binary value of Decimal number 6 = 110
Press 1: to select Binary to Decimal Converter
Press 2: to select Decimal to Binary Converter
Press 3: to quit
Choice : 3
Source code