Path: utzoo!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!samsung!usc!elroy.jpl.nasa.gov!jpl-devvax!lwall From: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Newsgroups: comp.lang.perl Subject: Re: dynamic formats Message-ID: <6794@jpl-devvax.JPL.NASA.GOV> Date: 15 Jan 90 20:59:15 GMT References: Reply-To: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Organization: Jet Propulsion Laboratory, Pasadena, CA Lines: 36 In article Johan Vromans writes: : A format specification is apparently of a static nature. Is it : possible to dynamically create formats, e.g. : : eval('format=\n@...\n$...\n.'); : : Or to switch formats: : : if (...) { : format = : ... : . : } else { : format = : ... : . : } A format is a non-executable compile-time declaration, just like a subroutine declaration, so the latter doesn't work. The eval trick ought to work, but doesn't. : Currently the only way I can think of, is creating a temporary file : with the format spec in it, and 'do'ing it. That is the only way to do it currently. The format parser only knows how to parse things that come in one line at a time. Strings which are eval'ed are already all there, so the format parser gets confused after the first line. This restriction should go away someday. It's not technically hard--it'll just take some elbow grease. The load_format() routine is one of the oldest in perl, and antedates eval by many moons. Another thing you should be aware of is that redefining a format doesn't currently free the storage for the old one. Larry