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

Re: help with perl



On Mon, 26 May 1997 23:40:35 +1000 (EST), Craig Sanders <cas@taz.net.au> said:
>
> The database is a .db file created with 'makemap hash redir <redir'
> from [:space:]-delimited source input like the following:
[...]
> //.*riddler.com/Commonwealth/bin/statdeploy.* //www.taz.net.au/blank_ad.gif

The problem is that makemap downcases the keys by default so Commonwealth
is commonwealth in the map.  Use the -f flag when building the map to
disable this behavior.

Since you're always scanning the db linearly, though, using a DB map
isn't buying you anything.  I'd just read the patterns from the text
file directly.

>       $out="" ;
>       $found = 0 ;
>       while ((($key,$record) = each %redir_db) && ! $found) {
>               if (($url =~ /$key/)) {
>                       $out = $url ;
>                       $out =~ s/$key/$record/ ;
>                       $found = 1 ;
>                } ;
>       } ;
>
>       if ($debug) {
>               print $url, "==>" ;
>       } ;
>       print $out, "\n" ;

Gratuitous unsolicited style tip #1:  Don't put semicolons after a
closing brace except for do and eval blocks, and sub ref constructors.

Gratuitous unsolicited style tip #2:  This code would more idiomatically
be

    print "$url==>" if $debug;
    while (($key, $record) = each %redir_db) {
    	if ($url =~ s/$key/$record/) {
	    print $url;
	    last;
	}
    }
    print "\n";

-- 
Roderick Schertler
roderick@argon.org


--
TO UNSUBSCRIBE FROM THIS MAILING LIST: e-mail the word "unsubscribe" to
debian-user-request@lists.debian.org . 
Trouble?  e-mail to templin@bucknell.edu .


Reply to: