Hello Brett,

Tuesday, July 03, 2001, Brett W. McCoy <[EMAIL PROTECTED]> wrote:

>> >> > > > Unpack works well with fixed format data like this.
>> >> > >
>> >> > > Why would you use unpack when this can be easily split apart with a regex?
>> >> > > I'd think unpack would be overkill!
>> >>
>> >> why is it overkill any more that a regex?
>>
>> BWM> Are you saying we should be using unpack rather than regular expressions?
[...]

BWM> The slight performance gain you might get with unpack doesn't compare to
BWM> the flexibility of a regular expression.  If the date style changes to,
BWM> say, 02July01 (instead of 2July2001), the regular expression will still
BWM> work and the code does not need to be changed.  The code would need to be
BWM> modified for the unpack version to continue to work (since it was checking
BWM> for the length of the string).  I would prefer the general solution to the
BWM> more specific unless the performance gain of the latter is significant.
BWM> In this case, it isn't.

in  my  opinion, regexp's is the slowest way to do something - payment
for flexibility. but, in most cases, speed grows very little and growing
does not matter.

btw,  unpack  isn't  faster method for fixed strings parsing. everyone
can throw rock at me, but substr works faster :)

   'subst' => sub {

       my ( $month, $day, $year );
       my $a;
       for my $date (@dates)
       {
            my $j=0;
            $day = substr ( $date, $j++, 1 );
            $a   = substr ( $date, $j, 1 );
            if ( ord($a) <= 57 )
            {
              $day .= $a;
              $j++;
            }

            $month .= substr ( $date, $j, 3 );
            $year   = substr ( $date, $j+3, 4 );
       }
   }


Best wishes,
 Maxim                            mailto:[EMAIL PROTECTED]


Reply via email to