<?xml version="1.0" encoding="windows-1252"?>
<node id="997337" title="Re: creating a username from a csv file" created="2012-10-04 18:34:39" updated="2012-10-04 18:34:39">
<type id="11">
note</type>
<author id="421114">
Tanktalus</author>
<data>
<field name="doctext">
&lt;p&gt;Oh, where to start.&lt;/p&gt;
&lt;p&gt;First off, you have both open FILE and open my $fh.  Stick to one style.  Specifically the latter.  Yes, it's a minor nit normally, but it got promoted to a major nit (if not, at least a lieutenant nit) by virtue of inconsistency.  Also, you don't check the first open's return - stick the "or die" in there as well.  (Again, a lieutenant nit for the same reason.)&lt;/p&gt;
&lt;p&gt;Second, parsing CSV files without [mod://Text::CSV_XS].  Not a capital crime, but maybe a minor bit of flogging.  (Personally, [http://perl5maven.com/calculate-bank-balance-take-two-dbd-csv|I prefer] [mod://DBD::CSV], but it uses [mod://Text::CSV_XS] under the covers, so I save my back from the flogging that way.)&lt;/p&gt;
&lt;p&gt;Next, your assignment to all those variables.  When I'm doing a massive split like this, I like to use a hash instead of an array.  Or individually-named variables:
&lt;c&gt;
my @fieldnames = qw(Lname Fname ssn address city state zip phone1 phone2);
my %row;
@row{@fieldnames} = split(/,/, $line); # yeah, I just told you to use Text::CSV, but I'm keeping my suggestions independent.
&lt;/c&gt;
Again, this is just a nit, not a problem.&lt;/p&gt;
&lt;p&gt;You didn't quite show us what you were trying, only alluded to it and gave us context.  But the function you're looking for is [doc://substr].
&lt;c&gt;
my $user = substr($Fname, 0, 1) . substr($Lname, 0, 3) . substr($ssn, -4);
&lt;/c&gt;
Though I have to wonder about anyone using ssn's for anything other than taxes.  Seems like a privacy invasion.&lt;/p&gt;</field>
<field name="root_node">
997328</field>
<field name="parent_node">
997328</field>
</data>
</node>
