Solved

merging variables

Posted on 2000-04-18
6
161 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Expert Comment

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

Expert Comment

by:maneshr
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Convert OverPunch 25 57
How to count json data 2 56
Sed question 2 45
Installing Git and chefdk via bat script 8 16
In this tutorial I will aim to show you how simple is making a small application in WhizBase, how to add, remove and update data in the DB. I will make a small address book application where you can add, browse, update and remove addresses. I wi…
This tutorial will discuss the log-in process using WhizBase. In this article I assume you already know HTML. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you might look at some of my other articles abo…
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…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

772 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

12 Experts available now in Live!

Get 1:1 Help Now