Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

strict and variable

Status
Not open for further replies.

przytulaguy

Technical User
Joined
Jul 24, 2006
Messages
8
Location
BE
I am using this
use strict
$var1=0
$handle="DEL".$var1
I wanted to use
opendir($hanle,"xxxxx") or die ....
..
I get Can't use string ("DEL0") as a symbol ref while "strict refs"
Is there a way to use a variable instead of a fix DIRHANDLE as I want to open multi handles and do not know in advance how many ?
Thanks for all info
Best Regards, Guy Przytula
 
Use the standard Filehandle module.
Code:
           use FileHandle;

           my $fh = new FileHandle;
           if ($fh->open("< filename")) {
               print <$fh>;
               $fh->close;
           }
 
thanks for the update
but this is not to open a file but open a directory and read all filenames/dates
Best Regards, Guy Przytula
 
DirHandle, then:
Code:
           use DirHandle;
           $d = new DirHandle ".";
           if (defined $d) {
               while (defined($_ = $d->read)) { something($_); }
               $d->rewind;
               while (defined($_ = $d->read)) { something_else($_); }
               undef $d;
           }
 
use strict
$var1=0
$handle="DEL".$var1

the code you have is not even correct, you have to declare your variables with "my" if you are using strict.

Code:
use strict
my $var1 = '0';
my $handle = "DEL$var1";
opendir($handle,"xxxxx") or die ....
 
Thanks for all update : but even a small program like
F:\TRANSFER>test.pl
Can't use string ("DEL0") as a symbol ref while "strict refs" in use at F:\TRANSFER\test.pl line 5.

F:\TRANSFER>type test.pl
#! perl -w
use strict;
my $var1 = '0';
my $handle = "DEL$var1";
opendir($handle,"d:\\db2scripts\tmp") or die "died" ;
--
returns the error
Any idea ?
Best Regards, Guy Przytula
 
Use a hash instead:
Code:
use strict;
use warnings;

my %dir_handle;
opendir($dir_handle{'test'}, 'c:/test/') or die;

while ($_ = readdir $dir_handle{'test'}) {
    print $_, "\n";
}
 
I used this :
use DirHandle;
$d = new DirHandle ".";
and this corrected all my problems

Thanks for all info/help
Best Regards, Guy Przytula
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top