Hehe... first of all it would be helpful if you told us what you wanted your program to do :) It seemed like you wanted to go through the man and pull out the section between the NAME and the SYNOPSIS. First, a few bugs in your program (I have them listed with comments) :

# Im not sure if this pipe will open; # I'm not on a linux machine right now # so I'll just trust that this works. open (MAN, "/usr/bin/man ssh |"); while (<MAN>) { s/^\s+//g; push(@ml,$_); } # what is this loop supposed to do? # line isnt used anywhere else in the loop and # you aren't modifying @ml at all... foreach $line (@ml) { $line =~s/\n$//; $line =~s/^\n//; $line =~s/^\s+//; } for ($x=0; $x<=45; $x++) { if ($ml[$x]=~/NAME/) { while($ml[$x] !~/SYNOPSIS/) { # forgotten semicolon $nl .= $ml[$x] } } }

Heres what I did to "fix" it:

open (MAN, "/usr/bin/man ssh |"); while (<MAN>) { s/^\s+//g; push(@ml,$_); } # apply the substitutions to each element of @ml map (s/\n$//, @ml); map (s/^\n//, @ml); map (s/^\s+//, @ml); for ($x=0; $x<@ml; $x++) { if ($ml[$x] =~ /NAME/) { # new loop starting at one element past # the current, appending the current line # to $nl. Stops when SYNOPSIS is encountered for ($x++; $ml[$x] !~ /SYNOPSIS/; $x++) { $nl .= $ml[$x]; } } }

Well, there ya go. Of course, I could have completely misunderstood what you wanted your program to do... and if thats the case... I'm sure I'll get laughed at :)


In reply to Re: script debug by jryan
in thread script debug by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.