Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

(tye)Re: How to make only two of three substitutions?

by tye (Sage)
on Oct 15, 2002 at 13:23 UTC ( #205367=note: print w/replies, xml ) Need Help??


in reply to How to make only two of three substitutions?

    $str =~ s#/##   for  1,2;
or     s#(/\s*){2}\z##
for example. But these assume you slurp the entire file into a string. Perhaps you are doing a perl -pe kind of thing...     perl -i.old -pe '$sawSlash++ && s#/## if m#/#'
(updated again. Thanks, blakem. I added "$str =~" to match what I was thinking and what I had tested.)

        - tye (saaa x y z aziez,s $e $s deedeydi,t $ex,print)

Replies are listed 'Best First'.
Re: (tye)Re: How to make only two of three substitutions?
by blakem (Monsignor) on Oct 15, 2002 at 20:16 UTC
    s#/## for 1,2;
    That won't work. $_ gets aliased in the for loop to the constants '1' and '2'. You could get away with:
    for my $i (1,2) { s#/## }
    Though, its not real pretty...

    -Blake

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (4)
As of 2019-10-21 03:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?