How to simplify this perl script to a cleaner simpler look?

my $branch_email_e = $FORM{r_Branch};
my $hostbranch_email_e = $FORM{r_Host_Branch};

my $branch\_email_f = $FORM\{r\_Direction_generale\};
my $hostbranch\_email_f = $FORM\{r\_Direction\_generale_daccueil\};
   
my $branch\_realname_e = '';
my $branch\_realname_f = '';   

if \(\($branch\_email_e eq 'Dot.exp.rh-exp.staf.hr@.gc.ca'\) or \($hostbranch\_email_e eq 'Dot.exp.rh-exp.staf.hr@.gc.ca'\)\) \{ $branch\_realname_e = 'Human Resources'; $FORM\{'branch\_in_emailsubject'\} = $branch\_realname_e; \}
    elsif \(\($branch\_email_e eq 'Dot.exp.fin-exp.staf.fin@.gc.ca'\) or \($hostbranch\_email_e eq 'Dot.exp.fin-exp.staf.fin@.gc.ca'\)\) \{ $branch\_realname_e = 'Finance'; $FORM\{'branch\_in_emailsubject'\} = $branch\_realname_e; \}
    elsif \(\($branch\_email_e eq 'Dot.exp.min-exp.staf.min@.gc.ca'\) or \($hostbranch\_email_e eq 'Dot.exp.min-exp.staf.min@.gc.ca'\)\) \{ $branch\_realname_e = 'Minister's Office'; $FORM\{'branch\_in_emailsubject'\} = $branch\_realname_e; \}
    elsif \(\($branch\_email_e eq 'Dot.exp.sm-exp.staf.dm@.gc.ca'\) or \($hostbranch\_email_e eq 'Dot.exp.sm-exp.staf.dm@.gc.ca'\)\) \{ $branch\_realname_e = 'Deputy Minister's Office'; $FORM\{'branch\_in_emailsubject'\} = $branch\_realname_e; \}
    elsif \(\($branch\_email_e eq 'Dot.exp.bapgr-exp.staf.ocro@.gc.ca'\) or \($hostbranch\_email_e eq 'Dot.exp.bapgr-exp.staf.ocro@.gc.ca'\)\) \{ $branch\_realname_e = 'Office of the Chief Risk Officer'; $FORM\{'branch\_in_emailsubject'\} = $branch\_realname_e; \}
    elsif \(\($branch\_email_e eq 'Dot.exp.dga-exp.staf.ab@.gc.ca'\) or \($hostbranch\_email_e eq 'Dot.exp.dga-exp.staf.ab@.gc.ca'\)\) \{ $branch\_realname_e = 'Acquisitions'; $FORM\{'branch\_in_emailsubject'\} = $branch\_realname_e; \}
    elsif \(\($branch\_email_e eq 'Dot.exp.dgbi-exp.staf.rpb@.gc.ca'\) or \($hostbranch\_email_e eq 'Dot.exp.dgbi-exp.staf.rpb@.gc.ca'\)\) \{ $branch\_realname_e = 'Real Property'; $FORM\{'branch\_in_emailsubject'\} = $branch\_realname_e; \}
    elsif \(\($branch\_email_e eq 'Dot.exp.dgcisp-exp.staf.cissb@.gc.ca'\) or \($hostbranch\_email_e eq 'Dot.exp.dgcisp-exp.staf.cissb@.gc.ca'\)\) \{ $branch\_realname_e = 'Consulting, Information, and Shared Services'; $FORM\{'branch\_in_emailsubject'\} = $branch\_realname_e; \}
    elsif \(\($branch\_email_e eq 'Dot.exp.dgcgbr-exp.staf.abcb@.gc.ca'\) or \($hostbranch\_email_e eq 'Dot.exp.dgcgbr-exp.staf.abcb@.gc.ca'\)\) \{ $branch\_realname_e = 'Accounting, Banking and Compensation'; $FORM\{'branch\_in_emailsubject'\} = $branch\_realname_e; \}
    elsif \(\($branch\_email_e eq 'Dot.exp.dgsmpc-exp.staf.cspcb@.gc.ca'\) or \($hostbranch\_email_e eq 'Dot.exp.dgsmpc-exp.staf.cspcb@.gc.ca'\)\) \{ $branch\_realname_e = 'Corporate Services, Policy and Communications'; $FORM\{'branch\_in_emailsubject'\} = $branch\_realname_e; \}
    elsif \(\($branch\_email_e eq 'Dot.exp.dgsit-exp.staf.itsb@.gc.ca'\) or \($hostbranch\_email_e eq 'Dot.exp.dgsit-exp.staf.itsb@.gc.ca'\)\) \{ $branch\_realname_e = 'Information Technology Services'; $FORM\{'branch\_in_emailsubject'\} = $branch\_realname_e; \}
    elsif \(\($branch\_email_e eq 'Dot.exp.dgve-exp.staf.aeb@.gc.ca'\) or \($hostbranch\_email_e eq 'Dot.exp.dgve-exp.staf.aeb@.gc.ca'\)\) \{ $branch\_realname_e = 'Audit and Evaluation'; $FORM\{'branch\_in_emailsubject'\} = $branch\_realname_e; \}
    elsif \(\($branch\_email_e eq 'Dot.exp.bt-exp.staf.tb@.gc.ca'\) or \($hostbranch\_email_e eq 'Dot.exp.bt-exp.staf.tb@.gc.ca'\)\) \{ $branch\_realname_e = 'Translation Bureau'; $FORM\{'branch\_in_emailsubject'\} = $branch\_realname_e; \}
    elsif \(\($branch\_email_e eq 'Dot.exp.atl-exp.staf.atl@.gc.ca'\) or \($hostbranch\_email_e eq 'Dot.exp.atl-exp.staf.atl@.gc.ca'\)\) \{ $branch\_realname_e = 'Atlantic Region'; $FORM\{'branch\_in_emailsubject'\} = $branch\_realname_e; \}
    elsif \(\($branch\_email_e eq 'Dot.exp.que-exp.staf.que@.gc.ca'\) or \($hostbranch\_email_e eq 'Dot.exp.que-exp.staf.que@.gc.ca'\)\) \{ $branch\_realname_e = 'Quebec Region'; $FORM\{'branch\_in_emailsubject'\} = $branch\_realname_e; \}
    elsif \(\($branch\_email_e eq 'Dot.exp.ont-exp.staf.ont@.gc.ca'\) or \($hostbranch\_email_e eq 'Dot.exp.ont-exp.staf.ont@.gc.ca'\)\) \{ $branch\_realname_e = 'Ontario Region'; $FORM\{'branch\_in_emailsubject'\} = $branch\_realname_e; \}
    elsif \(\($branch\_email_e eq 'Dot.exp.oue-exp.staf.wes@.gc.ca'\) or \($hostbranch\_email_e eq 'Dot.exp.oue-exp.staf.wes@.gc.ca'\)\) \{ $branch\_realname_e = 'Western Region'; $FORM\{'branch\_in_emailsubject'\} = $branch\_realname_e; \}
    elsif \(\($branch\_email_e eq 'Dot.exp.pac-exp.staf.pac@.gc.ca'\) or \($hostbranch\_email_e eq 'Dot.exp.pac-exp.staf.pac@.gc.ca'\)\) \{ $branch\_realname_e = 'Pacific Region'; $FORM\{'branch\_in_emailsubject'\} = $branch\_realname_e; \}
    elsif \(\($branch\_email_e eq 'Dot.exp.boa-exp.staf.opo@.gc.ca'\) or \($hostbranch\_email_e eq 'Dot.exp.boa-exp.staf.opo@.gc.ca'\)\) \{ $branch\_realname_e = 'Office of the Procurement  Ombudsman'; $FORM\{'branch\_in_emailsubject'\} = $branch\_realname_e; \}
    elsif \(\($branch\_email_e eq 'Dot.exp.dgcp-exp.staf.ppb@.gc.ca'\) or \($hostbranch\_email_e eq 'Dot.exp.dgcp-exp.staf.ppb@.gc.ca'\)\) \{ $branch\_realname_e = 'Parliamentary Precinct'; $FORM\{'branch\_in_emailsubject'\} = $branch\_realname_e; \}
    elsif \(\($branch\_email_e eq 'Dot.exp.mat-exp.staf.mat@.gc.ca'\) or \($hostbranch\_email_e eq 'Dot.exp.mat-exp.staf.mat@.gc.ca'\)\) \{ $branch\_realname_e = 'Matane Site'; $FORM\{'branch\_in_emailsubject'\} = $branch\_realname_e; \}
    elsif  \(\($branch\_email_e eq 'Dot.exp.she-exp.staf.she@.gc.ca'\) or \($hostbranch\_email_e eq 'Dot.exp.she-exp.staf.she@.gc.ca'\)\) \{ $branch\_realname_e = 'Shediac Site'; $FORM\{'branch\_in_emailsubject'\} = $branch\_realname_e; \}
    elsif  \(\($branch\_email_e eq 'Dot.exp.surveillance-exp.staf.oversight@.gc.ca'\) or \($hostbranch\_email_e eq 'Dot.exp.surveillance-exp.staf.oversight@.gc.ca'\)\) \{ $branch\_realname_e = 'Departmental Oversight'; $FORM\{'branch\_in_emailsubject'\} = $branch\_realname_e; \}

---------- Post updated at 08:47 AM ---------- Previous update was at 08:46 AM ----------

would I use a loop or a case statement or something like that?

I'd separate the data from the program, putting it in a big array. If you wanted to make it even more flexible you could read data into the array from a file.

my %hash=( 'Human Resources' => [ 'Dot.exp.rh-exp.staf.hr@.gc.ca', 'Dot.exp.rh-exp.staf.hr@.gc.ca'],
'Finance' => [ 'Dot.exp.fin-exp.staf.fin@.gc.ca', 'Dot.exp.fin-exp.staf.fin@.gc.ca' ]
 );

my $val1='Dot.exp.rh-exp.staf.hr@.gc.ca';
my $val2='Dot.exp.rh-exp.staf.hr@.gc.ca';

foreach $name(keys %hash)
{
        my $arr=$hash{$name};
        if(($val1 eq $arr->[0]) || ($val1 eq $arr->[1]))
        {
                printf("Val is %s\n", $name);
        }
}

[edit] no, that doesn't work. One moment.
[re-edit] Ahah, you need "eq", not "==". I hate perl. It works now.

thanks Corona688
It does seem to shorten and possible simplify, not all to familiar with hash arrays so will have to educate myself on how they work to better understand your solution.

thanks :slight_smile:

read it again, I removed some junk I left in by accident.

it actually is making more sense now, it's all slowly coming back (been a few years off of Perl and now am asked to go through this huge script and figure it out, clean it up and add more stuff...fun!)

thanks again