Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to add email address to string in Perl? ( "@" character )

I have some perl code below:

    my $formattedUserEmail = $[UserEmail];
    
    $additionalTestParameters .= "ECJOBLink,$jobLink;ECJOBId,$[jobId];EcJobCounter,$jobCounter,PFUser,$formattedUserEmail";

When the perl code runs, I see the contents of each var below:

    my $formattedUserEmail = dave.adam@site.com; 
    
    $additionalTestParameters .= "ECJOBLink,$jobLink;ECJOBId,1111;EcJobCounter,$jobCounter,PFUser,$formattedUserEmail";

But when the code runs, it results in errors, i beleive because of the ‘dave.adam@site.com’ email address, specifically the "@" character, which is a special symbol in perl.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Array found where operator expected at ... line 32, at end of line
syntax error at .... line 32, near "adam@site"
Global symbol "@site" requires explicit package name at C.... line 32.
Execution of ..... aborted due to compilation errors.

How can I fix my code so that the email var gets added to the $additionalTestParameters string?

>Solution :

You should use

    my $formattedUserEmail = 'dave.adam@site.com';

instead of

    my $formattedUserEmail = dave.adam@site.com; 

because Perl’s try to expand @site non existing array.


Also, $[UserEmail] looks suspicious.

If it’s a HASH, it should be ${'UserEmail'}.

$[UserEmail] is for a array member and UserEmail should be a numeric key.


Always:

use strict;
use warnings; 

in all of your scripts, it will helps for coding errors:

Array found where operator expected at reply input line 1, near "adam@site"
Bareword "dave" not allowed while "strict subs" in use at reply input line 1.
syntax error at reply input line 1, near "adam@site"
Global symbol "@site" requires explicit package name (did you forget to declare "my @site"?) at reply input line 1.
BEGIN not safe after errors--compilation aborted at reply input line 7.
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading