Posted on 2007-01-02 06:20:37-08 by thaljef in response to 3944
Re: Beginners observations
Those are some really good questions. Fortunately, they do have answers...

To open a pipe with the 3-argument form of "open", you want to use '|-' or '-|' to indicate the mode. In your case, I think this should do the trick...

open my $LSTAC, '-|', "$lstac -m"

See `perldoc -f open` and `perldoc perlopentut` for all the gory details.

It is true that you can't make $_ lexical with "my". The best approach is to use a named iterator, instead of defaulting to $_ (also known as the "topic" or "scratch" variable). That way, the reader has a better idea what is actually in the iterator. For example...

foreach my $person (@population){ print $person }

If you absolutely insist on using $_ as your iterator, then you don't need to declare it at all...

foreach (@population) { print }

But using a named iterator (which is also recomended by Conway) will make your code much more readable.

Hope that helps. Happy New Year!

-Jeff
Direct Responses: Write a response
Perl Weekly newsletter
A free weekly newsletter for people who are busy to read all the blogs. click here to check it out.