Perl, Array called by scalar doesn't work in foreach loop.

Posted by foxhop on Stack Overflow See other posts from Stack Overflow or by foxhop
Published on 2010-05-07T17:05:47Z Indexed on 2010/05/07 17:08 UTC
Read the original article Hit count: 207

Filed under:
|
|
|

This code outputs the scalars in the row array properly:

  $line = "This is my favorite test";
  @row = split(/ /, $line);

  print $row[0];
  print $row[1];

The same code inside a foreach loop doesn't print any scalar values:

  foreach $line (@lines){
      @row = split(/ /, $line);
      print $row[0];
      print $row[1];
  }

What could cause this to happen?

  I am new to perl coming from python.  I need to learn perl for my new position.

© Stack Overflow or respective owner

Related posts about perl

Related posts about array