Professional Web Applications Themes

removing all elements in an array - PERL Beginners

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?...

  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. #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

  3. #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]japhypobox.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

  4. #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

Similar Threads

  1. Removing duplicate elements from an XML file
    By Angshuman Guin in forum PERL Modules
    Replies: 1
    Last Post: August 7th, 05:13 PM
  2. Removing elements from associate array.
    By MaciejK in forum PHP Development
    Replies: 0
    Last Post: July 25th, 12:57 PM
  3. Accessing elements in array ref of array references
    By fatted in forum PERL Miscellaneous
    Replies: 3
    Last Post: July 24th, 08:58 PM
  4. [PHP] Removing array element by key
    By Jason Wong in forum PHP Development
    Replies: 0
    Last Post: July 10th, 08:54 PM
  5. Removing array element by key
    By Jwulff in forum PHP Development
    Replies: 0
    Last Post: July 10th, 08:50 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not 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