in reply to providing filenames dynamically
If so, then consider this code.
die "Usage $0 remove_regex replace_regex" if (@ARGV !=2); my ($remove, $replace) = @ARGV; while(<stdin>) { s/$remove/$replace/g; print; }
@ARGV should be considered a "read only" variable like in other languages.
Here use like: replace.pl a b <infile >outfile
If you want to pass filenames on command line, then same idea with getting values of @ARGV, but you will have to use a open() statement to read or write them.
|
|---|