in reply to Platform Dependence observed in Perl - Hash keys have different format

Your "workaround" means with 100% certainty the problem is your code

Perl doesn't magically insert junk into hash keys that requires a programmer to guess at hash keys, that would be insane

  • Comment on Re: Platform Dependence observed in Perl - Hash keys have different format

Replies are listed 'Best First'.
Re^2: Platform Dependence observed in Perl - Hash keys have different format
by rkabhi (Acolyte) on Mar 03, 2017 at 09:19 UTC

    Thanks for the response.

    Could you please throw some light on why same code for defining a hash would yield hash key as only Key on one system and as "Key" on another? What could be possibly wrong with the code? I have added the subroutine in my post which actually defines the hash %pinList. On this hash I observed unexpected key format on different machine. Am I defining the hash incorrectly?

      Without seeing your input data, this is hard to tell. Your code seems to do some wonky CSV parsing here:

      my @pinWords = (); if($line =~ m/.*?,.*?,.*/){ @pinWords = split(',',$line); } elsif($line =~ m/.*?;.*?;.*/){ @pinWords = split(';',$line); }

      and then you write that value directly into the hash:

      ... $pin =~ s/^\s*|\s*$//g; #To remove all leading and t +railing blanks ... $pinList{$pin} = [$pinMaxSDV,$pinMinSDV];

      So my guess is that sometimes your CSV input data has double quotes around the pin and sometimes it does not.

      See Text::CSV_XS for CSV parsing.

        Sorry for my delayed response again.

        The issue was only because of soffice putting string without double quotes in my system and putting with double quotes on another system. So my csv file looked like below:

        On my(first) machine:

        key,value

        On Second Machine

        "key","value"

        Hi huck, I am not sure how to check what you mentioned. Sorry as I am not familiar with accessing values from modules. I tried below code and it gave error as mentioned.

        use strict; use warnings; print "\nUseqq = " . Data::Dumper::Useqq . "\n";\ print "\nQuotekeys = " . Data::Dumper::Quotekeys . "\n"; use Data::Dumper qw(Dumper);

        The error with above code: Useless use of single ref constructor in void context at test_dumper.pl line 6. Bareword "Data::Dumper::Useqq" not allowed while "strict subs" in use at test_dumper.pl line 5. Bareword "Data::Dumper::Quotekeys" not allowed while "strict subs" in use at test_dumper.pl line 6. Execution of test_dumper.pl aborted due to compilation errors.