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;
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.