key as filehandle error

From: Bill (fult01_at_yahoo.com)
Date: 09/01/04


Date: 31 Aug 2004 17:04:42 -0700

I'm trying to use a hash key as a filehandle like so.

#!/usr/local/bin/perl
use strict;

my %buf = (
   'F00' => 'foo.dat'
);

&open_files();

exit 0;

sub open_files {
    while(my($k,$v)=each(%buf)) {
        open ($k, ">$v") || die $!;
    }
}

But, I get the following error:
Can't use string ("F00") as a symbol ref while "strict refs" in use at
./try.pl line 14.

I've tried varouis things like \*FOO, *$k ... nothing seems to work.
UNLESS I take out strict, then it works.

Anyone know what's happening here.

Thanks,
Bill



Relevant Pages

  • File handling with subroutines and references
    ... will efficiently read/write files. ... FILEHANDLE to prevent any conflicts during processing (Is this a good ... use strict; use warnings; ... sub file_close { ...
    (comp.lang.perl.misc)
  • Re: Right way to wrap FileHandle?
    ... On Wed, 1 Oct 2003, David Coppit wrote: ... functions exported by FileHandle, and use an AUTOLOAD in the main package ... sub AUTOLOAD ... no strict 'refs'; ...
    (comp.lang.perl.misc)
  • Right way to wrap FileHandle?
    ... I'd like to write FileHandle::Unget, a version of FileHandle whose ungetc ... use strict; ... sub AUTOLOAD ...
    (comp.lang.perl.misc)
  • Re: Filehandles Referenced with a Variable
    ... solution that does not require me to comment out 'use strict'. ... Only because $typeis not really a typeglob. ... : but it gives error: String found where operator expected. ... Can't use string as a symbol ref while "strict refs" in use ...
    (comp.lang.perl.misc)
  • Re: new in CGI::Session::Driver::postgredsql nonexisting
    ... i would suggest you turn on strict and warnings in this example.. ... or die "cannot prepare"; ... use CGI ':standard'; ... sub makeHTML ...
    (comp.lang.perl.misc)