Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Declare a long string using $

Posted on 2006-11-17
4
Medium Priority
?
886 Views
Last Modified: 2011-10-03
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
0
Comment
Question by:azsoft
4 Comments
 
LVL 85

Expert Comment

by:ozo
ID: 17963989
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
0
 
LVL 8

Expert Comment

by:Perl_Diver
ID: 17967325
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.


0
 
LVL 3

Accepted Solution

by:
Lil earned 200 total points
ID: 17970504
my $MAILRCP = "john, anna, steven";
#to add a new name to this:
$newnames = "garry, tom, Jeff, alia, mike, guna, larry";
$MAILRCP .= ", ".$newnames;

If this was a subroutine, it would look like this:

sub addNames()
{
my $MAILRCP = "john, anna, steven";
my $newnames = "garry, tom, Jef, alia, mike, guna, larry";
$MAILRCP .= ", ".$newnames
 return $MAILRCP;
}
0
 
LVL 1

Expert Comment

by:mallah
ID: 17973842


>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.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question