Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

splitting the 1st letter of a varible

Status
Not open for further replies.

paublo

ISP
Joined
Sep 14, 2006
Messages
127
Location
US
Hi, I'm slowly learning perl, although I'm a network admin and don't use it on an everyday basis. I have what might be an easy question for you guys.

basically i have a server that passes 2 varibles (username and password) to a perl script on a linux server.

the problem is i need the home directory to be /home/1st letter of username/useranme ex: /home/t/test.


how can i take the username and create another variable with just the 1st letter of the original username varible ?

heres the script im using.
open(INFILE, "@ARGV[0]");
$infile = <INFILE>;
($username,$password) = split(/\|/, $infile);
close(INFILE);

@calladduser = ("/usr/sbin/adduser $username -g 503 -d /home/CANT GET THIS WORKING/$username -s /sbin/nologin -p $password","\n");
system("@calladduser");

# for the crypting of adduser -p, since we are using shadow passwds
# and adduser -p passes plain passwords.

@cryptpasswd = ("echo $password | passwd $username --stdin");
system("@cryptpasswd");

print ("New User $username has been successfully added!\n");
print ("New User password: $password\n");
$username\n");

open(OUTFILE, ">>/usr/local/private/platypusd/secure_dir/plat_adduser.log");
print OUTFILE ("@calladduser");
close(OUTFILE);


TIA, P.A
 
Code:
my $username = "testuser1";
my ($first) = $username =~ /^(.)/;

print "username=$username; first=$first\n";

-------------
Cuvou.com | My personal homepage
Project Fearless | My web blog
 
thank you Kirsle, i knew it would be simple, for the people that know!
 
Or if you're unfamiliar with regular expressions, just stick with the string manipulation method:

Code:
[url=http://perldoc.perl.org/functions/my.html][black][b]my[/b][/black][/url] [blue]$username[/blue] = [red]"[/red][purple]testuser1[/purple][red]"[/red][red];[/red]

[black][b]my[/b][/black] [blue]$first[/blue] = [url=http://perldoc.perl.org/functions/substr.html][black][b]substr[/b][/black][/url] [blue]$username[/blue], [fuchsia]0[/fuchsia], [fuchsia]1[/fuchsia][red];[/red]

[url=http://perldoc.perl.org/functions/print.html][black][b]print[/b][/black][/url] [red]"[/red][purple]username=[blue]$username[/blue]; first=[blue]$first[/blue][purple][b]\n[/b][/purple][/purple][red]"[/red][red];[/red]

- Miller
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top