#!/macports/bin/bash
while read -a portname
do
    echo -e "${portname[2]}"
    
    cd  $(dirname $(port file ${portname[0]}))

    cp  'Portfile' 'Portfile.orig'
    declare portrev=( $( grep 'perl5.branches' $(port file ${portname[0]}) ) )
    if [[ ${#portrev[@]} -eq 0 ]]
    then
        sed -En -e "1,/^PortGroup/p" 'Portfile.orig' \
            >  'Portfile'
        echo -e "perl5.branches         5.8 5.10 5.12 5.14 5.16" \
            >> 'Portfile'
        sed -E  -e "1,/PortGroup/d" 'Portfile.orig' \
            >> 'Portfile'
    else
        sed -E -e  "/^perl5.branches/s/^(.*)$/\1 5.16/"   \
            'Portfile.orig' \
        >   'Portfile'
    fi
    rm  'Portfile.orig'

done < <( port list name:^p5- )
