Search code examples
perlcase-sensitive

perl how to search excel worksheet being case insensitive


current script:

$ws = $wb->Worksheet("Food_List");

if ( !$ws ) {
    print LOG
        "Error: Required 'Food_List' excel spreadsheet(tab). Review worksheet naming convention";
    exit 1;
}

so now we need to match the worksheet to 'Food_List'. What if I want to allow more flexibility and allow 'food_list', or 'FOOD_LIST'worksheet?


Solution

  • Assuming you're using Spreadsheet::ParseExcel:

    my $ws;
    for my $sheet ( $wb->worksheets() ) {
        if ( $sheet->get_name() =~ m/Food_list/i ) {
            $ws = $sheet;
            last;
        }
    }
    

    Update: Use get_name and it works.