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;
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Outside of code tags, you may need to use entities for some characters:
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
|
|