removing all elements in an array

Ask a Question related to PERL Beginners, Design and Development.

  1. #1

    Default removing all elements in an array

    How can I simply remove all elements in an array, given that the array
    is global and a procedure defines the elements to where the total
    number of elements in this array could be very well be less.

    I have tried @array = (); but this seems to affect the arrary in that
    it wont take any element assignments afterwards.

    Do I need to iterate through each element and blank the out?
    Richard Markham Guest

  2. Similar Questions and Discussions

    1. Removing duplicate elements from an XML file
      Is there an easy way of removing duplicate elements in an XML file. For example if I have three elements like: <incident id="GDOT-INC-252421"...
    2. Removing elements from associate array.
      Elo! I've got a problem with removing elements from associate array (php). Above you'll find a schematic structure of my array: ARRAY ------...
    3. Accessing elements in array ref of array references
      Currently I'm comparing the first value of each of the array references (which are stored in an array reference $ref_ref) as follows: ...
    4. [PHP] Removing array element by key
      On Friday 11 July 2003 04:50, jwulff wrote: unset() -- Jason Wong -> Gremlins Associates -> www.gremlins.biz Open Source Software Systems...
    5. Removing array element by key
      How do i remove an element of an array by its key? I've tried array_s(p)lice to no avail. Either it chops too much or too little with seemingly...
  3. #2

    Default Re: removing all elements in an array

    On 2/4/2004 10:27 PM, Markham, Richard wrote:
    > How can I simply remove all elements in an array, given that the array
    > is global and a procedure defines the elements to where the total
    > number of elements in this array could be very well be less.
    >
    > I have tried @array = (); but this seems to affect the arrary in that
    > it wont take any element assignments afterwards.
    >
    > Do I need to iterate through each element and blank the out?
    >
    @array = ();

    is what you want. What kind of assignments are producing errors, and
    what errors are you getting?

    Randy.


    Randy W. Sims Guest

  4. #3

    Default Re: removing all elements in an array

    On Feb 4, Markham, Richard said:
    >How can I simply remove all elements in an array, given that the array
    >is global and a procedure defines the elements to where the total
    >number of elements in this array could be very well be less.
    >
    >I have tried @array = (); but this seems to affect the arrary in that
    >it wont take any element assignments afterwards.
    Then you're doing something wrong.

    @array = ();

    is the proper way to do it. Show us your code.

    --
    Jeff "japhy" Pinyan [email]japhy@pobox.com[/email] [url]http://www.pobox.com/~japhy/[/url]
    RPI Acacia brother #734 [url]http://www.perlmonks.org/[/url] [url]http://www.cpan.org/[/url]
    <stu> what does y/// stand for? <tenderpuss> why, yansliterate of course.
    [ I'm looking for programming work. If you like my work, let me know. ]

    Jeff 'Japhy' Pinyan Guest

  5. #4

    Default Re: removing all elements in an array

    For Quality purpouses, Markham, Richard 's mail on Thursday 05 February 2004
    04:27 may have been monitored or recorded as:
    > How can I simply remove all elements in an array, given that the array
    > is global and a procedure defines the elements to where the total
    > number of elements in this array could be very well be less.
    >
    > I have tried @array = (); but this seems to affect the arrary in that
    > it wont take any element assignments afterwards.
    >
    well
    ---snip---
    #!/usr/bin/perl
    use strict;
    use warnings;
    my @array=qw/1 2 3 4 5 6 a s d f g/;

    print "Length for blank: ", scalar @array,"\n";
    print "$_ " foreach (@array);
    @array=();
    print "\nLength after blank: ", scalar @array,"\n";

    ---snap---

    does it.

    @array=(); is the way to go:
    I guess your proble is somewhere else.
    > Do I need to iterate through each element and blank the out?
    "...making easy thigs easy and hard things possible" - heavans no!

    wolf

    Wolf Blaum Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139