Priti24 has asked for the wisdom of the Perl Monks concerning the following question:

I have a folder named like lib and this folder lib having multiple files and i have to remove one variable from all of files in folder lib

All files having lots of subroutines but also have a subroutine common. And i have to remove 1 argument of that subroutine from all files. Is this possible to delete this argument using a command or i'll have to do this manually

sub getSolrDocuments{ my ($self,$records,$query_string) = @_; my $utils = Knimbus::Connectors::Utils->new; my $a = $utils->addFieldsToSolrDocuments($records, q{$a}, q{$b}, +q{$c}, q{$d}, $query_string); return $a; }

i have to remove 3rd argument($b) from addFieldsToSolrDocuments . value of $b is different in all files but position is same. Means i have to remove 3rd argument from all files<\p> is this possble using sed and grep command? Plz help me out......

  • Comment on How to remove a variable from a folder having lots of pm file in it using a command
  • Download Code

Replies are listed 'Best First'.
Re: How to remove a variable from a folder having lots of pm file in it using a command
by ikegami (Patriarch) on Jan 13, 2012 at 06:59 UTC
    find lib -type f -name '*.pm' -exec \ perl -i~ -pe's/addFieldsToSolrDocuments\([^,]*,[^,]*\K,[^,]*//' {} +

    This creates a backup of each file foo.pm -> foo.pm~. Be sure to review the differences if any. It's not very precise.

    (You can combine the two lines by removing the "\".)

      Thank u very much