Here is another easy-to-solve problem that leads to more complex questions.
A standard DNS serial has the following syntax: YYYYMMDDVV, that is: the modification date in year-month-day format (four, two and two digits, respectively) and a two-digit version number. For example, the third version of today's map should be 2002062403.
Now suppose you have a script that updates your DNS maps: to update the serial your code should:
- retrieve today's year, month and day and merge them together, say with a sprintf; let's put it in $today;
- compare the serial $today, e.g.: with a pattern matching: if ($serial =~ /^$today/) {...;
- if the match doesn't succeed, then setting $serial is really easy: $newserial = $today."01" ;;
- if the match succeeds, it's easy again but a little more work is required: extract the last two chars of $serial and increment by one; no sweat: substr or a regexp are ok.
Solved this easy problem, one meditation came into my mind: having some data in this form: YYYYMMDDVV, what is the most efficient way to deserialize this data? I mean, among the many ways of doing the job:
- using substr repeatedly, once for datum;
- using a regexp like /^(\d{4})(\d{2})(\d{2})(\d{2})$/;
- doing weird karussels with pack (maybe);
- ...
which, in your opinion, could be the best way under several aspects (speed, memory consumption, cpu consumption, simplicity... choose your favourite :-)
Ciao!
--bronto
|
---|
Replies are listed 'Best First'. | |
---|---|
(MeowChow) Re: Efficient coupling/decoupling of serialized data
by MeowChow (Vicar) on Jun 24, 2002 at 09:20 UTC | |
by bronto (Priest) on Jun 24, 2002 at 10:31 UTC | |
Re: Efficient coupling/decoupling of serialized data
by rob_au (Abbot) on Jun 24, 2002 at 09:13 UTC | |
by bronto (Priest) on Jun 24, 2002 at 10:08 UTC | |
Re: Efficient coupling/decoupling of serialized data
by samtregar (Abbot) on Jun 24, 2002 at 17:04 UTC | |
by PrakashK (Pilgrim) on Jun 24, 2002 at 22:02 UTC | |
by samtregar (Abbot) on Jun 24, 2002 at 23:22 UTC | |
Re: Efficient coupling/decoupling of serialized data
by Albannach (Monsignor) on Jun 24, 2002 at 17:30 UTC |