08-31-2004
join 2 array in perl?
Hi guys,
Can anyone tell me how to join 2 array together?
@array1=("abc", "def");
@array2=("xyz", "uuu");
@join_array = fun(@array1,@array2);
# @join_array == ("abc", "def", "xyz", "uuu")
any function can do what fun(@@) does?
thanks
Gusla
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
I am trying to use a script to replace the header of each file, whose filename are stored within the array $test, using the sed command within a Perl script as follows:
$count = 0;
while ( $count < $#test )
{
`sed -e 's/BIOGRF 321/BIOGRF 332/g' ${test} > 0`;
`cat 0 >... (2 Replies)
Discussion started by: userix
2 Replies
2. Shell Programming and Scripting
Hi
can anyone suggest me how to write a file containing values,... say
19
20
21
22
..
40
to an array @array = (19, 20, ... 40)
-- Thanks (27 Replies)
Discussion started by: meghana
27 Replies
3. Shell Programming and Scripting
Hi,
Is there any way I can grep an array against another array?
Basically here's what I need to do.
There will be an array containing some fixed texts and I have to check whether some files contain these lines. Reading the same files over and over again for each different pattern doesnt seem... (1 Reply)
Discussion started by: King Nothing
1 Replies
4. Shell Programming and Scripting
Hi,
Can any one please let me know, how to join the lines in a file, but based one a condition.
There is a file, where few lines start with a date stamp. and few do not.
I wanted to join the lines till I find a date stamp. If found date its should in a newline.
Please help me.
... (5 Replies)
Discussion started by: thankful123
5 Replies
5. Shell Programming and Scripting
Hi Everyone,
#!/usr/bin/perl
use strict;
use warnings;
my @test=("a;b;qqq;c;d","a;b;ggg;c;d","a;b;qqq;c;d");
would like to split the @test array into two array:
@test1=(("a;b;qqq;c;d","a;b;qqq;c;d"); and @test2=("a;b;ggg;c;d");
means search for 3rd filed.
Thanks
find the... (0 Replies)
Discussion started by: jimmy_y
0 Replies
6. Shell Programming and Scripting
Hi,
I have tried the split and join functions but stuck with unexpected results. Any help appreciated. I pass multiple values at command line like perl test.pl -type java,xml. This works good for me but i am not sure how to print it in the required format.
Here is the code i tried:... (4 Replies)
Discussion started by: nmattam
4 Replies
7. Shell Programming and Scripting
Hi everyone
I have one question about using array in perl. let say I have several log file in one folder.. example
test1.log
test2.log
test3.log
and the list goes on..
how to make an array for this file? It suppose to detect log file in the current directory and all the log file will... (3 Replies)
Discussion started by: sayachop
3 Replies
8. Shell Programming and Scripting
I have an array and two variables as below,
I need to check if $datevar is present in $filename.
If so, i need to replace $filename with the values in the array.
I need the output inside an ARRAY
How can this be done.
Any help will be appreciated. Thanks in advance. (2 Replies)
Discussion started by: irudayaraj
2 Replies
9. Shell Programming and Scripting
Hi all,
Not sure if this should be in the programming forum, but I believe it will get more response under the Shell Programming and Scripting FORUM.
Am trying to write a customized df script in Perl and need some help with regards to using arrays and file handlers.
At the moment am... (3 Replies)
Discussion started by: newbie_01
3 Replies
10. UNIX for Dummies Questions & Answers
Hi,
I have 20 tab delimited text files that have a common column (column 1). The files are named GSM1.txt through GSM20.txt. Each file has 3 columns (2 other columns in addition to the first common column).
I want to write a script to join the files by the first common column so that in the... (5 Replies)
Discussion started by: evelibertine
5 Replies
LEARN ABOUT PHP
array_intersect_assoc
ARRAY_INTERSECT_ASSOC(3) 1 ARRAY_INTERSECT_ASSOC(3)
array_intersect_assoc - Computes the intersection of arrays with additional index check
SYNOPSIS
array array_intersect_assoc (array $array1, array $array2, [array $...])
DESCRIPTION
array_intersect_assoc(3) returns an array containing all the values of $array1 that are present in all the arguments. Note that the keys
are used in the comparison unlike in array_intersect(3).
PARAMETERS
o $array1
- The array with master values to check.
o $array2
- An array to compare values against.
o $...
- A variable list of arrays to compare.
RETURN VALUES
Returns an associative array containing all the values in $array1 that are present in all of the arguments.
EXAMPLES
Example #1
array_intersect_assoc(3) example
<?php
$array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red");
$array2 = array("a" => "green", "b" => "yellow", "blue", "red");
$result_array = array_intersect_assoc($array1, $array2);
print_r($result_array);
?>
The above example will output:
Array
(
[a] => green
)
In our example you see that only the pair "a" => "green" is present in both arrays and thus is returned. The value "red" is not returned
because in $array1 its key is 0 while the key of "red" in $array2 is 1, and the key "b" is not returned because its values are different in
each array.
The two values from the key => value pairs are considered equal only if (string) $elem1 === (string) $elem2 . In other words a strict type
check is executed so the string representation must be the same.
SEE ALSO
array_intersect(3), array_uintersect_assoc(3), array_intersect_uassoc(3), array_uintersect_uassoc(3), array_diff(3), array_diff_assoc(3).
PHP Documentation Group ARRAY_INTERSECT_ASSOC(3)