in reply to Running complex sed from perl
If you had a complex sed script that you were converting to perl, then you may want to use s2p. But your sed script is simply doing a global search and replace. It also looks like shell quoting may be muddying the waters.
In general, if you see a sed invocation like sed -e 's#pattern#replacement#', then your perl code should look something like[1]:
# Standard setup stuff and file handle opening goes here while (<THE_FILE_HANDLE>) { s#pattern#replacement#; }
So a simple example could be:
#!/usr/bin/perl use strict; use warnings; # Get and open the input and output files my $INFname = shift; open my $INFH, '<', $INFName or die "Can't open '$INFName' for input: +$!"; my $OUTFName = shift or die "Missing filename(s)!\n"; open my $OUFH, '>', $OUTFName or die "Can't open '$OUTFName' for outpu +t: $!"; # Do the search and replace while (<$INFH>) { s/foo/bar/g; print $OUFH $_; }
So all you really need to do is pick apart your regular expression, make sure you can express it in perl without getting any quoting bits mixed in, and you should be good to go.
Notes:
[1] You can even do it on the command line like the sed example, but I don't generally use one-liners.
[2] The code is untested, and you'll probably want to modify it in any case.
...roboticus
When your only tool is a hammer, all problems look like your thumb.
|
|---|