[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Omaha.pm] Quick shorter code tip: for() {}




This came up at work this week...

j


BEFORE:

    while (($item_code,$enabled,$descript) = $sth->fetchrow_array)
    {
        $item_code =~ s/[^ -~]//g;
        $item_code =~ s/\s+$//;
        $enabled =~ s/[^ -~]//g;
        $enabled =~ s/\s+$//;
        $descript =~ s/[^ -~]//g;
        $descript =~ s/\s+$//;

AFTER

    my @row;
    while (@row = $sth->fetchrow_array)
    {
        for (@row) {
           s/[^ -~]//g;
           s/\s+$//;
        }
        ($item_code,$enabled,$descript) = @row;