sureshp
asked on
Small OOP program in perl
Hi,
I need a small example to store userid and password in a flat file.
I would like to do as...
I would like to create a module, in that i have two functions.
1. for creating user id
2. for creating password
for creating userid, i will pass two inputs (ie, unique_number, userid)
for creaing password, i will pass two inputs(ie, unique_number,password).
userid function will store the unique number and userid in a flat file.
password function will store the password in the flat file .
In my main program i am passing these values to module.
Can you please help me to write a sample program for that?
Thanks and Regards,
S
I need a small example to store userid and password in a flat file.
I would like to do as...
I would like to create a module, in that i have two functions.
1. for creating user id
2. for creating password
for creating userid, i will pass two inputs (ie, unique_number, userid)
for creaing password, i will pass two inputs(ie, unique_number,password).
userid function will store the unique number and userid in a flat file.
password function will store the password in the flat file .
In my main program i am passing these values to module.
Can you please help me to write a sample program for that?
Thanks and Regards,
S
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
GT
# -- your main program
package main;
use Sureshp::Users;
my $obj = bless {}, "main";
$obj->create_userid(1, 'test_user1');
$obj->create_password(1,'s
exit;
# --- your package file under a folder in your @INC
package Sureshp::Users; # you can use an module name that you see fit
use strict;
use vars qw(@ISA $VERSION @EXPORT @EXPORT_OK);
use Carp;
$VERSION = 0.01;
@ISA = qw(Exporter);
@EXPORT = qw(create_userid create_password);
@EXPORT_OK = qw(
create_userid create_password
);
sub create_userid {
my $s = shift;
my ($n, $id, $fn) = @_;
$fn = '/my/user/id/file.txt' if ! $fn;
open FN, ">>$fn" or die "Could not write to file: $!\n";
print FN "$n,$id\n"
close FN;
return;
}
sub create_password {
my $s = shift;
my ($n, $pwd, $fn) = @_;
$fn = '/my/user/id/password.txt'
open FN, ">>$fn" or die "Could not write to file: $!\n";
print FN "$n,$pwd\n"
close FN;
return;
}