Newsgroup: comp.lang.perl


Article 7603 of comp.lang.perl:
Newsgroups: comp.lang.perl
Path: icdoc!dds
From: dds@doc.ic.ac.uk (Diomidis Spinellis)
Subject: Re: Is there a way to build a format picture dynamically?
Nntp-Posting-Host: speedy.doc.ic.ac.uk
Message-ID: <1991Dec13.155756.10409@doc.ic.ac.uk>
Organization: Dept. of Computing, Imperial College, London, England
Date: Fri, 13 Dec 1991 15:57:56 GMT
References: <1991Dec13.101335.22869@ircam.fr>
Lines: 28
Content-Length: 977
In article <1991Dec13.101335.22869@ircam.fr> fingerhu@ircam.fr (Michel Fingerhut) writes:
>Hello -- I want to gather statistics from a variable number of local hosts
>(e.g., depending on which one is up) and output them with "write".  However
>I don't see how to build the "format" pictures at run time depending
>on the number (and names, etc...) of those hosts.  Any suggestion?

Use eval.  Create a string with the format you want and run eval on
it.  As a simple example, consider having the date, part of the format
specifier:

$date=`date`;
$format = "
format hosts =
$date
@<<<<<<<<<<<<<< @|||||||| @<<<<<<<
\$name,		\$uptime,  \$room
.
";
eval $format;
$~=hosts;
$name='foo';$uptime=12;$room=429;
write; write;

Diomidis
-- 
Diomidis Spinellis                  Internet:                 dds@doc.ic.ac.uk
Department of Computing             UUCP:                    ...!ukc!icdoc!dds
Imperial College, London SW7        #include "/dev/tty"




Newsgroup comp.lang.perl contents
Newsgroup list
Diomidis Spinellis home page

Creative Commons License Unless otherwise expressly stated, all original material on this page created by Diomidis Spinellis is licensed under a Creative Commons Attribution-Share Alike 3.0 Greece License.