Im working on a script that reads in a csv file and then prints specific information from it to a different file called password.passwrd. so far ive gotten by script to read the csv file however i need to create a user name by taking the first letter from the first name, the first 3 letters from the last name and finally the last 4 digits from the ssn number. Ive tried using splice but that doesnt seem to work, can anyone help point me in the right direction?
update: it seems like i have figured it out, i dont know why i didnt think of using split before.#!/usr/bin/perl use strict; use warnings; open FILE,'>>',"password.passwd" or die 'Could not open file'; my $file = 'file.csv'; my @data; my $count=500; open(my $fh, '<', $file) or die "Can't read file '$file' [$!]\n"; while (my $line = <$fh>) { chomp $line; $count++; my @fields = split(/,/, $line); push @data, \@fields; #print "@fields\n"; my($Lname,$Fname,$ssn,$address,$city,$state,$zip,$phone1,$phone2)=($fi +elds[0],$fields[1],$fields[2],$fields[3],$fields[4],$fields[5],$field +s[6],$fields[7],$fields[8]); my $user=""; my $password="4cb9c8a8048fd02294477fcb1a4119la"; my $userId="$count"; my $groupId='25'; my $info="$Fname $Lname"; my $home='/home/payroll'; my $shell='/bin/payroll'; ##################################################### ##################create usr name######################### ########################################################## print FILE "$user:$password:$userId:$groupId:$info:$home:$shell\n"; } close $fh; close File;
In reply to creating a username from a csv file by jrp370
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |