On Wed, Jul 20, 2011 at 9:53 PM, Shlomi Fish <shlo...@shlomifish.org> wrote:

> Hi Overkill,
>
> On Wed, 20 Jul 2011 13:24:06 -0400
> Overkill <overk...@sadiqs.net> wrote:
>
> > Greetings,
> >
> > I'm trying to increment the UID field of the unix password file from an
> > csv file.  I've tried to insert C style increment and it keeps bomping
> > out.  What would be the logic to increment the 5009 to increment by
> > one?  Thanks for any help.
> >
> > -Overkill
> >
>
> don't parse CSV using regular expressions - use Text::CSV :
>
> http://perl-begin.org/uses/text-parsing/
>
> Regards,
>
>        Shlomi Fish
>
> > #!/usr/bin/perl
> >
> > #use strict;
> > #use warnings;
> >
> >     while (<DATA>) {
> >     chomp;
> >      ($first, $last, $username) = split(",");
> >        print "$username:x:5009:4001:$first
> > $last:/home/$username:/bin/false\n";
> >        }
> >    exit;
> >
> > __DATA__
> > "Bob","Ahrary","bahrary"
> > "Jill","Anderson","janderson"
> >
> >
>
>
>
> --
> -----------------------------------------------------------------
> Shlomi Fish       http://www.shlomifish.org/
> What Makes Software Apps High Quality -  http://shlom.in/sw-quality
>
> The prefix “God Said” has the extraordinary logical property of converting
> any
> statement that follows it into a true one.
>
> Please reply to list if it's a mailing list post - http://shlom.in/reply .
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>
I'm willing to dispute that. :-)

For the simple reason that as long as you control the input to the CVS file
and can be certain that no UTF8 characters or any other mess sneaks in the
simple split using the /,/ regex will be faster and much simpler then the
Text::CVS module though in any situation where you do not control the input
or in the future might not have control over the input you should definitely
use it.

Based on the current data set however this module is pure overkill...

There is a fine line between a module being useful and being over kill if
you are creating a script that you might want to use in the future or share
with colleagues etc... then you should definitely use modules as usually
they cover all kinds of corner cases that you are unlikely to even think of
let alone cover in your code. But there are situations where that is simply
not needed. A simple example is a script I once wrote for an ISP to deal
with a cable company reorganizing their network, the input though not
controlled by me was bound by a lot of rules and I could without any worries
assume all kinds of things about my input based on the business rules
governing the naming of nodes bundles and locations in the network. Of
course these situations are not very common but in case you do encounter
such a situation it can be very handy to ignore the modules and go for a
much more limited but much more strict way of working that throws an error
on every corner case that should not happen based on the business rules. (as
long as you are prepared to get called out of bed at 3 at night when an
operator finds informs you that due to a decission made a little change in
the naming conventions and your script is rolling over and playing dead
because it was not informed about this...)

In general I do agree wit the usage of modules since in the end the modules
normally have seen many iterations and usually cover much more situations
the the once you can think of based on your typical working situaiton...
which means you are much more certain your script will be able to survive
even if in a few years form now you company moves to China and wants to use
chineese names rather then latin names; which would most likely break your
current script by the way :-)

Regards,

Rob

Reply via email to