jayto has asked for the wisdom of the Perl Monks concerning the following question:
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?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Why cant regex parse this string?
by moritz (Cardinal) on Jul 12, 2012 at 13:57 UTC | |
by jayto (Acolyte) on Jul 12, 2012 at 14:08 UTC |