in reply to How can one delete an element and it corresponding values from the array of arrays?

It has already been noted in your previous thread that a set of arrays is a poor choice of data structure for your task. Difficulty of deleting a record is one problem of many that you'll encounter - it's much easier using hashes.

#!/usr/bin/env perl use v5.12; use Data::Dumper; my %students = ( x1 => { name => "Alice", telephone => 1001, regno => "x1", }, x2 => { name => "Bob", telephone => 1002, regno => "x2", }, x3 => { name => "Carol", telephone => 1003, regno => "x3", }, ); say "Let's look at the data structure..."; print Dumper \%students; say "What is student x1's telephone number?"; say $students{x1}{telephone}; say "What is Carol's telephone number?"; my ($carol) = grep { $_->{name} eq "Carol" } values %students; say $carol->{telephone}; say "Now let's delete student x2..."; delete $students{x2}; say "And change Carol's phone number"; $carol->{telephone} = "1004"; say "Let's look at the data structure again..."; print Dumper \%students;
package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name
  • Comment on Re: How can one delete an element and it corresponding values from the array of arrays?
  • Download Code

Replies are listed 'Best First'.
Re^2: How can one delete an element and it corresponding values from the array of arrays?
by supriyoch_2008 (Monk) on Mar 18, 2013 at 10:25 UTC

    Hi tobyink

    Thanks for your suggestions. I have noticed that you have mentioned in previous thread that a set of arrays is a poor choice of data structures. Honestly speaking, I find the Data structures in perl (like arrays of arrays, hashes of arrays, arrays of hashes etc.) very complicated for my understanding because of diverse use of parentheses & brackets and because of my recent introduction to perl as a biologist. Perl is the first computer language that I have been trying to learn through personal endeavor. I donot have any formal training on computer and its applications. I hope you will understand my limitations in understanding a computer language. Moreover, it may sound strange that I started learning how to use a computer(a laptop) since 22nd February 2008 when I was given a laptop by the university. Prior to that I could not afford a laptop because of its high cost.

    Regards,

      The nice thing is that there are really only three things to learn, and then the world of data structures is all yours.

      You've got Arrays, and you've got Hashes, and then you've got references. Once you wrap your head around those three, and see the recursive possibilities, you can make pretty much anything.