Re: groups of values from an array
- From: rob.dixon@xxxxxxx (Rob Dixon)
- Date: Tue, 29 Jan 2008 16:02:54 +0000
Horvath, Peter wrote:
Hello Perl guru's,[snip more data]
I need to pull multiple values form an array. There are
separator array entries. I need to be able to get all the values between
the separator values, process them, and then move onto the next group
till the end. Here is an example of the array.
========================================================================
========
media ID: 001070
media type: 1/2" cartridge tape (6)
barcode: 001070
media description: V0|256|S190|20040315
volume pool: NBdatabase (5)
robot type: NONE - Not Robotic (0)
volume group: Offsite-V0
vault name: V0
vault sent date: Thu Jan 17 21:23:12 2008
vault return date: Thu Jan 31 19:51:59 2008
vault slot: 5038
vault session id: 8314
vault container id: -
created: Wed Feb 28 18:55:26 2001
assigned: Thu Jan 17 19:51:59 2008
last mounted: Thu Jan 17 20:58:00 2008
first mount: Wed Feb 28 19:01:24 2001
expiration date: ---
number of mounts: 148
max mounts allowed: ---
status: 0x1
========================================================================
========
As Chas says, don't put the data into an array in the first place: you
have gained nothing by importing it into memory. The program below reads
a file structured like this into an array of hashes, which is likely to
be the most convenient form for any processing you need to do.
HTH,
Rob
use strict;
use warnings;
my @data;
my %record;
while (<DATA>) {
chomp;
if (/^==/) {
push @data, {%record} if %record;
%record = ();
}
elsif (/(.+):\s+(.+)/) {
$record{$1} = $2;
}
}
.
- Follow-Ups:
- Re: groups of values from an array
- From: Chas. Owens
- Re: groups of values from an array
- References:
- groups of values from an array
- From: Peter Horvath
- groups of values from an array
- Prev by Date: Re: Process Directory and subdirectories Recursively
- Next by Date: Re: groups of values from an array
- Previous by thread: Re: groups of values from an array
- Next by thread: Re: groups of values from an array
- Index(es):
Relevant Pages
|