Solved

merging variables

Posted on 2000-04-18
6
163 Views
Last Modified: 2013-12-25
I've got an array-variable called @yield in a sub called dorm1. @yield contains some variables seperated with comma's.

I've got a second array-variable called @yield in a sub called dorm2. This @yield array contains different variabled as in sub dorm1.

Now I want to have both the @yield array's (from both sub's) in one @yield array (the one from sub dorm2 pasted after the one from sub dorm1). Is this possible with one or more lines ?
0
Comment
Question by:oostwijk
  • 3
  • 2
6 Comments
 
LVL 16

Expert Comment

by:maneshr
ID: 2728193
try this...

i am assuming that you are storing the yield array from dorm1 is stored in a and yield array from dorm2 in stored in b.

E.g.
@a=&dorm1;
@b=&dorm2;


#!/usr/local/bin/perl

## you can have any values in the array.
@a = (1, 3, 5, 6, 7, 8);
@b = (2, 3, 5, 7, 9);

## Try with these values too!!
##@a=("one","two","Three","nine");
##@b=("one","two","Three","four","five","seven","nine");

@arr=split(/,/,(join(',',@a).join(',',@b)));

print @arr,"\n";
==============================

in the future pl. post all your PERL related Q's to the PERL forum..

http://www.experts-exchange.com/Computers/Programming/Languages/Perl/

you will get a wider choice of answers.
0
 

Accepted Solution

by:
venky75 earned 50 total points
ID: 2729331
Hi there,

I would like to correct something in what maneshr has posted.

It would be something like this:

@y1=&dorm1;
@y2=&dorm2;
@yield=(@y1,@y2);

sub dorm1
{
 @yield1=("a","b","c");
 #rest of the code
 return @yield1;
}

sub dorm2
{
 @yield2=("d","e","f")
 #rest of the code
 return @yield2;
}

Hope this works out for u.

Bye
venky


0
 

Expert Comment

by:turbobasic
ID: 2731477
It seems that I didn't explain my question well enough. This is what I've got in :

sub dorm1 {
$fld="dorm1";
@fields=(

);}
"1,11,2,4",
"1,12,6,7",
"1,13,4,4",
"1,4,6,7,5",
"1,5,6,66",
"1,6,6,5",
"1,7,2,1",
"9,19,1,1",
"9,20,1,22",
and this in:

sub dorm2 {
$fld="dorm2";
@fields=(
"3,11,2,4",
"1,12,6,1",
"5,13,7,4",
"6,4,6,5,5",
"1,8,6,6",
"1,6,6,4",
"1,8,2,1",
"9,19,6,3",
"9,20,3,1",
);}

I wan't to have the @field-arrays merged together so that I get a final array also called @field. (so that array looks like this :
@fields=(
"1,11,2,4",
"1,12,6,7",
"1,13,4,4",
"1,4,6,7,5",
"1,5,6,66",
"1,6,6,5",
"1,7,2,1",
"9,19,1,1",
"9,20,1,22",
"3,11,2,4",
"1,12,6,1",
"5,13,7,4",
"6,4,6,5,5",
"1,8,6,6",
"1,6,6,4",
"1,8,2,1",
"9,19,6,3",
"9,20,3,1",
);}

Is this possible with one or more lines ?


0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Expert Comment

by:turbobasic
ID: 2731486
that comment came from me (oostwijk), I use the name turbobasic when I'm at my work.
0
 
LVL 16

Expert Comment

by:maneshr
ID: 2731539
try this...

#!/usr/local/bin/perl

sub dorm1 {
$fld="dorm1";
@fields=(
"1,11,2,4",
"1,12,6,7",
"1,13,4,4",
"1,4,6,7,5",
"1,5,6,66",
"1,6,6,5",
"1,7,2,1",
"9,19,1,1",
"9,20,1,22",
);}

sub dorm2 {
$fld="dorm2";
@fields=(
"3,11,2,4",
"1,12,6,1",
"5,13,7,4",
"6,4,6,5,5",
"1,8,6,6",
"1,6,6,4",
"1,8,2,1",
"9,19,6,3",
"9,20,3,1",
);}

@a=&dorm1;
@b=&dorm2;

@arr=(@a,@b);
print @arr,"\n";
0
 
LVL 16

Expert Comment

by:maneshr
ID: 2731556
OR try this....

#!/usr/local/bin/perl

sub dorm1 {
$fld="dorm1";
@fields=(
"1,11,2,4",
"1,12,6,7",
"1,13,4,4",
"1,4,6,7,5",
"1,5,6,66",
"1,6,6,5",
"1,7,2,1",
"9,19,1,1",
"9,20,1,22",
);}

sub dorm2 {
$fld="dorm2";
@fields=(
"3,11,2,4",
"1,12,6,1",
"5,13,7,4",
"6,4,6,5,5",
"1,8,6,6",
"1,6,6,4",
"1,8,2,1",
"9,19,6,3",
"9,20,3,1",
);}

@a=&dorm1;
@b=&dorm2;

@arr=split(/-/,join('-',@a,@b));

print scalar @arr,"\n";

foreach(@arr){
  print $_,"\n";
}
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Introduction:   Welcome to my first article ever. To begin with, the reason I write this article.  I participated in a question on Experts Exchange about the start command in Windows and there were some discussion about the usage. The discussio…
In this tutorial I will show you how to make a simple HTML bar chart with the usage of WhizBase, If you want more information about WhizBase please read my previous articles at http://www.experts-exchange.com/ARTH_5123186.html (http://www.experts-ex…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

770 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