in reply to the variable is not getting assigned

I know it's not a big issue, but personally i don't like to put variables captured in between quotes like this:
my $message = "<event id=\"ALERT_$tier_$code1\" source=\"APP\">";
I do think it's better maintainable, readable etc. if you concatenate strings like this:
my $message = "<event id=\"ALERT_" . $tier . "_" . $code1 . "\" source=\"APP\">";
As you immediately see in the last line, the $tier and $code1 are Perl variables, as you don't see that as fast in your given one.

update: or indeed use grandfather's ${tier}

update2: I have to agree to davidrw, sprintf works even more clean. I have to admit as well, that i don't use it that often, even though it's a great function for string formatting, and i really don't know why.
Perhaps i need to force myself a bit more :).

"We all agree on the necessity of compromise. We just can't agree on when it's necessary to compromise." - Larry Wall.

Replies are listed 'Best First'.
Re^2: the variable is not getting assigned
by pKai (Priest) on Jan 11, 2006 at 08:50 UTC

    IMHO both variations suffer from escapism.

    When I have to insert double quotes into a double quoted string, I will most likely use qq for better readability:

    my $message = qq(<event id="ALERT_${tier}_$code1" source="APP">);

    YMMV

Re^2: the variable is not getting assigned
by davidrw (Prior) on Jan 12, 2006 at 05:49 UTC
    I often like using sprintf for it instead of variable concatentation .. note also using single quotes for the string literals means you don't have to have the escaping backslashes...
    my $message = sprintf '<event_id="ALTER_%d_%d" source="APP">', $tier, +$code1;

    Also, to OP: I second blazar's comments, and would also add to them that your assignment of $severity with the two if statements can simply be written as:
    $severity = $code1 ? 1 : 5;
    Though, what's the point of $severity ? It doesn't seem to be used...