in reply to script debug
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 :)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re (tilly) 2: script debug
by tilly (Archbishop) on Aug 19, 2001 at 07:14 UTC | |
by jryan (Vicar) on Aug 19, 2001 at 21:45 UTC | |
by tilly (Archbishop) on Aug 19, 2001 at 22:19 UTC | |
|
Re: Re: script debug
by jryan (Vicar) on Aug 19, 2001 at 00:42 UTC |