Re: How to find easily an element

2005-11-06 Thread Xavier Noria

On Nov 6, 2005, at 18:27, Gilles wrote:


Hi,

How to find easily if an element $val is in a given list @list ?


perldoc -q contain

-- fxn

PS: BTW, Perl has lists and arrays, though only arrays can be stored  
in variables. In that case @list is not a list, it is an array. See  
perldoc -q difference.


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




How to find easily an element

2005-11-06 Thread Gilles
Hi,

How to find easily if an element $val is in a given list @list ?

Thanks

Gilles

 



Re: array of hashrefs

2005-11-06 Thread Shawn Corey

Octavian Rasnita wrote:

Hi,

I have tried the following test program:

my @array = (
{a => 'aaa', b => 'bbb',},
{a => 'ala', b => 'bala',},
);

my @array2 = @array;

$array2[0]{a} = 'nanan';
push(@array2, 'test');

use Data::Dumper;
print Dumper [EMAIL PROTECTED];

The result was:

$VAR1 = [
  {
'a' => 'nanan',
'b' => 'bbb'
  },
  {
'a' => 'ala',
'b' => 'bala'
  }
];

I know why modifying an element from a hashref from the second array
modifies that element in the first array and why the new pushed element in
the second array is not shown in the first array, but I don't know how to
create a second array with all the elements of the first one, but totally
separately.

Is this possible somehow, or I will need to use foreach element of the first
array, and create the correspondent element in the second one?
The array doesn't have more levels, so I would like avoiding using a CPAN
module that can copy an entire data structure.

Thank you.

Teddy




You can use the typeglob to modify the symbol table so that the two 
arrays are synchronized but it does not work with 'my' variables:


#!/usr/bin/perl

use strict;
use warnings;

use Data::Dumper;

our @array = (
  {a => 'aaa', b => 'bbb',},
  {a => 'ala', b => 'bala',},
);

our @array2;
*array2 = [EMAIL PROTECTED];

$array2[0]{a} = 'nanan';
push(@array2, 'test');

print Dumper [EMAIL PROTECTED];
print Dumper [EMAIL PROTECTED];

__END__

BTW, use this one sparingly; it will confuse a lot of people.

--

Just my 0.0002 million dollars worth,
   --- Shawn

"Probability is now one. Any problems that are left are your own."
   SS Heart of Gold, _The Hitchhiker's Guide to the Galaxy_

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]