Quoting Tal Cohen <[EMAIL PROTECTED]>:
> On my development system it works fine (SunOS XXX 5.8 Generic_117350-24
> sun4u sparc SUNW,Sun-Fire-880), however I copied it onto another system
> (SunOS XXX 5.8 Generic_117350-26 sun4u sparc SUNW,Sun-Fire) and all of a
> sudden, the script will only work if at some point in the function I print
> to STDERR one of the values of the internal hash (see below).

This suggests to me that you are doing something wrong with the hash, 
although I
cannot tell immediately from the sparse example.

>            %hash = function1(%hash);
> .....
> sub function1 {
>
>                        my %internalHash = @_;
> .....

Well, that should work okay if you are only passing a hash to the 
function.  But
if you pass any other arguments, you will get into trouble.  Perl flattens
arrays and hashes into lists when passing arguments to functions, so the
following call will fail in seemingly mysterious ways:
    %hash = function1(%hash, "a string", "another string");

You may be safer passing a reference to the hash instead, as in the following
code:
#############################################################################
use strict;
use warnings;

use Data::Dumper;

my %hash = (
            apple  => "red",
            banana => "yellow",
            cherry => "red",
            date   => "brown",
           );

sub test1 {
    # Will work only if called with exactly one hash
    print "In test 1...\n";
    my %internalHash = @_;
    print Dumper \%internalHash;
}

sub test2 {
    # Passing a reference works fine
    print "In test 2...\n";
    my ($ref) = @_;
    my %internalHash = %$ref;
    print Dumper \%internalHash;
}

sub test3 {
    # Does not work as one might expect; $scalar is never set
    print "In test 3...\n";
    my (%internalHash, $scalar) = @_;
    print Dumper \%internalHash, \$scalar;
}

sub test4 {
    # Passing a reference works fine; $scalar is set properly
    print "In test 4...\n";
    my ($ref, $scalar) = @_;
    my %internalHash = %$ref;
    print Dumper \%internalHash, \$scalar;
}

test1(%hash);
test2(\%hash);
test3(%hash, "test");
test4(\%hash, "test");
#############################################################################

Notice that in test3, the "test" string gets assigned as part of the hash.  If
you happen to do something similar (although not shown in your example), this
could be your problem.

+ Richard



 
_______________________________________________
Boston-pm mailing list
[email protected]
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to