From: Rich Fernandez <[EMAIL PROTECTED]>
> I have a hash which looks something like this:
> %hash = ( foo => 'a', bar => 'b', filespec => "$filespec");
>
> I also have a function which includes the following code:
>
> # Figure out if we were passed a filename or an array ref
> if ( exists $info -> {filespec} ) {
>
> $filespec = $info -> {filespec};
>
> if ( ref($filespec) eq "ARRAY" ) {
> #process filenames from array;
> print "filespec = $filespec, filespec type = ",
> ref($filespec),
> "\n";
> print "Processing an array\n";
> } else {
> print "Processing single filename: $filespec\n";
> print "filespec = $filespec, filespec type = ",
> ref($filespec),
> "\n";
> }
> } else {
> die "No Files passed in for processing!\n";
> }
>
> __END__
>
>
> I'm passing a reference to the hash into the function. The function is
> actually contained in a module I'm developing, but I don't think that
> should matter?
>
> When processing gets to this part of the code the "if" condition
> always fails Instead it always processes the "else" block.
Now you know why writing
"$variable"
is a bad idea.
You forced Perl to stringify the reference, therefore the $info-
>{filespec} is not a reference anymore, it's string
"ARRAY(0x3c01b424)".
Jenda
===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>