Alright Monks, so I made a subroutine that is supposed to break down links into 3 pieces, the domain,the path,and filename. The subroutine works for most urls:
sub createStruct{
my %song = ();
my $orig_url = $song{url} = shift;
my $url = URI->new( "$orig_url" );
my $domain = $song{domain} = $url->host;
my @split_url = split('/',$url);
my $filename = $song{filename} = $split_url[-1];
$orig_url = $url;
$orig_url =~ s/$domain//g;
$orig_url =~ s/$filename//g;
$orig_url =~ s/http:\/\/|https:\/\/|ftp:\/\///g;
my $dir = $song{dir} = $orig_url;
return \%song;
}
but when I pass this url into the subroutine, it cannot remove the filename from the original url.
This is the URL: http://freemp3files.hostoi.com/mp3_6744/Club SoundZ We Vol.15 (2010).mp3
This is the line that doesnt work : $orig_url =~ s/$filename//g;
Why cant the filename be removed for this particular url?