FeraliX has asked for the wisdom of the Perl Monks concerning the following question:

I've just started up with Perl again and I've run into a wall. I have an array in another perl file linked to my main page. I want to be able to add and remove strings from the array, but Im not sure how to approach it. I've tried numerous scripts and all turn up nothing. Any help would be greatly appriciated.
// index.pl \\ require "alternate.pl"; // alternate.pl \\ @raider = ('Nammick::223','Abelia::222','Vaoz::201','Silversnow::192', +'Roruk::174','Xandir::171','Herzog::169','Juggerknott::169','Abaraxiu +s::163','Nochesa::159');

Replies are listed 'Best First'.
Re: Delete/Add a string in an array
by Zaxo (Archbishop) on Apr 25, 2006 at 05:14 UTC
Re: Delete/Add a string in an array
by davorg (Chancellor) on Apr 25, 2006 at 07:58 UTC

    You've got a few answers pointing you at the array manipulation functions, but I wonder if they're missing the main point of your question. Reading between the lines, I suspect that you actually want changes that you make to the array to be stored in alternate.pl, so that you get the altered array the next time that you run your program.

    If that's the case, then you might be better off storing your data in a text file and manipulating it as an array using Tie::File.

    --
    <http://dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

Re: Delete/Add a string in an array
by meleon (Novice) on Apr 25, 2006 at 05:20 UTC
      my @arr = ( "foo", "bar" ); print @arr, "\n"; # append a scalar push @arr, "post"; print @arr, "\n"; # and remove it again my $s = pop @arr; print "== popped the last one: $s ==\n"; print @arr, "\n"; # prepend a scalar unshift @arr, "pre"; print @arr, "\n"; # and remove it my $t = shift @arr; print "== shifted the first one: $t ==\n"; print @arr, "\n";