Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: creating a username from a csv file

by Tanktalus (Canon)
on Oct 04, 2012 at 22:34 UTC ( #997337=note: print w/replies, xml ) Need Help??

in reply to creating a username from a csv file

Oh, where to start.

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.)

Second, parsing CSV files without Text::CSV_XS. Not a capital crime, but maybe a minor bit of flogging. (Personally, I prefer DBD::CSV, but it uses Text::CSV_XS under the covers, so I save my back from the flogging that way.)

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:

my @fieldnames = qw(Lname Fname ssn address city state zip phone1 phon +e2); my %row; @row{@fieldnames} = split(/,/, $line); # yeah, I just told you to use +Text::CSV, but I'm keeping my suggestions independent.
Again, this is just a nit, not a problem.

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 substr.

my $user = substr($Fname, 0, 1) . substr($Lname, 0, 3) . substr($ssn, +-4);
Though I have to wonder about anyone using ssn's for anything other than taxes. Seems like a privacy invasion.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://997337]
LanX wonders, do we have a rule against systematic down voting?
[erix]: we frown :)
[marto]: Does the command line arg --product-version@ help?
[LanX]: xD
[erix]: 'systematic' is going to be hard to define I think
[marto]: Err no @
LanX Much enemy much ore
[Corion]: marto: Naah, my module doesn't care, but the users of my module might expect some things to work in Chrome that only work in later builds (or, as seems to be the case, don't work there either ;) )
[Corion]: But I really wonder - I can tell Chrome to go offline, but requesting pages over the network still succeeds. But if I manually click the "offline" checkbox, that's different :-/

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (8)
As of 2017-12-12 20:23 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (335 votes). Check out past polls.