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

Re^3: Stupid mistakes I repeatedly make

by thinker (Parson)
on Mar 29, 2005 at 08:53 UTC ( [id://443070]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Stupid mistakes I repeatedly make
in thread Stupid mistakes I repeatedly make

Here's one way to do it in PHP. There are possibly better ways.

#!/usr/bin/php -q <?php error_reporting(E_ALL); $data = array("one", "foo", "two", "foo", "three", "foo", "four", "foo", "foo"); $changed = 0; $new = preg_replace_callback("/foo/", create_function( '', '$GLOBALS{"changed"}++; return "bar";' ), $data); print_r($new); print "We changed $changed items\n"; ?>

This prints

Array ( [0] => one [1] => bar [2] => two [3] => bar [4] => three [5] => bar [6] => four [7] => bar [8] => bar ) We changed 5 items

I hope this helps satisfy your curiosity

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2024-09-15 12:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The PerlMonks site front end has:





    Results (21 votes). Check out past polls.

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.