perl how to search excel worksheet being case insensitive

51 views Asked by At

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?

1

There are 1 answers

4
Sobrique On BEST ANSWER

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.