Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

How to remove a variable from a folder having lots of pm file in it using a command

by Priti24 (Novice)
on Jan 13, 2012 at 06:49 UTC ( #947697=perlquestion: print w/ replies, xml ) Need Help??
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
Re: How to remove a variable from a folder having lots of pm file in it using a command
by ikegami (Pope) 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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (13)
As of 2014-12-19 20:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

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





    Results (91 votes), past polls