Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: How do I put bracket on substring(s) of a string?

by jdporter (Paladin)
on Sep 10, 2008 at 19:55 UTC ( [id://710453]=note: print w/replies, xml ) Need Help??


in reply to How do I put bracket on substring(s) of a string?

sub put_brackets { my( $str, @pats ) = @_; my $mask = ' ' x length $str; my $ofs = 0; for ( @pats ) { $ofs = index $str, $_, $ofs; last if $ofs < 0; # this pattern not found; look for no more. substr $mask, $ofs, length($_), 'a' x length($_); } # print "string= '$str'\n"; # print "mask = '$mask'\n"; join '', map sprintf( /a/ ? '[%s]' : '%s', substr $str, 0, length($_), '' ), split /\b/, $mask }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2024-04-25 23:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found