gri6507 has asked for the wisdom of the Perl Monks concerning the following question:

Fellow Monks,

I post this question not because I don't want to do the work, but because I don't want to reinvent the wheel for the work that I would have to do.

My task is this: I need to parse out /etc/remote to find the device tag (i.e. dv=/dev/term/a) for a particular handle. The problem is that sometimes the handle is listed only as a compatibility link (i.e. tc=sysa) and then I have to find the device tag for the sysa handle (or keep on recursing ad infinitum until a device tag is found). For example, having the following /etc/remote

MyPort:\ :dv=/dev/term/b:br#9600:el=^C^S^Q^U^D:ie=%$:oe=^D: sysa:\ :dv=/dev/term/a:br#9600:el=^C^S^Q^U^D:ie=%$:oe=^D: MyAlias:tc=sysa

the device for 'MyPort' is /dev/term/b, and the device for 'MyAlias' is /dev/term/a.

Does anyone know if something like this exists? It seems like I would be reinventing the wheel if I rolled my own code. Thanks.

Replies are listed 'Best First'.
Re: Parsing /etc/remote
by merlyn (Sage) on Nov 29, 2005 at 14:59 UTC
      Thanks merlyn, it seems to almost work.
      use strict; use warnings; use English; use Term::Cap; my $PortName = 'MyPort'; if (scalar(@ARGV)) { $PortName = $ARGV[0]; } $ENV{TERMPATH} = '/etc/remote'; my $terminal = Tgetent Term::Cap { TERM => $PortName, OSPEED => 9600}; print $terminal->Tgoto('dv', "", "",);

      So, when called with MyPort parameter, it gives me /dev/term/b as expected. However, when called with MyAlias parameter, it does not return anything (but no errors either). What am I missing?

        Although it doesn't seem to be required by the file format in the examples and man pages I've looked at, if the end of the alias line is terminated with a colon it will work as expected.