Shell to perl

john83reuben's Avatar, Join Date: Feb 2008
Light Poster
I have done a script, but it is based on shell script, and i want to convert it to perl. I am very new to perl.

This is my shell script

#!/bin/bash

echo -n "Enter your name : "
read username
echo -n "Enter your password : "
read password

pass=$(perl -e 'print crypt($ARGV[0], "password")' $password)
useradd -m -p $pass $username

And i want to change it to perl script

This is how i change it, but it does not work

#!/usr/bin/perl

print "Enter your name : \n";
$username = <STDIN>;
print "Enter your password : \n";
$password = <STDIN>;

$pass=$('print crypt($ARGV[0], "password")' $password)
system("useradd -m -p $pass $username");

PLease help me.
john83reuben's Avatar, Join Date: Feb 2008
Light Poster
I have found the solution.Thanks

#!/usr/bin/perl

print "Enter your name : \n";
$username = <STDIN>;
print "Enter your password : \n";
chomp(my $password = <STDIN>);

$pass = crypt($password,"password");

system("useradd -m -p $pass $username");
pradeep's Avatar, Join Date: Apr 2005
Team Leader
Good that you have found the solution yourself! Happy coding in Perl!