in reply to Parsing a Large file with no reason
I was just trying to have people to bounce some ideas off of - however this is what I came up with - its crude and runs slow on large files (the 1 file I am running this off of as a test is 80,000+ lines long) - If someone sees something I can do differently I am open to suggestions
#!/usr/bin/perl use strict; use warnings; no warnings 'uninitialized'; use Data::Dumper; use Tie::File; my $base = $ARGV[0]; open(FILE, $base) || die "Unable to locate file: $!\n"; my (@searray,@flarray); tie(@flarray, 'Tie::File',$base); while(<FILE>) { my ($start,$end); chomp; if($_ =~ /-El\s+vg/../vgserial_id/) { $start = (split /\s+/,$_)[3] if($_ =~/-El/); $end = (split /\s+/, $_)[1] if($_ =~/vgserial_id/); } if(defined $start) { push(@searray, $start); } else { $start = ''; +} if(defined $end) { push(@searray, $end); } else { $end = ''; } } my %hash_ref = @searray; #print Dumper \%hash_ref; foreach my $hkey(keys %hash_ref) { my $hvalue = $hash_ref{$hkey}; my $count = 0; for (my $i = 0; $i < @flarray; $i++) { next unless $flarray[$i] =~ /$hvalue/; next if($flarray[$i] =~ /vgserial_id/); my ($mc,$lvsip) = (($i-1),($i-5)); my $mount = (split /\s+/, $flarray[$mc])[1]; my $lvnam = (split /\s+/, $flarray[$lvsip])[3]; next if($mount =~ /None/); print "$i: VG: $hkey : MOUNT: $mount : LV_name: $lvnam : SIZE: $ +size\n"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Parsing a Large file with no reason
by Cristoforo (Curate) on Jan 29, 2010 at 02:25 UTC |