On 2010.03.12 00:33, John W. Krahn wrote: > raphael() wrote: >> #!/usr/bin/env perl >> >> use strict; >> use warnings; >> >> my @array = qw ( >> http://abc.com/files/randomthings/A/1.html >> http://abc.com/files/randomthings/A/2.html >> ); >> >> for ( @array ) { >> >> # This works >> # s!/A/\d+.html$!!; $url = $_; > > Not quite, that should be: > > s!/A/\d+\.html$!!; $url = $_; > > Unless the . character is escaped it will match *any* character. > > >> # Doesn't work ~ gives "1" >> ( my $url ) = ( $_ ) =~ s!/A/\d+.html$!!; >> print "$url" . "\n"; >> >> } >> >> __END__ >> >> I want to remove the '/A/1.html' > > That means that you want to modify @array? Do you really need to? > > >> and assign the remaining value i.e. link to >> "$url" >> But all I get is "1" as value of "$url" which I think is return value >> that >> substitution worked. >> >> How can I remove '/A/1.html' and assign remaining "$_" to "$url"? > > If you just want to assign everything before '/A/1.html' to $url then: > > ( my $url ) = m!(.*)/A/\d+\.html$!; > > If you really need to modify @array then go with your commented out code > at the top of the loop.
I applaud the OP for his question ;) After I changed some of the sample by removing the use of $_, there were certain circumstances where having the parens were necessary, and other times not. Am I correct in thinking that this: $url = $file =~ m{ (.*) /A/\d+.html }x; ...assigns '1' to $url because =~ binds tighter and assigns a 'true' value to $url, whereas: ( $url ) = $file =~ m{ (.*) /A/\d+.html }x; ...$url here is evaluated first, and assigned the actual string afterwards? iow, is it simply an arithmetic thing, that can also be seen as this:? ( $url ) = ( $file =~ m! (.*) /A/\d+.html !x ); D'oh! I just answered my own question. Learn something new everyday, even though it's a principle that I've known for years, but just didn't apply it... ( my $this ) = ( ( $url ) = ( $file =~ m! (.*) /A/\d+.html !x ) ); print "$url :: $this\n"; Steve -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/