in reply to (jeffa) Re: url2link
in thread Url2Link 0.1 GUI/TK

The basename + substitution business doesn't seem to make any sense. The doc says basename quotes any metacharacters in the suffix(es), so that line is looking for a literal dot star at the end of the filename - rather unlikely, even if we have a URL to begin with. The substitution will replace the first repeated sequence of one dot followed by any number of word characters by .url (whose dot needs no quoting since it's on the right hand side of the substitution anyway). That sequence does not necessarily have to be what terminates the string. Taking a ponderous guess at the purpose of the hooha, I bid URI.

And for some more Perlishness, use the diamond operator instead of explicitly opening a file. With lots fewer temporaries:

use strict; use warnings; use URI; use URI::Find; use Config::IniHash; use File::Basename; use File::Spec::Functions qw(catfile); my $dir = 'Links'; unless (-d $dir) { mkdir $dir or die "can't mkdir($dir): $!"; } URI::Find->new(\do {local $/; <> })->find(sub { my($uri, $orig_uri) = @_; WriteINI(catfile($dir, uc URI->new($uri)->host), { DEFAULT => { BASEURL => $uri }, InternetShortcut => { URL => $uri, Modified => 0 }, }); });

Makeshifts last the longest.

Replies are listed 'Best First'.
(jeffa) 3Re: url2link
by jeffa (Bishop) on Jan 13, 2003 at 14:22 UTC
    "The basename + substitution business doesn't seem to make any sense."

    I thought it made sense ... i just thought it to be a but i now see that it is a horrible way to do it! ;) I knew there had to be a better way, and what you have is soooo much better. Thanks Aristotle.

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    
      "jeffa says regarding Url2Link 0.1 GUI/TK ... we like CPAN around here" So you are not allow to be creative in here? Meaning come up with your core code?

        Sure you are allowed to be creative. The problem is when the code you write does not work robustly because you make too many assumptions. If you reinvent the wheel, then the one you make should at least be round as well.

        And to be honest, I use CPAN modules for exactly the same reason I use Perl: because I'm too lazy to take care of everything myself. Others have spent a good amount of time creating solutions that work reliably and don't trip over unusual input. Why should I go to the trouble of reimplementing all of that for what conceptually is a very simple task?

        Like in my previous node on this thread: I want the hostname from a URL. So I just take a module and say "I want the hostname". And now I know that whatever URLs I ever throw at it, it will always work right. Even if I throw a gopher:// at it. Or something else I never thought of when I was writing the script. It doesn't break.

        And if I really do want to implement a hostname URL extraction, I have the module's source to read.

        Makeshifts last the longest.