Loading ...
Sorry, an error occurred while loading the content.

Clearing Arrays

Expand Messages
  • joshypy
    Dear Friends, Is there any way to Clear all the elements of all arrays in a program by a Single Command. Joshy
    Message 1 of 4 , Apr 4 12:06 AM
    View Source
    • 0 Attachment
      Dear Friends,

      Is there any way to Clear all the elements of all arrays in a program
      by a Single Command.

      Joshy
    • Damien Carbery
      ... see perldoc perldata page. You can also gain some minuscule measure of efficiency by pre-extending an array that is going to get big. You can also extend
      Message 2 of 4 , Apr 4 4:42 AM
      View Source
      • 0 Attachment
        --- In perl-beginner@yahoogroups.com, "joshypy" <joshypy@...> wrote:
        >
        > Dear Friends,
        >
        > Is there any way to Clear all the elements of all arrays in a program
        > by a Single Command.
        >
        > Joshy
        >
        see 'perldoc perldata' page.

        You can also gain some minuscule measure of efficiency by
        pre-extending an array that is going to get big. You can also extend
        an array by assigning to an element that is off the end of the array.
        You can truncate an array down to nothing by assigning the null list
        () to it. The following are equivalent:

        @whatever = ();
        $#whatever = -1;
      • Yogesh Sawant
        ... program ... array. ... and if in case you wish to remove the array entirely: @whatever = (); undef @whatever; cheers yogesh
        Message 3 of 4 , Apr 5 8:40 AM
        View Source
        • 0 Attachment
          --- In perl-beginner@yahoogroups.com, "Damien Carbery"
          <daymobrew@...> wrote:
          >
          > > Dear Friends,
          > >
          > > Is there any way to Clear all the elements of all arrays in a
          program
          > > by a Single Command.
          > >
          > > Joshy
          > >
          > see 'perldoc perldata' page.
          >
          > You can also gain some minuscule measure of efficiency by
          > pre-extending an array that is going to get big. You can also extend
          > an array by assigning to an element that is off the end of the
          array.
          > You can truncate an array down to nothing by assigning the null list
          > () to it. The following are equivalent:
          >
          > @whatever = ();
          > $#whatever = -1;
          >
          and if in case you wish to remove the array entirely:

          @whatever = ();
          undef @whatever;

          cheers
          yogesh
        • Charles K. Clarkson
          ... Technically, yes. If we define single command and clear all elements loosely. If all arrays are lexically scoped then ending the code block of the
          Message 4 of 4 , Apr 7 6:57 AM
          View Source
          • 0 Attachment
            joshypy wrote:

            : Dear Friends,
            :
            : Is there any way to Clear all the elements of all arrays
            : in a program by a Single Command.

            Technically, yes. If we define "single command" and
            "clear all elements" loosely. If all arrays are lexically
            scoped then ending the code block of the largest scope
            will clear the final array (or arrays).

            Your question begs another one. Why would this be
            important? Perl handles its own garbage clean up. If you
            are using lexical variables, your data structures will
            go out of scope as soon as you no longer need them. I
            can't help but wonder if you are using lexical variables.

            HTH,

            Charles K. Clarkson
            --
            Mobile Homes Specialist
            254 968-8328
          Your message has been successfully submitted and would be delivered to recipients shortly.