Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Map not giving me what I thought it would.

by princepawn (Parson)
on Jun 02, 2001 at 08:55 UTC ( [id://85160]=note: print w/replies, xml ) Need Help??


in reply to Map not giving me what I thought it would.

First,

shorten this:
map { s/^-// } @ARGV; print join ("\n", @ARGV) . "\n";

to this

print join "\n", map { s/^-// } @ARGV;

now for an answer

In the first case, you were modifying $_ and as a result modifying@ARGV in place. Since you printed @ARGV, you got what you expected.

however, the second time, you received a number indicating the number of succesful matches. Check out the /gmodifier you want - to match more than once in the string.

Here is a simpler example that shows what was happening each time you applied your regexp to $_

$_ = 'aaaaaaaaaaa'; my $x = s/a//; print "$x\n";

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://85160]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2024-04-23 12:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found