David,

Thank you very much for your help. I had tried to use the eval command, but I wasn't able to sort out the proper syntax.

Your solution works perfectly using my test raw data. I will be able to hook up the engine monitor later tonight so I can test with the real thing and see how much more CPU time this option will use. If this way uses too much CPU time, I will try the method suggested by Charles Clarkson.

Thanks to everyone for their assistance,

Kevin Horton


On 2-Feb-05, at 1:46 PM, David Van Ginneken wrote:

Kevin,

Would something like this work for you?

Main program:
-----------------------------------------
use strict;
my $data_time = 'date';
my $TACH = 'tach345';
my $MP = 'mp123';
our @array;
require 'config.pl';

foreach (@array) {
   eval 'print $' . $_ . ' . "\t"';
}
print "\n";

-----------------------------------------
config.pl contains the following

our @array = ('data_time', 'MP', 'TACH');




On Wed, 2 Feb 2005 10:34:35 -0800, Wagner, David --- Senior Programmer Analyst --- WGO <[EMAIL PROTECTED]> wrote:
On 2-Feb-05, at 1:09 PM, Wagner, David --- Senior Programmer Analyst
--- WGO wrote:

Kevin Horton wrote:
I'm a perl newbie working on a script to log data from a device that
sends more variables than I need to log.  I have a working prototype
script, with the list of variables to be logged hard-coded, which
means I need to edit the script any time I need to change the items
to be printed.

Now I want to extend the script to use a configuration file to define
the list of variables to be logged, and the order to write them to the
log file. I've been messing around with this for many hours, and I've
dug through the various perl man pages, plus Perl in a Nutshell, and
Programming Perl, but I'm not making any progress.


My working prototype script with the hard-coded list of variables
prints output with the following line:

print OUTPUT
"$data_time\t$TACH\t$MP\t$FUEL_FLOW\t$QTY\t$CHT1\t$CHT2\t$CHT3\t$CHT 4\ >> t$
EGT1\t$EGT2\t$EGT3\t$EGT4\t$OILT\t$OILP\t$VOLT\t$OAT\t$UNIT_TEMP\n";


I've got a config file that I read to create an array of variable
names that should be logged.  The first few items in @variable_list
are:

data_time
TACH
MP
FUEL_FLOW

I would greatly appreciate any hints on how I can use the data in
@variable_list to print just the variables I want.

Kevin, I would change it to a hash and then either use some type of
regex against the keys to get what you want to print out or bypass.


But, I also need to control the order the variables are printed. I
understood that if you access the keys in a hash the order you get them
is random. I guess I could create a hash with just the variables I
want, with the keys being numbers. I could then pull the variable for
each key in order. But, I still don't understand the syntax I need.
I.e. once I pull a variable name out of the hash, how do I print that
variable? I tried messing around with symbolic references, but I
couldn't get them to work.


Thanks,

Kevin

Then you sort the keys or make the hash a little more dynamic. You could do something like:

        $hash{key1}[0] = 1;     # how the data came in
        $hash{key1}[1] = 'value of key1';
        $hash{key2}[0] = 2;
        $hash{key2}[1] = 'value of key2';

        #
        #       Alpha sort on the keys of hash
        #
        foreach my $MyKey (sort keys %hash) {
                # now print or whatever
       }

#
# numeric sort off the first element of hash
#
foreach my $MyKey ( sort {$hash{$a}[0] <=> $hash{$a}[0]} keys %hash) {
# prints in numeric order
}


I believe there are even modules which will help keep the order, but seems like overkill to me.

Wags ;)


******************************************************* This message contains information that is confidential and proprietary to FedEx Freight or its affiliates. It is intended only for the recipient named and for the express purpose(s) described therein. Any other use is prohibited. *******************************************************

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>




--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to