hello bart
thanks for all the pointers especially about the superb /e modifier (the
substitution now looks like:
s/<TAG[^>]+id=(\d+)>/exists($tagHash{$1}) ? $tagHash{$1} : "<tag id=$1>"/igeo)
thanks
allan


Bart Lateur wrote:
> 
> On Sat, 30 Jun 2001 01:20:51 +0200, allan wrote:
> 
> >my (main) question is wheter it is worthwhile to create a txt-file of
> >the relevant data on each line and then build a hash based on this file.
> >this hash would probably never have more than a few hundred elements. my
> >aiming is partly to unstress the database server but primarily to
> >speeden things up as it is concerning a heavily visited website.
> 
> I would not bother with creating a separate database export file. In my
> experience, it's easy to forget to update the export file, and you're
> doing you're  thing with outdated data.
> 
> But loading data into a hash isn't a bad idea. I've done that with
> thousands of items. But I'd just do one SELECT statement (if it's an SQL
> db server), and get them all at once, and store them into the hash
> directly.
> BTW using "<TAG ID=1>" as the hash key isn't really smart. For one, a
> hash is case sensitive. Since all the tags are "TAG", using just the ID
> as the hash key sounds less like asking for trouble. Oh, and
> s/$tag/$id/ig does sound like a bad idea, too. You know what: you can do
> your processing in the RHS of the s///, with an /e modifier. So
> 
> >       while (/(<TAG[^>]+id=(\d+)>)/ig) {
> >               my $tag = $1;
> >               my $id = $2;
> >               my $value =  getValue($id);
> >               s/$tag/$value/ig; #replace
> >       }
> 
> can become
> 
>         s{(<TAG[^>]+id=(\d+)>)}{
>             my $tag = $1;
>             my $id = $2;
>             my $value =  getValue($id);
>             $value
>         }ieg;
> 
> (and that's still more verbose than necessary) where getValue() is
> essentially a hash lookup.
> 
> --
>         Bart.

Reply via email to