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 dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question with open file 2

Status
Not open for further replies.

zhenning

Technical User
Sep 22, 2005
50
CA
Hi,

I can open a file using "open(F,"19150009212005.txt");"
I also one variable : $date=09212005
How can I open the file using this variable? I tried:
open(F,"191500/$date/.txt"); It did not work.

Thanks
zhenning
 
it's because it starts with a zero! if it didn't it would work.

you will have to enclose in speech marks (either double or single) $date = '09212005';


Kind Regards
Duncan
 
Your string would interpolate as: "191500/9212005/.txt" so not only are you miss the zero but you have a filename of ".txt". Is that really what you want?
I think not.
Code:
my $date     = "09212005";
my $pathname = "191500/$date.txt";
open F, $pathname or die "Failed to open $pathname";


Trojan.
 
Sorry I did not address clearly. Folloing is my code:

my $date=@data[1]; (@data[1] contains "09222005" got from web CGI)
my $pathname = "191500$date.txt";
print "$date<br>\n";
print "$pathname<br>\n";
open(F,$pathname);

It did not work. But I got the print outputs;
09222005
19150009222005.txt
Why I still can not open this file?

But the following codes worked:
my $date = "09222005";
my $pathname = "191500$date.txt";
open(F,$pathname);

The only different is at "my $date=@data[1];"

thanks
 
The file I want to open is 19150009222005.txt
 
Sorry it was some problem with the file. the code from Trojan worked. Thanks!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top