in reply to dynamically named arrays

Rather than trying to create dynamically named arrays (which can be done but requires using things called symbolic references which are generally frowned upon unless there is a specific reason for their use) a hash of arrays seems like your best option here.

Some sample code to get you started. See perldata and perlreftut for further info.

#! perl -sw use strict; my %files; while(<DATA>) { chomp; my ($type, $ts) = m/(..)(.*)/; $files{$type} = [] if not exists $files{$type}; push @{$files{$type}}, $ts; } foreach my $type (keys %files) { print $type,$_,$/ for sort @{$files{$type}}; } __DATA__ vs010101.000 ud010101.000 ve020202.000 eq131302.000 eq010101.000 vs031102.000 us020101.000 ve051001.000

Gives output

c:\test>206767 eq010101.000 eq131302.000 us020101.000 ud010101.000 vs010101.000 vs031102.000 ve020202.000 ve051001.000 c:\test>

Cor! Like yer ring! ... HALO dammit! ... 'Ave it yer way! Hal-lo, Mister la-de-da. ... Like yer ring!

Replies are listed 'Best First'.
Re: Re: dynamically named arrays
by Anonymous Monk on Oct 21, 2002 at 05:18 UTC

    thanks for all the replies! whats basically happeneing is that someone at work is writing a catalogue search program in clarion (i know, i'd write it in perl if it were feasible) and becuase of clarion's lack of networking support i was asked to write a program to download catalogue updates. i came up with the ingenious idea of downloading updates of each type, getting the modification time for each file downloaded and put it into an array (intrinsicly named after the type). after all files have been downloaded it would sort the array, get that latest modified file and put it into an ini file so next time the update program is run it will check the modification time of the file its downloading against the one in the ini file. probably not the best way to do things but i can't think of any other way at the moment - i'm sure that will change.

      If the box on the other end is a UN*X box you could consider touching a file in each directory holding files called something like '.browser-time'.

      If the timestamps of the '.browser-time' and the '.' differ, files where changed or added since your last visit, cause the '.' takes over the timestamp of the latest changed or added file

      This can save you some time in searching these things.

      er formait hyarya.
      -- "Life is a house and the next tornado is never far away"
      -- "lovely by nature"

        Well, if you're using UN*X, there are things like rdist and rsync that would do the whole works more efficiently.

        thor

        The modification time does not "take over the timestamp" of the latest changed or added file. The modification time of a directory only changes when a file is added or removed.
      You may find that a DB_File or relative would be more suitable than an INI file.

      --- demerphq
      my friends call me, usually because I'm late....