#!/usr/bin/env perl use warnings; use strict; use Getopt::Std; my %opt; getopts('he:',\%opt); $opt{'h'} and &help; my $expr = $opt{'e'} or &help('no -e option specified'); @ARGV or &help('no filename(s) specified'); sub help { warn join(' ', @_), "\n\n" if @_; print STDERR < dbdump_foo.sql prefixes all table names with the string foo_. ZZ exit(!!@_); } foreach my $f (@ARGV) { if (!open(F, '<', $f)) { warn "cannot read file, skipped: $f\n"; next; } my @f = ; close(F); my %table_name = map { $_ => 1 } map { /^\s*CREATE TABLE `([^`]+)`/i ? ($1) : () } @f; #warn "table names: ", join(', ', keys %table_name), "\n"; foreach my $l (@f) { my @l = split(/`/, $l, -1); if (@l > 2) { my @newl = map { if (defined $table_name{$_}) { eval $expr; }; $_ } @l[1 .. @l-2]; splice(@l, 1, @l-2, @newl); } print join('`', @l); } }