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

Reading in a file path from a file results in weirdness 3

Status
Not open for further replies.

travs69

MIS
Dec 21, 2006
1,431
US
The following code is printing out:
Code:
D:/temp
 2/temp
/test.rtf
when I would have expected
Code:
D:/temp
D:/temp 2
D:/temp/test.rtf


config.txt contains one line
Code:
temp_dir=D:/temp

Code:
use strict;

my %config;
my $config_file = 'config.txt';
#Get the config data
open(CONFIG, "<$config_file");
while(<CONFIG>){
	chomp;
	my ($k, $v) = split(/\s*\=\s*/, $_,2);
	$k = lc $k;
	$config{$k} = $v;
}
close(CONFIG);


print "$config{temp_dir}\n";
print "$config{temp_dir} 2\n";
my $tmp_file = "$config{temp_dir}/test.rtf";
print "$tmp_file\n";
exit;

This really has me stumped as I'm not sure if I'm missing something obvious or what.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
Works as you expected for me in Unix and Windows (Strawberry Perl). What OS and Perl implementation are you using?

Are you certain there are no dodgy invisible characters in that input file?

Annihilannic.
 
windows 7 & 2003, strawberry perl 5.12. I'll re-create that input file, perhaps something strange is going on there.

Thank you for checking!

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
Hey travs,

I presume that you've hopefully already solved your problem by now. I'd start by printing the imported data hash to see if the values actually correspond to what you expect.

Code:
use Data::Dumper;
print Dumper(\%config);

I don't see anything obviously wrong with the code you provided though, and it also worked on my system as expected.

- Miller
 
Miller,
Thanks I haven't actually had time to get back to this side project yet as it has been a crazy/busy week but truthfully I didn't even think about dumping it. I'll play with it and let you guys know what's going on.



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top