Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: Perl substitute

by Don Coyote (Pilgrim)
on Apr 15, 2013 at 13:52 UTC ( #1028743=note: print w/replies, xml ) Need Help??

in reply to Perl substitute

This will do what you need, however, you will need to adapt the untainting regex to your particular requirements. I was a little uncertain about processing a regex with backticks, so I used taintmode.

#!usr/bin/perl -Tw use warnings; use strict; opendir my $dh, './testdir/'; #assume all files, no sub dirs my @filelist = readdir($dh); close($dh); my $rep = qr'<>'; while (@filelist){ my $basefile = shift @filelist; next unless $basefile =~ m/^((\w+\s*)+\.(pl|txt))$/; $basefile = $1; my $pathfile = './testdir/'.$basefile; open (my $rfh, '<', $pathfile); my @filelines; while (<$rfh>){ $_ =~ s/$rep/\`<>\`/g; push @filelines, $_; } close($rfh); open (my $wfh, '>', $pathfile); while (@filelines){ my $line = shift @filelines; print $wfh $line; } close($wfh); } exit 0;

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (10)
As of 2016-10-27 14:53 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (365 votes). Check out past polls.