in reply to Adding Strings to an Array Permanently

If it's data persistance you are looking for, have a look at the Storable, Data::Serializer, etc... modules. You do a freeze of your structure and then save the output string to an external file. When the script is run the next time, first read the file, then do a thaw to get back your structure. I like the Data::Serializer because it is flexible and has support for encryption as well.

  • Comment on Re: Adding Strings to an Array Permanently

Replies are listed 'Best First'.
Re: Re: Adding Strings to an Array Permanently
by OxYgEn (Acolyte) on Mar 02, 2004 at 00:33 UTC
    Uh, this is a bit embarrasing, but...
    I'm very new to perl. I don't think you can be much newer than me. Could you give me some little snippet of code with an example of what you're saying, Roger?

    Thanks again,
    OxYgEn
      #!/usr/bin/perl -w use strict; use IO::File; use Data::Serializer; use Data::Dumper; my @list; my $s = Data::Serializer->new( serializer => 'Storable', portable => 0, compress => 0, ); if (-s "./list.bin") { print "Load ice and thaw\n"; my $f = new IO::File "./list.bin", "r" or die; my $ice = do { local $/; <$f> }; @list = @{$s->thaw($ice)}; print Dumper(\@list); } else { print "Build list and freeze\n"; @list = qw/ 0 1 2 3 /; my $ice = $s->freeze(\@list); my $f = new IO::File "./list.bin", "w" or die; print $f $ice; }