I have a Perl array of URLs that all contain "http://". I'd like to remove that string from each one leaving only the domain. I'm using the following for loop:
#!/usr/bin/perl
### Load a test array
my @test_array = qw (http://example.com http://example.net http://example.org);
### Do the removal
for (my $i=0; $i<=$#test_array; $i++) {
($test_array[$i] = $test_array[$i]) =~ s{http://}{};
}
### Show the updates
print join(" ", @test_array);
### Output:
### example.com example.net example.org
It works fine, but I'm wondering if there is a more efficient way (either in terms of processing or in terms of less typing). Is there a better way to remove a given string from an array of strings?