Link to home
Start Free TrialLog in
Avatar of azsoft
azsoft

asked on

Declare a long string using $

Hi,

I'm new in Perl. I've an assignment to edit perl script.

This is the original line
my $MAILRCP = 'john,anna,steven';

If I have a very long string(additional name to add on) , can I do like this:
my $MAILRCP = 'john,anna,steven,garry,tom,Jeff',
                        'alia','mike','guna','larry';

Please help.
Thanks
Avatar of ozo
ozo
Flag of United States of America image

You can do it like this:
my $MAILRCP = 'john,anna,steven,garry,tom,Jeff'.
                        'alia'.'mike'.'guna'.'larry';
or like this:
my $MAILRCP = 'john,anna,steven,garry,tom,Jeff
                        alia,mike,guna,larry';
or like
my $MAILRCP = join",",'john,anna,steven,garry,tom,Jeff',
                        'alia','mike','guna','larry';
Depending on what you want the string to contain
Avatar of Perl_Diver
Perl_Diver

to append to the end of a string you use the concatenation operator '.=' but it all depends on the structure of the data you are adding. If the string to add is already formatted exactly how you need it:

$foo = 'this';
$bar = 'that';
$foo .= $bar;
print $foo;


as ozo showed above there are numerous ways to append data to a string.


ASKER CERTIFIED SOLUTION
Avatar of Lil
Lil
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial


>If I have a very long string(additional name to add on) , can I do like this:

if you have a number of additional names to add on from some source say from a file its
better to loop and process one record at a time.

putting all the names in one var will take lots of memory.