On 3/21/07, Alan Campbell <[EMAIL PROTECTED]> wrote:
I'm trying to use cmd line perl -e to do some fairly basic sed-style find/replace.
Why don't you just use sed for that, if you're not doing the main program in Perl? Maybe I'm misunderstanding you, but it sounds like you're saying that you're writing shell scripts in which you're frequently calling 'perl -e'. That's like buying a Hefty bag to carry your Louis Vuitton.
Was able to get first few things working but stumbled when I wanted to do the following....
I won't quote "the following"; I'll just say that It took me about twenty minutes of puzzling before I realized what you're trying to do. I think. Your program is doing something resembling code coverage checking, trying to find out which items in a list are not mentioned in a number of files. Am I close? Okay, I will quote one loop:
for (my $ctr = 0; $ctr < scalar(@syms_info); $ctr++) { $syms_info[$ctr] = "\n" if ($syms_info[$ctr] =~ $bss_sym); }
This is what a foreach loop is made to do; if you recode it as a foreach, you'll only have to mention 'syms_info' once, instead of three times, and you won't need $ctr or the scalar operator at all. Also, $bss_sym is from a line of input; is the input in the form of a regular expression? If not, probably you want to use 'eq' (string equality) instead of '=~' (pattern matching). ....But I'm unclear why you want to use a newline to represent matched items. Why not remove them from the list entirely? I'm sure I'm missing something. If removing would work, consider grep instead of the foreach loop.
...but I'd like a (somewhat convoluted perhaps) 1-liner w/ perl -e cmd-liner.
Why do you want a 'perl -e' program, as opposed to an ordinary perl program? It's not going to be easier to read, write, understand, maintain, or debug. It's not going to run faster. It's always cool to condense a program to a one-liner. However, this sounds like a program that needs to be improved in the realm of correctness, not coolness. Good luck with your project! --Tom Phoenix Stonehenge Perl Training -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/