What a convoluted way to say@month = split //, $DOB[0]; $digits_month = @month;
There's many more albeit small examples of pretzel logic in that piece of code. A first cleanup yields$digits_month = length $DOB[0];
my $bday = "8/16/97"; my $firstname = "Benjamin"; my $lastname = "Biederman"; my ($month, $day, $year) = split /\//, $bday; my $formatted_bday = ''; if (length($month) == 1) { $formatted_bday = "0"; } $formatted_bday .= $month; if (length($day) == 1) { $formatted_bday .= "0"; } $formatted_bday .= $day; my $login_name = lc substr $firstname, 0, 1; . lc substr $lastname, 0, 1; . $formatted_bday;
Of course that's still far too elaborate. Builtin functions to do such formatting already exist. Assume that Perl has what you need when you're trying to solve such trivial problems.
You're also well advised to read Mark-Jason Dominus' excellent Program Repair Shop and Red Flags article series on Perl.com.
Makeshifts last the longest.
In reply to Re: Convert split to regex
by Aristotle
in thread Convert split to regex
by 3dbc
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |