Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

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;

Comment on Re: Perl substitute
Download Code

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 cooling their heels in the Monastery: (9)
As of 2016-02-08 22:27 GMT
Find Nodes?
    Voting Booth?

    How many photographs, souvenirs, artworks, trophies or other decorative objects are displayed in your home?

    Results (286 votes), past polls