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

Getting more output than I want!

Status
Not open for further replies.

rbold

Programmer
Jul 8, 2002
6
0
0
GB
Hi,
New to perl so I hope this isn't a dumb one, I've looked but I can't find an explanation for this:
I've got a script to analyse a win2k directory listing and produce a list of the number of files and total size for each file type. The bit that prints the output is:
Code:
foreach $extension(%filetypeinfo){
		print("$extension \t $filetypeinfo{$extension}->[0] \t $filetypeinfo{$extension}->[1]\n");
	}
This is giving the result I expected (eg "doc 3 10000") but after every line it's printing a line containing something like "ARRAY(0x1a54ae0)". Any idea why these are appearing and how I can get rid of them?
Thanks in advance,
Rob
 
You're cycling through a hash not an array
and the ARRAY(0x1a54ae0) is the array the hash is referrring to ... I think

Can you post more code to give context

--Paul
 
I'm not too sure what is going on here except that somewhere you are accessing and printing an array reference (i.e. the referencer itself and not the array).

Try someting like this;

while (($extension, @rest) = each %filetypeinfo) {

print $extension . "\n";

foreach (@rest) {

print $_ . "\n";

}

}

This will examine your hash values and tell you exactly what you have. If (from the foreach loop you still get a value "ARRAY(hex number) then you have an anonymous array within the @rest array.


It doesn't really answer your question but at least you will see what is going on.
 
Thanks for the replies.
PaulTEG, yep, it is a hash I'm trying to cycle through - the hash is (should be!) keyed by the file extension (eg doc) and it should contain a load of two element arrays: element[0] should have the number of files of type "doc" and element[1] should have the total size of all these files.
GReadey, I used a modified version of the code you posted and it works fine! What I ended up with is :
Code:
while (($extension, @rest) = each %filetypeinfo){
	print $extension . "\t";
	foreach (@rest){
		print $_->[0] . "\t" . $_->[1] . "\n";
	}
}
Thanks again,
Rob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top