Brian Volk wrote:
Gunnar Hjalmarsson wrote:
Brian Volk wrote:
I have a file that contains the file name and the url. I need
to separate the url so I can use LWP::Simple; to check the
link, however, I need to keep the file name in tact so I can
trace it back to my website. Anyone have any suggestions?
Use map() together with split() to populate a hash.
Like this...
my %urls = map { split(' ', $_) } <LINKS>;
Yep, that's what I had in mind.
if this is correct, can someone hint to me how I am supposed to
incorporate this into my foreach statement.
<code snipped>
I changed @urls to %urls and the script actually gave me what I was
trying to accomplish... but I would rather know the correct way.
Well, your description of what the file looks like exactly, and of
what it is you are trying to accomplish, isn't that clear to me, so I
don't know of any "Correct Way". :) This is my interpretation:
#!/usr/bin/perl
use strict;
use warnings;
use LWP::Simple;
my $file = '/Program Files/OptiPerl/results.txt';
open my $LINKS, $file or die "Can't open $file: $!";
open my $BAD, '>> bad.txt' or die $!;
open my $GOOD, '>> good.txt' or die $!;
my %urls = map { split ' ', $_ } <$LINKS>;
for my $name ( keys %urls ) {
print "$name $urls{$name}\n";
my ($type) = head( $urls{$name} );
print { defined $type ? $GOOD : $BAD } "$name $urls{$name}\n";
}
close $LINKS;
close $BAD;
close $GOOD;
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>