in reply to script debug

Hi, Anonymous Monk. It looks like this is a continuation to this previous question. Is it? You haven't really said what the problem is -- "this won't work" is a pretty broad problem statement -- but assuming you're the same person, working on the same problem, then maybe some suggestions are in order.

First, you're accumulating lines in memory and not doing anything with them. If you're expecting some output, a print or something similar is necessary. Second, there's no real point collecting lines in memory if all you're going to do is copy them out verbatim. So, as a first cut, I suggest this transformation:

open (MAN, "/usr/bin/man ssh |"); my $printing_on = 0; # If true, print what you see while (<MAN>) { s/^\s+//g; # if you like; could be omitted. if ($_ eq "NAME\n") # constant string; no regexp needed { $printing_on = 1; } elsif ($_ eq "SYNOPSIS\n") { exit; # we're done } print if $printing_on; }
TIMTOWDI, but this is a simple way to print lines between "NAME" and "SYNOPSIS".

I'm using the ESP::Telepathy module a lot without knowing your intentions, so I'll stop here. Please provide a little more detail about what "won't work" means, and you should get a better answer.

HTH

Replies are listed 'Best First'.
Re: Re: script debug
by faure (Sexton) on Aug 19, 2001 at 02:01 UTC
    Just because I learned the flip-flop recently:
    #!/usr/bin/perl -n print if (/NAME/../SYNOPSIS/); # then: man ls | this_script.pl
    OR maybe you have other plans for the text...
    #!/usr/bin/perl $cmd = shift; open MAN, "man - $cmd |"; while (<MAN>) { $section = $_ if /^[ A-Z]+$/; push @lines, $_ if $section =~ /NAME|DESCRIPTION/; } do_something_else_with(@lines); # perhaps get rid of the page headers/footers