http://qs1969.pair.com?node_id=1233764


in reply to Re^2: Parsing Problems
in thread Parsing Problems

I would really, really suggest replacing the eval() with something like

my $name_space = "modes::$ARGV[2]"; my $code = $name_space->can( 'flex' ) or die "$name_space does not implement flex()"; $temp = $code->( $line );

This is on the hypothesis that in fat-fingering in your example you reversed the slope of a back slash.

When obscure code fails it is really hard to debug. I infer from your eval() example that what you are trying to do is this:

  1. Run a script whose second argument is the name of a processor for your input.
  2. Process each line of the file using a subroutine named flex() in a Perl module named "modes::$ARGV[2]"
  3. This module has already been loaded.

If these are correct, the above code should implement it in an easier-to-read-and-debug manner. The three statements compute the name of the module, get the address of the subroutine in that module (failing if it can not be found), and call the subroutine, passing it the line from the file, and storing the result in $temp.

This is off-topic for your question, but all your Perl should have use strict; and use warnings; near the top of the file. If your script does not do this, all sorts of bugs could lurk. Of course, if you just slam these into a legacy script it may find all sorts of things -- more than you are able to fix in one sitting. But it's worth a try -- one of the warnings/errors may tell you what your problem is.