Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

ref() is not reporting correctly
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.

When $filespec is a string I get (correct) output that looks like this:
filespec = somefile.txt, filespec type =

When $filespec is an arrayref I get (incorrect) output that looks like this
out of the else block:
filespec = ARRAY(0x3c01b424), filespec type =

where I expect to see something like:
filespec = ARRAY(0x3c01b424), filespec type = ARRAY

Anybody see where I've gone wrong?

Thanks for the help!

richf


Report this thread to moderator Post Follow-up to this message
Old Post
Rich Fernandez
08-06-04 01:55 AM


Re: ref() is not reporting correctly
From: Rich Fernandez <rfernandez@arrow.com>
> 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
===== Jenda@Krynicky.cz === 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


Report this thread to moderator Post Follow-up to this message
Old Post
Jenda Krynicky
08-06-04 01:55 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL Beginners archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 04:38 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.