in reply to Re: reiterateing over array
in thread reiterateing over array

I could use a hash but if the bot ever goes down then the list of protected users is gone. Thats why Im opening the list from a .txt file and putting the contents in the an array. So the only way the protected users list would be lost is if i deleted the .txt file. Unless you meant in some other way.

Replies are listed 'Best First'.
Re^3: reiterateing over array
by alexm (Chaplain) on Aug 19, 2008 at 21:35 UTC

    You might want to use something like DBM::Deep that lets you tie a hash into a file. Thus, you get the simplicity of using a hash for quick access and the persistence of the data in a file.

Re^3: reiterateing over array
by blazar (Canon) on Aug 20, 2008 at 18:04 UTC
    I could use a hash but if the bot ever goes down then the list of protected users is gone. Thats why Im opening the list from a .txt file and putting the contents in the an array.

    I personally believe that if you can open the list from a .txt file an put its contents into an array, then you could also put them into an a hash. unless you meant in some other way! ;)

    --
    If you can't understand the incipit, then please check the IPB Campaign.
Re^3: reiterateing over array
by k0rn (Acolyte) on Aug 19, 2008 at 20:37 UTC
    And I did not understand this

    use List::Util qw( first ); my $pro = first { $user[0] eq $_ } @protected; do_stuff_with( $pro ) if defined $pro;

      I personally believe that you should explain exactly what you couldn't understand, given that you've been shown the relevant documentation:

      my $pro = first { $user[0] eq $_ } @protected;
      assigns to $pro the first value in @protected which is equal to $user[0], that is, $user[0] itself, if the latter is in @protected, or else an undefined value. Thus the following line chooses what to do depending on whether $pro is defined or not, which appears to be what you want, ain't it?
      --
      If you can't understand the incipit, then please check the IPB Campaign.