Question

I have a array of hash which I am dereferencing in the msg->attach() function of the Mime::Lite. The code is as follows:

for my $href (@$aref){
    $msg->attach(
            Type     => 'text',
            Data     => "productype: $href->{prodtype}   product: $href->{product}    qbs_id:$href->{qbs_id}\n";
    );
}

It indicates syntax error in the above example. Please inform me if this is a right way to put msg->attach() in a loop or we can't keep it in a loop. Thank you.

Was it helpful?

Solution

Inside the argument list for attach, no semicolons ; may occur. Use a comma , to seperate the arguments:

for my $href (@$aref) {
    $msg->attach(
        Type => 'text',
        Data => "productype: $href->{prodtype}   product: $href->{product}    qbs_id:$href->{qbs_id}\n",
    );
}

A trailing comma may also be omitted, but I consider that bad style.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top