Solved

Declare a long string using $

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Perl efficient DB Call 8 82
pipe to sed or perl, please help 5 127
Having a problem with ActiveState Perl on 64-bit Windows 7 3 68
Perl string replace for refred url 9 59
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.

863 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

22 Experts available now in Live!

Get 1:1 Help Now