Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

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.


In reply to Re: creating a username from a csv file by Tanktalus
in thread creating a username from a csv file by jrp370

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others chilling in the Monastery: (10)
    As of 2014-09-02 17:03 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite cookbook is:










      Results (25 votes), past polls