CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Intermediate:
Undefined Format


New User

Jan 3, 2012, 5:17 AM

Post #1 of 3 (1377 views)
Undefined Format Can't Post


I have a very simple file:

use strict;
use format;

my $foo = 2;

format LIST =

open(FILE, ">foo.txt");
$~ = 'LIST';
print FILE "hello?";
write FILE;


For whatever, reason I am getting the following error message:
Undefined format "FILE" called at ./ line 16.

I am using Perl version 5.005_03 built for x85_64-linux.
I also get this error when running version 5.10.1 built for i686-cygwin-thread-multi-64int.

The odd thing is that it prints to the file using "print" just fine, but it cannot perform the "write". So, I know the problem is not with the file.
When I change the FILE to STDOUT, it prints to the screen successfully, so I know the problem is not with the format.

It seems to be only when I attempt to write a format to a file that there is a problem.

Any ideas? Thanks in advance.


Jan 3, 2012, 7:03 AM

Post #2 of 3 (1374 views)
Re: [pmkenned] Undefined Format [In reply to] Can't Post

(1) You didn't indicate, which line is line 16 in your listing.

(2) What is "use format" supposed to do?

(3) Always put "use warnings" in your code.


Jan 3, 2012, 7:47 AM

Post #3 of 3 (1372 views)
Re: [pmkenned] Undefined Format [In reply to] Can't Post

$~ only works for the selected device. STDOUT is the default selection. That is why your script works for STDOUT. The easy fix is to change the name of the format to FILE.
Good Luck,


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives