Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Perl substitute

by Don Coyote (Monk)
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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2014-12-20 08:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (95 votes), past polls