Solved

Declare a long string using $

Posted on 2006-11-17
4
835 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 84

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 50 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

705 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now