Thank you for contributing code, but it's not very Perl-ish. Let's make some changes, eh? (And what is up with multiple closing braces on the last line --- did you not a receive a syntax error like i did?)

First, your check for the "Links" directory is a bit awkward, we shouldn't have to bail if the directory already exists:

my $dir = 'Links'; if (-d $dir) { chdir $dir or die "can't chdir: $!"; } else { mkdir $dir or die "can't mkdir: $!"; }
but why even do that? All you need to do is create the dir if id doesn't exist, and then use that dir name when you write to files. This prevents having to chdir (something i try to avoid). Next, why waste RAM with an array when you loop on the file handle?
open FILEIN, "urls.txt" or die "Could not open file $!"; while(<FILEIN>) { chomp; ... }
As you will see in a little while however, my version will need to 'slurp' the the whole file into a scalar. Also, this code screams out to me "Use a Getopt module!!", but i'll leave that as an exercise. ;)

Next, pull in the URI::Find, Config::IniHash and File::Basename CPAN modules to ease our burden. At this point, however, the skeleton of your script changes, so here is my version complete:

use strict; use warnings; use URI::Find; use Config::IniHash; use File::Basename; use vars qw( @FOUND ); my $dir = 'Links'; my $file = 'urls.txt'; unless (-d $dir) { mkdir $dir or die "can't mkdir: $!"; } open FILEIN, $file or die "can't open $file: $!"; my $urls = do {local $/; <FILEIN>}; my $finder = URI::Find->new(\&found); $finder->find(\$urls); for (@FOUND) { my $hash = { DEFAULT => { BASEURL => $_ }, InternetShortcut => { URL => $_, Modified => 0 }, }; my $file = basename($_,'.*'); $file =~ s/(\.\w+)+/\.url/; WriteINI("$dir/\u$file", $hash); } sub found { my($uri, $orig_uri) = @_; push @FOUND,$orig_uri; }

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)

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.