> Subject: Example of hash and array movement correct? > > > > Hello,
Hello > I am looking for ways to move data > between array and hashes. > In all 3 of your examples, you don't show us the declaration of your variables nor how they are filled with data. I can make some assumptions, though. > Does anybody has a better way or idea to do some of this: > > Example 1: > @indatas = $datas [0 .. 4]; If I assume that the @datas variable is declared like this: my @datas = qw( One Two Three Four Five Six Seven ); then I can take a slice of that array to initiate the next array: my @indatas = @datas[0 .. 4]; I think in Example 1, you just need to reference the @datas array with an '@' sign at the front (instead of a '$' sign) when you are using it to create a slice. > Example 2: > $nkey = $dataln[3] . $dataln[4]; If I assume that the @dataln variable is declared like this: my @dataln = qw( A B C D E F G H ); then I can easily create a scalar variable, $nkey, by concatanating two of the elements of the @dataln array: my $nkey = $dataln[3] . $dataln[4]; It looks to me that you got this one right. Is this what you were asking? > Example 3: > $base{$bv[0]} = [ $bv[1], $bv[2], $bv[3], $bv[4] ]; If I assume that the @bv array and the %base hash are declared like this: my @bv = qw( Alpha Bravo Charlie Delta Echo ); my %base; then I can initiate an element of that hash with a slice from the @bv array: $base{$bv[0]} = [EMAIL PROTECTED] .. 4]]; Again, when taking a slice from an array, you need to reference the array with the '@' sign. Your example works, but you asked for simpler/easier ways to do things. Were these examples helpful? Maybe if you gave us a better idea of what you wanted to do with what kind of data we could be more specific helping you. --Errin -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>