>>>>> "JLC" == Joseph L Casale <jcas...@activenetwerx.com> writes:

  JLC> I get a page full of output from a command passed into a
  JLC> Net::Telnet session that as per the cpan example is stored in
  JLC> $output. I then want to call a sub passing $output into it, that
  JLC> matches a string against each line, and sets a a var to "OK" if
  JLC> the match is successful.

  JLC> All is well, but I am unclear on the correct way to loop through
  JLC> each line in $output, when I simply print it, it appears over
  JLC> several lines in the terminal.

  JLC> When I run it into my sub, its being treated as one line?

you need to show how you call this sub and its input. there is no way to
diagnose it from just this code.

  JLC> sub parse_output {
  JLC>         foreach (@_) {

use a named variable with foreach loops. sure some docs and examples
show using the default $_ but it can have problems with action at a
distance. also a name makes the code read better.

  JLC>                 chomp($_);

if you do use $_, there is no need to pass it to many ops including
chomp. chomp by itself does the same thing.

  JLC>                 print "Line: $_\n";
  JLC>                 if ( $_ =~ /$match/ ) {

again, m// will match against $_ so either don't bind to it or bind to a
named variable (or some expression).

and where does $match get set? it must be from outside the sub so it is
a global. bad!

  JLC>                         $status = "OK";

same with status. either declare it locally and return it or do
something else but don't set globals just to mark something as ok

  JLC>                         next;
  JLC>                 }
  JLC>         }
  JLC> }

  JLC> parse_output($output);

  JLC> It only prints one "Line:" although it works as it sets $status?

works in what way? if i pass it one line with something that matches, it
will pass that 'test'.

  JLC> What am I missing?

more code and data. use Data::Dumper to show exactly what you are
passing in.

uri

-- 
Uri Guttman  ------  u...@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to