Tags:
create new tag
view all tags

SID-02223: Spreadsheet Plugin - LIST2HASH Empty List Entries

Status: Answered Answered TWiki version: 6.0.1 Perl version:
Category: SpreadSheetPlugin Server OS: Last update: 9 years ago

This is a continuation of my learning hashes in: SID-02210

I have created a hash and passed that hash into a variable using SetGetPlugin:

%SET{ "FarmAnimals" value="%CALCULATE{$HASH2LIST(FarmAnimalHash)}%" remember="1"}%

Retrieving the hash using:

%GET{"FarmAnimals"}%

Results in the following output:

Cow, milk, Horse, wagon, Lobster, ,Chicken, eggs
Notice that the hash for Lobster is blank. This is intentional.

I would now like to convert the list shown above to a hash.

%CALCULATE{$LIST2HASH(FarmAnimalHash, %GET{ "FarmAnimals"}%)}%

The result is that the hash created ignores the desired empty value for Lobster in the hash.

Expected output of

%CALCULATE{$GETHASH(FarmAnimalHash, Lobster)}%
is blank however actual output is Chicken.

Are there any recommendations on how I could solve this?

-- Jani Hamalainen - 2016-07-04

Discussion and Answer

I've taken a stab (with lots of help) at modifying SpreadSheetPlugin by changing the code as indicated below.

The desire is that LIST2HASH accommodates an empty value(s). It seems logical that if SETHASH allows for keys to have an empty value it would make sense that changing a list to a hash allows the same.

sub _getList
{
    my( $theAttr ) = @_;

    my @list = ();

   foreach( split( /,\s*/, $theAttr, -1 ) ) {  #Addition of LIMIT (-1): capture case when last entry in a list is blank.
        if( m/\s*R([0-9]+)\:C([0-9]+)\s*\.\.+\s*R([0-9]+)\:C([0-9]+)/ ) {
            # table range
            push( @list, _getTableRange( $_ ) );
        } else {
            # list item
            if ($_ eq "") { #Addition of IF - do not send blank to split because it gets removed.
               push @list, $_; # split portion is eliminated to preserve the blank.
            } else {
               push( @list, split( /\s*,\s*/, $_ ) ); 
            }
         }
    }
    return @list;  
}

Disclaimer: There's probably better ways of accomplishing what I'm after and there may be errors / effects that I do not realize. Just hoping to provide a starting point and maybe good code could be implemented into the plugin.

-- Jani Hamalainen - 2016-07-05

Thank you Jani for reporting and for the proposed fix. This bug is tracked at TWikibug:Item7746

-- Peter Thoeny - 2016-07-06

This is now fixed a bit differently, test cases have been updated as well to test for empty values.

The SpreadSheetPlugin is updated as well for download/update.

-- Peter Thoeny - 2016-07-06

Thanks a lot Peter!

-- Jani Hamalainen - 2016-07-06

      Change status to:
ALERT! If you answer a question - or someone answered one of your questions - please remember to edit the page and set the status to answered. The status selector is below the edit box.
SupportForm
Status Answered
Title Spreadsheet Plugin - LIST2HASH Empty List Entries
SupportCategory SpreadSheetPlugin
TWiki version 6.0.1
Server OS

Web server

Perl version

Browser & version

Edit | Attach | Watch | Print version | History: r5 < r4 < r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r5 - 2016-07-06 - JaniHamalainen
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2026 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.