Re: Work with first x number of elements in array

2006-05-25 Thread Paul Johnson
On Fri, May 26, 2006 at 10:35:41AM +1000, Keenan, Greg John (Greg)** CTR ** wrote: > >Using a hash: > > > >for my $cfg ( keys %cfgs ) { > >my $fileIn = "$cfgDir/$cfg/tapelist"; > >open FILEIN, '<', $fileIn or die "Could not open $fileIn: $!"; > >print +( reverse )[ -$cfg{$cfg} .. -1

RE: Work with first x number of elements in array

2006-05-25 Thread Keenan, Greg John (Greg)** CTR **
>Small correction: because of the hyphens those barewords need to be quoted. > >my @cfgs = ( >[ Toaster=> 6 ], >[ 'MFG-UNIX' => 5 ], >[ 'SYS-UNIX' => 5 ], >[ 'Amanda-Daily' => 1 ], >); > >my %cfgs = ( >Toaster=> 6, >'MFG-UNIX' => 5, >'SYS-

Re: Work with first x number of elements in array

2006-05-25 Thread John W. Krahn
John W. Krahn wrote: > Keenan, Greg John (Greg)** CTR ** wrote: >> >>my $cfgDir = '/amanda/admin/etc/amanda'; >>my @cfgs = qw(Toaster MFG-UNIX SYS-UNIX Amanda-Daily); >>my %numTapes = ( >> "$cfgs[0]" => 6, >> "$cfgs[1]" => 5, >> "$cfgs[2]" => 5, >> "$cfgs[3]" => 1, >> ); > > Do you really ne

RE: Work with first x number of elements in array

2006-05-25 Thread Keenan, Greg John (Greg)** CTR **
>Using an AoA: > >for my $cfg ( @cfgs ) { >my $fileIn = "$cfgDir/$cfg->[0]/tapelist"; >open FILEIN, '<', $fileIn or die "Could not open $fileIn: $!"; >print +( reverse )[ -$cfg->[1] .. -1 ]; } > >Using a hash: > >for my $cfg ( keys %cfgs ) { >my $fileIn = "$cfgDir/$cfg/tapelist"; >

Re: Work with first x number of elements in array

2006-05-25 Thread John W. Krahn
Joshua Colson wrote: > On Fri, 2006-05-26 at 09:45 +1000, Keenan, Greg John (Greg)** CTR ** > wrote: >> >>my $cfg; >>foreach $cfg (@cfgs) { >>my $fileIn="$cfgDir/$cfg/tapelist"; >>open (FILEIN, "<$fileIn") or die ("Could not open $fileIn: $!"); >>my @lines = reverse ; >>my $line; >

Re: Work with first x number of elements in array

2006-05-25 Thread John W. Krahn
Keenan, Greg John (Greg)** CTR ** wrote: > Hi, Hello, > What is the best way to only work with the first x number of elements in an > array? > > At the moment this script prints the entire contents of @lines for each > element in @cfgs > > I would like to restrict this to the number of elemen

Re: Work with first x number of elements in array

2006-05-25 Thread Joshua Colson
On Fri, 2006-05-26 at 09:45 +1000, Keenan, Greg John (Greg)** CTR ** wrote: > --start-- > use strict; > use warnings; > > my $cfgDir = '/amanda/admin/etc/amanda'; > my @cfgs = qw(Toaster MFG-UNIX SYS-UNIX Amanda-Daily); > my %numTapes = ( > "$cfgs[0]" => 6, > "$cfgs[1]" => 5, > "$cfgs[2]"

Work with first x number of elements in array

2006-05-25 Thread Keenan, Greg John (Greg)** CTR **
Hi, What is the best way to only work with the first x number of elements in an array? At the moment this script prints the entire contents of @lines for each element in @cfgs I would like to restrict this to the number of elements listed in the hash %numTapes for each element in @cfgs Any