Re: How can I do this in Perl?

2011-04-03 Thread Wernher Eksteen
Hi,

Thank you for showing me a better way to run the while loops, not
using the foreach loop, but the for loop and some
extra regex ways to accomplish things. Otherwise it prints out exactly
what I had before :-)

I have attached my request in a text file this time, to make it more
readable without email screwing up
the text alignment and formatting.

Please have a look and let me know how this could be done.

Basically, I need to compare the emcpower\w+\d partitions names from
the %allLocalMountedDisks hash
to that of the emcpower\w+ disks from the %allEmcMountedDisks hash.
I'm not sure, but I think the
emcpower\w+\d and emcpower\w+  names are the hash keys...? If so, then
I don't want to compare the
values/result of the hash keys, I just want to compare the hash keys
against another, and if matched
with =~ to append the key and values of %allLocalMountedDisks with the
matched keys and found values
found in %allLocalMountedDisks.

I know Perl is powerful, but until I understand Perl and hashes much
better I can't get this to work and
hope someone on this list can help me out so I can learn from that.

Please have a look at the attach text file where I try to explain as best I can.

Many thanks.

Kind regards,
Wernher
Thank you for correcting and showing me a better different way to do the while 
loops, but instead of the
two for loops printing the following out:

emcpowera   sdbd sddg sdfj sdhm   #  - [1st for loop output]
emcpoweraa  sdae sdch sdek sdgn   # These the available emcpower disks and 
their associate devices
emcpowerbc  sdb sdbe sddh sdfk
emcpowerc   sdbb sdde sdfh sdhk
emcpowerd   sdba sddd sdfg sdhj   # - [end of 1st for loop]

emcpowera1  /dwpdb006 # - [2nd for loop output]
emcpoweraa1 /dwpdb033 # These are the local emcpower* disk 
paritions and their local mount points.
emcpowerbc1 /s00_11   # Note that the emcpowerbc disk has 2 
partitions, 1 and 2 below.
emcpowerbc2 /utl_file_dir
emcpowerc1  /odsdb006
emcpowerd1  /odsdb005 # - [end of 2nd for loop]

How can I match the emcpower partitions ie: emcpowera1 as a result from the 2nd 
loop, to the emcpower disks 
ie: emcpowera as a result from the 1st loop.

What I would like to do is to compare what (emcpower\w+\d) partitions ie: 
emcpowera1 (seen from the output of
the 2nd for loop), where mounted against the available list of the 
(emcpower\w+) disk devices ie: emcpowera
(found in the 1st output) and then match on the (emcpower\w+) disk found (from 
1st output). The result of the 
output of the matched partition found (2nd output) must concatenate to the 
result of the emcpower disk (1st output), 
and then also show the (emcpower\w+) disks (from 1st output) that wasn't 
matched, if any.

In other words,

If emcpowera1 was found (from 2nd output), to match with emcpowera (from 1st 
output) and display the result 
along with the mount point that was found for emxpowera1 like this:

   emcpowera sdbd sddg sdfj sdhm emcpowera1 /dwpdb006

If there are any (emcpower\w+) disks ie: emxpowerz that wasn't matched by a 
(emxpower\w+\d) partition ie: emxpowerz1, 
to then only display normal output found in loop 1, because it doesn't have a 
matching partition ie:

emcpowerz sdbg sddv sdfd sdht

If there are more than one (emcpower\w+\d) partition, to display the output for 
example like this:

emcpowerbc  sdb sdbe sddh sdfk  emcpowerbc1 /s00_11
emcpowerbc2 /utl_file_dir

So the end result from the above should for example display:

emcpowera   sdbd sddg sdfj sdhm  emcpowera1  /dwpdb006
emcpoweraa  sdae sdch sdek sdgn  emcpoweraa1 /dwpdb033
emcpowerbc  sdb sdbe sddh sdfk   emcpowerbc1 /s00_11
sdba sddd sdfg sdhj  emcpowerbc2 /utl_file_dir
emcpowerc   sdbb sdde sdfh sdhk  emcpowerc1  /odsdb006
emcpowerd   sdba sddd sdfg sdhj  emcpowerd1  /odsdb005
emcpowerz   sdbg sddv sdfd sdht
-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Re: How can I do this in Perl?

2011-04-03 Thread John W. Krahn

Wernher Eksteen wrote:


Thank you for correcting and showing me a better different way to do the while 
loops, but instead of the
two for loops printing the following out:

emcpowera   sdbd sddg sdfj sdhm   #  - [1st for loop output]
emcpoweraa  sdae sdch sdek sdgn   # These the available emcpower disks and 
their associate devices
emcpowerbc  sdb sdbe sddh sdfk
emcpowerc   sdbb sdde sdfh sdhk
emcpowerd   sdba sddd sdfg sdhj   # - [end of 1st for loop]

emcpowera1  /dwpdb006 # - [2nd for loop output]
emcpoweraa1 /dwpdb033 # These are the local emcpower* disk 
paritions and their local mount points.
emcpowerbc1 /s00_11   # Note that the emcpowerbc disk has 2 
partitions, 1 and 2 below.
emcpowerbc2 /utl_file_dir
emcpowerc1  /odsdb006
emcpowerd1  /odsdb005 # - [end of 2nd for loop]

How can I match the emcpower partitions ie: emcpowera1 as a result from the 2nd 
loop, to the emcpower disks
ie: emcpowera as a result from the 1st loop.

What I would like to do is to compare what (emcpower\w+\d) partitions ie: 
emcpowera1 (seen from the output of
the 2nd for loop), where mounted against the available list of the 
(emcpower\w+) disk devices ie: emcpowera
(found in the 1st output) and then match on the (emcpower\w+) disk found (from 
1st output). The result of the
output of the matched partition found (2nd output) must concatenate to the 
result of the emcpower disk (1st output),
and then also show the (emcpower\w+) disks (from 1st output) that wasn't 
matched, if any.

In other words,

If emcpowera1 was found (from 2nd output), to match with emcpowera (from 1st 
output) and display the result
along with the mount point that was found for emxpowera1 like this:

   emcpowera sdbd sddg sdfj sdhm emcpowera1 /dwpdb006

If there are any (emcpower\w+) disks ie: emxpowerz that wasn't matched by a 
(emxpower\w+\d) partition ie: emxpowerz1,
to then only display normal output found in loop 1, because it doesn't have a 
matching partition ie:

emcpowerz sdbg sddv sdfd sdht

If there are more than one (emcpower\w+\d) partition, to display the output for 
example like this:

emcpowerbc  sdb sdbe sddh sdfk  emcpowerbc1 /s00_11
emcpowerbc2 /utl_file_dir

So the end result from the above should for example display:

emcpowera   sdbd sddg sdfj sdhm  emcpowera1  /dwpdb006
emcpoweraa  sdae sdch sdek sdgn  emcpoweraa1 /dwpdb033
emcpowerbc  sdb sdbe sddh sdfk   emcpowerbc1 /s00_11
sdba sddd sdfg sdhj  emcpowerbc2 /utl_file_dir

  ^^^
Why is this list


emcpowerc   sdbb sdde sdfh sdhk  emcpowerc1  /odsdb006
emcpowerd   sdba sddd sdfg sdhj  emcpowerd1  /odsdb005

  ^^^
the same as this list?


emcpowerz   sdbg sddv sdfd sdht





John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction.   -- Albert Einstein

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: How can I do this in Perl?

2011-04-02 Thread Wernher Eksteen
Hi,

The Perl script (shown further down below) gives me the following
output (without the comments).
Please note that this is not the complete output, I only show the
necessary detail for sake of clarity.

emcpowerasdbd sddg sdfj sdhm   #  - [1st foreach loop output]
emcpoweraa  sdae sdch sdek sdgn  # These the available
emcpower disks and their associate devices
emcpowerbc  sdb sdbe sddh sdfk
emcpowercsdbb sdde sdfh sdhk
emcpowerdsdba sddd sdfg sdhj
emcpowera1  /dwpdb006  #  - [2nd foreach loop output]
emcpoweraa1/dwpdb033  # These are the local
emcpower* disk paritions and their local mount points.
emcpowerbc1/s00_11  # Note that the
emcpowerbc disk has 2 partitions, 1 and 2 below.
emcpowerbc2/utl_file_dir
emcpowerc1  /odsdb006
emcpowerd1  /odsdb005

What I would like to do is to compare what (emcpower\w+\d) partitions
(seen from the output of the 2nd foreach loop), where mounted against
the available list of the (emcpower\w+) disk devices (found in the 1st
output) and then match on the (emcpower\w+) disk found (from 1st
output). The result of the output of the matched partition found (2nd
output) must concatenate to the result of the emcpower disk (1st
output), and then also show the (emcpower\w+) disks (from 1st output)
that wasn't matched, if any.

In other words,

If emcpowera1 was found (from 2nd output), to match with emcpowera
(from 1st output) and display the result as follow:

emcpowera sdbd sddg sdfj sdhm emcpowera1 /dwpdb006

If there are any (emcpower\w+) disks that wasn't matched by a
(emxpower\w+\d) partition, to then display that normally like ie:

 emcpowerz sdbd sddg sdfj sdhm

If there are more than one (emcpower\w+\d) partition, to display the
output for example like this:

 emcpowerbc  sdb sdbe sddh sdfk  emcpowerbc1 /s00_11

emcpowerbc2 /utl_file_dir

I have included comments in the script to make it as clear as possible.

I can send the raw input for both $powermt and $mount if you need
them, just let me know.

==

---script begin---
#!/usr/bin/perl

use strict;
use warnings;

my $powermt = '/sbin/powermt display dev=all';
my $mount = '/bin/mount';

open my $emcDisks, '-|', $powermt or die Could not execute powermt: $!;
open my $localDisks, '-|', $mount or die Could not execute mount: $!;

my ($emcDevices, $localSdDevices);
my (@allLocalEmcDisks, @allLocalSdDisks, @allLocalMountedDevices);
my (%allEmcMountedDisks, %allLocalMountedDisks);

# Locate all available emcpower* disks and all sd* disks associated
with each EMC PowerPath disk.
while (my $i = $emcDisks) {
 if ( $i =~ /name=(emcpower\w+)/ ) {
   $emcDevices = $1; # $1 = emcpowerbc
 } elsif ( $i =~ /\blpfc\s+(sd\w+)/ ) { # $i = (sdb, sdbe, sddh, sdfk)
   push @{$allEmcMountedDisks{$emcDevices}}, $1; # hash =
emcpowerbc[sdb, sdbe, sddh, sdfk]
 }
# Locate all local mounted /dev/emcpower* partitions and all
local mounted /dev/sd* disk partitions
while (my $b = $localDisks) {
if ($b =~ /\/dev\/(emcpower\w+\d)/) {
push @allLocalMountedDevices, $1; # $1 = emcpowerbc1
@allLocalEmcDisks = split (/\s+/, $b); # $b =
/dev/emcpowerbc1 on /s00_11 type ext3 (rw,acl,user_xattr)
push @{$allLocalMountedDisks{$1}},
$allLocalEmcDisks[2]; # hash = [emxpowerbc1, /s00_11]
} elsif ($b =~ /\/dev\/(sd\w+\d)/) {
push @allLocalMountedDevices, $1; # $1 = sdi1
@allLocalSdDisks = split (/\s+/, $b); # $b =
/dev/sdi1 on /dwpdb039 type ext3 (rw,acl,user_xattr)
push @{$allLocalMountedDisks{$1}},
$allLocalSdDisks[2]; # hash = [sdi, /dwpdb039]
}
}
}

# [1st foreach loop]
# Print each available emcpower* disks with their associated sd* disks
on the same line.
foreach my $i (sort keys %allEmcMountedDisks) {
printf %s\t%s\n, $i, join(' ', @{$allEmcMountedDisks{$i}});
}

# [2nd foreach loop]
# Print each local mouted disk found with it's mount point on the same line.
foreach my $i (sort keys %allLocalMountedDisks) {
printf \n%s %s\n, $i, join ' ', @{$allLocalMountedDisks{$i}};
}

---script end---
==

Regards,
Wernher Eksteen

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: How can I do this in Perl?

2011-04-02 Thread John W. Krahn

Wernher Eksteen wrote:

Hi,


Hello,


The Perl script (shown further down below) gives me the following
output (without the comments).
Please note that this is not the complete output, I only show the
necessary detail for sake of clarity.

emcpowerasdbd sddg sdfj sdhm   #- [1st foreach loop output]
emcpoweraa  sdae sdch sdek sdgn  # These the available
emcpower disks and their associate devices
emcpowerbc  sdb sdbe sddh sdfk
emcpowercsdbb sdde sdfh sdhk
emcpowerdsdba sddd sdfg sdhj
emcpowera1  /dwpdb006  #- [2nd foreach loop output]
emcpoweraa1/dwpdb033  # These are the local
emcpower* disk paritions and their local mount points.
emcpowerbc1/s00_11  # Note that the
emcpowerbc disk has 2 partitions, 1 and 2 below.
emcpowerbc2/utl_file_dir
emcpowerc1  /odsdb006
emcpowerd1  /odsdb005

What I would like to do is to compare what (emcpower\w+\d) partitions
(seen from the output of the 2nd foreach loop), where mounted against
the available list of the (emcpower\w+) disk devices (found in the 1st
output) and then match on the (emcpower\w+) disk found (from 1st
output). The result of the output of the matched partition found (2nd
output) must concatenate to the result of the emcpower disk (1st
output), and then also show the (emcpower\w+) disks (from 1st output)
that wasn't matched, if any.

In other words,

If emcpowera1 was found (from 2nd output), to match with emcpowera
(from 1st output) and display the result as follow:

 emcpowera sdbd sddg sdfj sdhm emcpowera1 /dwpdb006

If there are any (emcpower\w+) disks that wasn't matched by a
(emxpower\w+\d) partition, to then display that normally like ie:

  emcpowerz sdbd sddg sdfj sdhm

If there are more than one (emcpower\w+\d) partition, to display the
output for example like this:

  emcpowerbc  sdb sdbe sddh sdfk  emcpowerbc1 /s00_11

emcpowerbc2 /utl_file_dir

I have included comments in the script to make it as clear as possible.

I can send the raw input for both $powermt and $mount if you need
them, just let me know.

==



The inner while loop and the outer while loop do not have any variables 
in common.  But that is not the problem.


The inner while loop only executes *once* because once the filehandle 
reaches end-of-file it cannot read any more from that filehandle.


But it doesn't have to because no variables are used between the two 
while loops.  You probably want something like this:




#!/usr/bin/perl
use strict;
use warnings;

my $powermt = '/sbin/powermt display dev=all';
my $mount   = '/bin/mount';

open my $emcDisks, '-|', $powermt or die Could not execute $powermt: $!;

my ( $emcDevices, %allEmcMountedDisks );

# Locate all available emcpower* disks and all sd* disks associated with 
each EMC PowerPath disk.

while ( my $i = $emcDisks ) {
if ( $i =~ /name=(emcpower[a-z]+)/ ) {
$emcDevices = $1;# $1 = emcpowerbc
}
elsif ( $i =~ /\blpfc\s+(sd[a-z]+)/ ) {# $i = (sdb, sdbe, 
sddh, sdfk)
push @{ $allEmcMountedDisks{ $emcDevices } }, $1;# 
hash = emcpowerbc[sdb, sdbe, sddh, sdfk]

}
}

close $emcDisks or warn $! ? Error closing '$powermt' pipe: $!
   : Exit status $? from '$powermt';

# [1st foreach loop]
# Print each available emcpower* disks with their associated sd* disks 
on the same line.

for my $i ( sort keys %allEmcMountedDisks ) {
print $i\t@{$allEmcMountedDisks{$i}}\n;
}



open my $localDisks, '-|', $mount or die Could not execute $mount: $!;

my %allLocalMountedDisks;

# Locate all local mounted /dev/emcpower* partitions and all local 
mounted /dev/sd* disk partitions

while ( my $b = $localDisks ) {
if ( $b =~ m{/dev/((?:emcpower|sd)[a-z]+[1-9])\s+on\s+(/\w+)} ) {
# $b = /dev/emcpowerbc1 on /s00_11 type ext3 
(rw,acl,user_xattr)

# hash = [emxpowerbc1, /s00_11]
# $b = /dev/sdi1 on /dwpdb039 type ext3 (rw,acl,user_xattr)
# hash = [sdi, /dwpdb039]
push @{ $allLocalMountedDisks{ $1 } }, $2;
}
}

close $localDisks or warn $! ? Error closing $mount pipe: $!
 : Exit status $? from $mount;

# [2nd foreach loop]
# Print each local mouted disk found with it's mount point on the same line.
for my $i ( sort keys %allLocalMountedDisks ) {
print \n$i @{$allLocalMountedDisks{$i}}\n;
}





John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction.   -- Albert Einstein

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




How can I do this in Perl?

2011-04-01 Thread Wernher Eksteen
Hi,

From the folowing list is a result of the @power array, when run
through the foreach loop:

Pseudo name=emcpowerd
  1 lpfc  sdba SP A7 active  alive  0  0
  1 lpfc  sddd SP B7 active  alive  0  0
  3 lpfc  sdfg SP B6 active  alive  0  0
  3 lpfc  sdhj SP A6 active  alive  0  0
Pseudo name=emcpowerc
  1 lpfc  sdbb SP A7 active  alive  0  0
  1 lpfc  sdde SP B7 active  alive  0  0
  3 lpfc  sdfh SP B6 active  alive  0  0
  3 lpfc  sdhk SP A6 active  alive  0  0
Pseudo name=emcpoweraz
  1 lpfc  sdbh SP B7 active  alive  0  0
  3 lpfc  sddk SP B6 active  alive  0  0
  1 lpfc  sde  SP A7 active  alive  0  0
  3 lpfc  sdfn SP A6 active  alive  0  0

From the list above, how can Perl assign the sd* disks to it's
relevant emcpower device, so that the output shows this:

emcpowerdsdba sddd sdfg sdhj
emcpowercsdbb sdde sdfh sdhk
emcpoweraz  sdbh sddk sde sdfn

This is how the @power array was obtained:

$powermt = 'powermt display dev=all';
@power = `$powermt`;

foreach my $i (@power) {
   if (($i =~ /emcpower*/) || ($i =~ /lpfc*/)) {
   print $i;
   }
}

Thanks,
Wernher

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: How can I do this in Perl?

2011-04-01 Thread Uri Guttman
 WE == Wernher Eksteen crypt...@gmail.com writes:


  WE Pseudo name=emcpowerd
  WE   1 lpfc  sdba SP A7 active  alive  0 
 0
  WE   1 lpfc  sddd SP B7 active  alive  0 
 0
  WE   3 lpfc  sdfg SP B6 active  alive  0 
 0
  WE   3 lpfc  sdhj SP A6 active  alive  0 
 0
  WE Pseudo name=emcpowerc
  WE   1 lpfc  sdbb SP A7 active  alive  0 
 0
  WE   1 lpfc  sdde SP B7 active  alive  0 
 0
  WE   3 lpfc  sdfh SP B6 active  alive  0 
 0
  WE   3 lpfc  sdhk SP A6 active  alive  0 
 0
  WE Pseudo name=emcpoweraz
  WE   1 lpfc  sdbh SP B7 active  alive  0 
 0
  WE   3 lpfc  sddk SP B6 active  alive  0 
 0
  WE   1 lpfc  sde  SP A7 active  alive  0 
 0
  WE   3 lpfc  sdfn SP A6 active  alive  0 
 0

   From the list above, how can Perl assign the sd* disks to it's
  WE relevant emcpower device, so that the output shows this:

  WE emcpowerdsdba sddd sdfg sdhj
  WE emcpowercsdbb sdde sdfh sdhk
  WE emcpoweraz  sdbh sddk sde sdfn

  WE This is how the @power array was obtained:

  WE $powermt = 'powermt display dev=all';
  WE @power = `$powermt`;

  WE foreach my $i (@power) {
  WEif (($i =~ /emcpower*/) || ($i =~ /lpfc*/)) {

that * isn't doing what you think it does. perl regexes are not shell
globs. it happens to work anyway since the tokens are unique
enough. read perlretut to learn perl regexes.

what have you tried so far? you know enough perl to get the array of
lines and loop over that. in english (or your native tongue), just
describe how you would do it to get to your goal. write it down. it is
only a few steps. then it will be easier to convert that to the perl
needed to accomplish it. if you then have more troubles, post your code
here and you will get help. a clue: you need a hash and its values will
be array references. read perlreftut, perllol and perldsc for more on
that.

uri

-- 
Uri Guttman  --  u...@stemsystems.com    http://www.sysarch.com --
-  Perl Code Review , Architecture, Development, Training, Support --
-  Gourmet Hot Cocoa Mix    http://bestfriendscocoa.com -

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: How can I do this in Perl?

2011-04-01 Thread Rob Dixon

On 01/04/2011 19:52, Wernher Eksteen wrote:


 From the folowing list is a result of the @power array, when run
through the foreach loop:

Pseudo name=emcpowerd
   1 lpfc  sdba SP A7 active  alive  0  0
   1 lpfc  sddd SP B7 active  alive  0  0
   3 lpfc  sdfg SP B6 active  alive  0  0
   3 lpfc  sdhj SP A6 active  alive  0  0
Pseudo name=emcpowerc
   1 lpfc  sdbb SP A7 active  alive  0  0
   1 lpfc  sdde SP B7 active  alive  0  0
   3 lpfc  sdfh SP B6 active  alive  0  0
   3 lpfc  sdhk SP A6 active  alive  0  0
Pseudo name=emcpoweraz
   1 lpfc  sdbh SP B7 active  alive  0  0
   3 lpfc  sddk SP B6 active  alive  0  0
   1 lpfc  sde  SP A7 active  alive  0  0
   3 lpfc  sdfn SP A6 active  alive  0  0

 From the list above, how can Perl assign the sd* disks to it's
relevant emcpower device, so that the output shows this:

emcpowerdsdba sddd sdfg sdhj
emcpowercsdbb sdde sdfh sdhk
emcpoweraz  sdbh sddk sde sdfn

This is how the @power array was obtained:

$powermt = 'powermt display dev=all';
@power = `$powermt`;

foreach my $i (@power) {
if (($i =~ /emcpower*/) || ($i =~ /lpfc*/)) {
print $i;
}
}


Please always 'use strict' and 'use warnings', and consequently declare
all of your variables. That way most straightforward problems will be
solved my Perl before ever reaching his list.

It is better to open a pipe to a child process running your command,
rather than read all the output into an array and process that. I
suggest something like the program below, which builds a hash of the
device/disk relationship and prints it out at the end.

HTH,

Rob


use strict;
use warnings;

my $powermt = 'powermt display dev=all';

open my $fh, '-|', $powermt or die $!;

my ($device, %disks);

while (my $line = $fh) {

  if ( $line =~ /name=(emcpower\w+)/ ) {
$device = $1;
  }
  elsif ( $line =~ /\blpfc\s+(sd\w+)/ ) {
push @{$disks{$device}}, $1;
  }
}

foreach my $device (sort keys %disks) {
  printf %s  %s\n, $device, join ' ', @{$disks{$device}};
}

** OUTPUT **

emcpoweraz  sdbh sddk sde sdfn
emcpowerc  sdbb sdde sdfh sdhk
emcpowerd  sdba sddd sdfg sdhj

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: How can I do this in Perl?

2011-04-01 Thread Wernher Eksteen
 Please always 'use strict' and 'use warnings', and consequently declare
 all of your variables. That way most straightforward problems will be
 solved my Perl before ever reaching his list.

Thanks, I will remember to do so for future.

 It is better to open a pipe to a child process running your command,
 rather than read all the output into an array and process that. I
 suggest something like the program below, which builds a hash of the
 device/disk relationship and prints it out at the end.

 HTH,

 Rob

Thanks Rob, this works fantastic!

Regards,
Wernher Eksteen

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: How can I do this in Perl?

2011-04-01 Thread Wernher Eksteen
 that * isn't doing what you think it does. perl regexes are not shell
 globs. it happens to work anyway since the tokens are unique
 enough. read perlretut to learn perl regexes.

 what have you tried so far? you know enough perl to get the array of
 lines and loop over that. in english (or your native tongue), just
 describe how you would do it to get to your goal. write it down. it is
 only a few steps. then it will be easier to convert that to the perl
 needed to accomplish it. if you then have more troubles, post your code
 here and you will get help. a clue: you need a hash and its values will
 be array references. read perlreftut, perllol and perldsc for more on
 that.

 uri

Thanks Uri, I will take this into consideration and learn from this
going forward
and also make sure I understand what Rob's answer actually does and compare
notes and reference with the likes of perltut etc.

Kind regards,
Wernher

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




RE: can i do it with perl ?

2004-01-28 Thread Dan Muey
   I there, 
 

Ello!

  I need to write a web database application using
 perl, and i need a way that when the users logs into
 the system  i download all the information regarding
 to the user to its local computer and make all the
 transaction locally.  After that, when the user logs
 out of the system all the information and transaction
 that were made by that user are then updated to the
 database server.   Can i do it with perl ?, which
 modules ?,  thanks.

Yes you can.
Look at cpan for DBI (for database stuff) CGI (for handling form input)

HTH

Dmuey 

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: can i do it with perl ?

2004-01-24 Thread Dan Anderson
On Fri, 2004-01-23 at 20:49, John McKown wrote:
 On Fri, 23 Jan 2004, Dan Anderson wrote:
 
  
  Give me a little bit of time with a soldering iron, some wire, and a
  laptop connected to your home network and your dishwasher and that can
  be rectified.  :-D
  
  -Dan
 
 I don't think that the lady who comes in and does my dishes is going to 
 let you anywhere near her with a soldering iron in your hand! grin

We are borg.  You will be assimilated.  Resistance is futile. grin

-Dan


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: can i do it with perl ?

2004-01-24 Thread drieux
On Jan 24, 2004, at 12:48 PM, Dan Anderson wrote:
On Fri, 2004-01-23 at 20:49, John McKown wrote:
On Fri, 23 Jan 2004, Dan Anderson wrote:
Give me a little bit of time with a soldering iron, some wire, and a
laptop connected to your home network and your dishwasher and that 
can
be rectified.  :-D
I don't think that the lady who comes in and does my dishes is going 
to
let you anywhere near her with a soldering iron in your hand! grin
We are borg.  You will be assimilated.  Resistance is futile. grin
why does

	perldoc Cleaning::Woman

cause my computer to go into a rage about the
cleaning woman[1]
And do I need to take down the Satelite Dish first
before trying to wash it Or can I put the whole
house into the dishwasher
You know this with trying to be a Terran is
clearly much tougher than the original briefing said...
ciao
drieux
---

[1] cf:  Deadmen don't wear plaid for those
who may not be old enough to remember that Homage
to Film Noir
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



can i do it with perl ?

2004-01-23 Thread Joe Echavarria

  I there, 

 I need to write a web database application using
perl, and i need a way that when the users logs into
the system  i download all the information regarding
to the user to its local computer and make all the
transaction locally.  After that, when the user logs
out of the system all the information and transaction
that were made by that user are then updated to the
database server.   Can i do it with perl ?, which
modules ?,  thanks.

__
Do you Yahoo!?
Yahoo! SiteBuilder - Free web site building tool. Try it!
http://webhosting.yahoo.com/ps/sb/

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: can i do it with perl ?

2004-01-23 Thread Bob Showalter
Joe Echavarria wrote:
   I there,
 
  I need to write a web database application using
 perl, and i need a way that when the users logs into
 the system  i download all the information regarding
 to the user to its local computer and make all the
 transaction locally.  After that, when the user logs
 out of the system all the information and transaction
 that were made by that user are then updated to the
 database server.   

Why does it need to work that way?

 Can i do it with perl ?, 

Sure.

 which modules ?,  thanks.

Too soon to say.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: can i do it with perl ?

2004-01-23 Thread wolf blaum
   I there,
Hi, 
  I need to write a web database application using
 perl, and i need a way that when the users logs into
 the system  i download all the information regarding
 to the user to its local computer and make all the
 transaction locally.  After that, when the user logs
 out of the system all the information and transaction
 that were made by that user are then updated to the
 database server.   Can i do it with perl ?, which
 modules ?,  thanks.

Why does it have to be a web application? 
Or rather just a client/server thing?
What Database?
I didnt find a way to do the dishes yet, anything else I ever tried works in 
perl.

Just give us some more info.
Wolf


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: can i do it with perl ?

2004-01-23 Thread Daniel Staal
--As off Saturday, January 24, 2004 12:07 AM +0100, wolf blaum is 
alleged to have said:

I didnt find a way to do the dishes yet, anything else I ever tried
works in  perl.
--As for the rest, it is mine.

I'm sure you could do something with LEGO::RCX and a Mindstorms kit...
;-)
Daniel T. Staal

---
This email copyright the author.  Unless otherwise noted, you
are expressly allowed to retransmit, quote, or otherwise use
the contents for non-commercial purposes.  This copyright will
expire 5 years after the author's death, or in 30 years,
whichever is longer, unless such a period is in excess of
local copyright law.
---
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: can i do it with perl ?

2004-01-23 Thread Dan Anderson
On Fri, 2004-01-23 at 18:07, wolf blaum wrote:
I there,
 Hi, 
   I need to write a web database application using
  perl, and i need a way that when the users logs into
  the system  i download all the information regarding
  to the user to its local computer and make all the
  transaction locally.  After that, when the user logs
  out of the system all the information and transaction
  that were made by that user are then updated to the
  database server.   Can i do it with perl ?, which
  modules ?,  thanks.
 
 Why does it have to be a web application? 
 Or rather just a client/server thing?
 What Database?
 I didnt find a way to do the dishes yet, anything else I ever tried works in 
 perl.

Give me a little bit of time with a soldering iron, some wire, and a
laptop connected to your home network and your dishwasher and that can
be rectified.  :-D

-Dan


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: can i do it with perl ?

2004-01-23 Thread wolf blaum
 Give me a little bit of time with a soldering iron, some wire, and a
 laptop connected to your home network and your dishwasher and that can
 be rectified.  :-D

I new that was a gentle list!
I just dont have a dishwasher :(
But given the traffic here I happily dont get much time to use dishes at all.

Have a nice weekend, Wolf


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: can i do it with perl ?

2004-01-23 Thread John McKown
On Fri, 23 Jan 2004, Joe Echavarria wrote:

 
   I there, 
 
  I need to write a web database application using
 perl, and i need a way that when the users logs into
 the system  i download all the information regarding
 to the user to its local computer and make all the
 transaction locally.  After that, when the user logs
 out of the system all the information and transaction
 that were made by that user are then updated to the
 database server.   Can i do it with perl ?, which
 modules ?,  thanks.
 

Unless this is an in house application for internal business use, I'd 
suggest against it. The main reason is that you are downloading something 
to the user's computer. They may not like that very much at all! I know 
that if a web site wanted to put some application on my machine, I'd tell 
them to take a walk. If the visitors are on a company PC, they might not 
even be able to install your application on their system. I know that our 
PC people do _not_ allow any unauthorized software to be installed by the 
user. In fact, any software going onto a PC owned by our company _must_ be 
tested and approved by our Integration Lab. The end-users do not have 
the authority to do any sort of installation.

Also, if your software is written in Perl, you would be forcing the users 
of it to have Perl installed. This may or may not be true.

And what DB are you considering? That would need to be installed as well. 
Along with the Perl bindings. Unless it was integrated with Perl.

Now, suppose we get by all my objections. How would you upload the 
changed data? What if another person had changed the same datum? How do 
you guarantee the reliability of your data? What if the user's computer 
dies (blue screens)? What if the user simply does not log off of your 
application?

I think this is going to be very difficult. Good luck to you!

--
Maranatha!
John McKown


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: can i do it with perl ?

2004-01-23 Thread John McKown
On Fri, 23 Jan 2004, Dan Anderson wrote:

 
 Give me a little bit of time with a soldering iron, some wire, and a
 laptop connected to your home network and your dishwasher and that can
 be rectified.  :-D
 
 -Dan

I don't think that the lady who comes in and does my dishes is going to 
let you anywhere near her with a soldering iron in your hand! grin

--
Maranatha!
John McKown


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Can I do this with perl?

2002-03-04 Thread Dave Adams

Hi there,

I have a problem which I would like to use perl to resolve, however I'm not
sure if it is possible to do. 

I need to scan a file and check some conditions, first if field 9 is
duplicated on 1 or more rows, then I need to check field 10 to see which is
the greater value and then only print the whole row where field 10 is the
greater, if field 9 is not a duplicate then print the whole row.
An example of the data is below.

28525|U2|4CY0|50|6775.15|2002-02-07|10461|321.43|102040724|102040773|
28526|U2|4CY0|25|3571.78|2002-02-07|6107|167.74|102040774|102040798|
28527|U2|4CY0|50|6930.3|2002-02-07|11376|324.12|102040774|102040823|
28528|U2|4CY0|25|4640.28|2002-02-07|4800|217.43|102040824|102040848|
28529|U2|4CY0|50|8432.05|2002-02-07|9023|392.03|102040824|102040873|

Dave



Re: Can I do this with perl?

2002-03-04 Thread Jon Molin

Dave Adams wrote:
 
 Hi there,
 
 I have a problem which I would like to use perl to resolve, however I'm not
 sure if it is possible to do.
 
 I need to scan a file and check some conditions, first if field 9 is
 duplicated on 1 or more rows, then I need to check field 10 to see which is
 the greater value and then only print the whole row where field 10 is the
 greater, if field 9 is not a duplicate then print the whole row.
 An example of the data is below.
 
 28525|U2|4CY0|50|6775.15|2002-02-07|10461|321.43|102040724|102040773|
 28526|U2|4CY0|25|3571.78|2002-02-07|6107|167.74|102040774|102040798|
 28527|U2|4CY0|50|6930.3|2002-02-07|11376|324.12|102040774|102040823|
 28528|U2|4CY0|25|4640.28|2002-02-07|4800|217.43|102040824|102040848|
 28529|U2|4CY0|50|8432.05|2002-02-07|9023|392.03|102040824|102040873|

read about split, arrays and hashes and i bet you'll solve it in an
hour.

perldoc -f splir perlfunc
perldoc perldata


/jon


 
 Dave

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Can I do this with perl?

2002-03-04 Thread Nikola Janceski

Yes you can do it with perl, and I suggest using hashes.

open(FILE, $file);
my %seen;
while(FILE){
my ($item9, $item10) = (split /\|/, $_)[8,9];
if(exists $seen{$item9}){
if($itme10  $seen{$item9}){
# the new $item10 is larger than the last one seen
} else {
# the contrary is true
}

} else {
$seen{$item9} = $itme10;
}
close FILE;

-Original Message-
From: Dave Adams [mailto:[EMAIL PROTECTED]]
Sent: Monday, March 04, 2002 10:10 AM
To: [EMAIL PROTECTED]
Subject: Can I do this with perl?


Hi there,

I have a problem which I would like to use perl to resolve, however I'm not
sure if it is possible to do. 

I need to scan a file and check some conditions, first if field 9 is
duplicated on 1 or more rows, then I need to check field 10 to see which is
the greater value and then only print the whole row where field 10 is the
greater, if field 9 is not a duplicate then print the whole row.
An example of the data is below.

28525|U2|4CY0|50|6775.15|2002-02-07|10461|321.43|102040724|102040773|
28526|U2|4CY0|25|3571.78|2002-02-07|6107|167.74|102040774|102040798|
28527|U2|4CY0|50|6930.3|2002-02-07|11376|324.12|102040774|102040823|
28528|U2|4CY0|25|4640.28|2002-02-07|4800|217.43|102040824|102040848|
28529|U2|4CY0|50|8432.05|2002-02-07|9023|392.03|102040824|102040873|

Dave



The views and opinions expressed in this email message are the sender's
own, and do not necessarily represent the views and opinions of Summit
Systems Inc.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Can I do this with perl?

2002-03-04 Thread Brett W. McCoy

On Mon, 4 Mar 2002, Dave Adams wrote:

 I have a problem which I would like to use perl to resolve, however I'm not
 sure if it is possible to do.

 I need to scan a file and check some conditions, first if field 9 is
 duplicated on 1 or more rows, then I need to check field 10 to see which is
 the greater value and then only print the whole row where field 10 is the
 greater, if field 9 is not a duplicate then print the whole row.
 An example of the data is below.

 28525|U2|4CY0|50|6775.15|2002-02-07|10461|321.43|102040724|102040773|
 28526|U2|4CY0|25|3571.78|2002-02-07|6107|167.74|102040774|102040798|
 28527|U2|4CY0|50|6930.3|2002-02-07|11376|324.12|102040774|102040823|
 28528|U2|4CY0|25|4640.28|2002-02-07|4800|217.43|102040824|102040848|
 28529|U2|4CY0|50|8432.05|2002-02-07|9023|392.03|102040824|102040873|

Of course this can be done with Perl, although the algorithm will take
some thinking through.  You should be able to read these rows into an
array (using split, et al).

However, this will be much easier if you can get this into a real
database system so you can use DBI.  In fact, a text file like this can
even be used with DBI -- take a look at DBD:CSV.  It lets you create and
manipulate tables via SQL, which would make your problem much simpler
(although DBD::CSV may have problems enforcing unique constraints).
Otherwise, if you have a good bit of data to deal with, take a look at a
database system like PostgreSQL, which can easily handle the logic you are
trying to implement.

-- Brett
  http://www.chapelperilous.net/

To do nothing is to be nothing.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Can I do this with perl?

2002-03-04 Thread Chas Owens

A quick dissection of what is going on here:

On Mon, 2002-03-04 at 10:20, Nikola Janceski wrote:
 Yes you can do it with perl, and I suggest using hashes.
 
 open(FILE, $file);

This opens a file and associates it with FILE; you really should say
something like 'or die Could not open $file:$!' to make sure the file
opened.

 my %seen;

Creates a hash variable named %seen;

 while(FILE){

This loops while there are still lines left to read from FILE.  I would
have used just the  operator to read from either the stdin or files
named on the command line and ditched the open above, but that is just a
style issue.

   my ($item9, $item10) = (split /\|/, $_)[8,9];

This line is fairly complicated.  First we are splitting the line read
by the while above into a list using the '|' character as the
separator.  Then taking an array slice (a method of returning only a
subset of an array) that contains the ninth and tenth fields (remember
Perl uses zero based arrays).  Finally we are storing field nine into
$item9 and field ten into $item10.  

   if(exists $seen{$item9}){

This bit of code checks to see if we have seen $item9 before by checking
to see if it exists in the hash %seen.  This would normally  be
shortened to if ($seen{$item9}) { since the value associated with any
key not stored in the hash is undef by default and undef is equivalent
to false, but we are storing field ten in it later and field ten can be
0 (which is also false).

   if($itme10  $seen{$item9}){
   # the new $item10 is larger than the last one seen

You would want to say 'print $_;' (or possibly jsut 'print;' since print
uses the default variable, $_, when there are no other arguments) here
to print the record.

   } else {
   # the contrary is true
   }
   
   } else {
   $seen{$item9} = $itme10;

Here we are setting the value of the key $item9 to the value $item10 in
the hash named %seen.  This is also where you would want to print the
record since it is the first time we have seen $item9.  See above for
how to do that.

   }
 close FILE;

This closes the file associated with FILE.  It is not completely
necessary since perl will close all open file handles on exit, but I
think it is good practice. 

 
 -Original Message-
 From: Dave Adams [mailto:[EMAIL PROTECTED]]
 Sent: Monday, March 04, 2002 10:10 AM
 To: [EMAIL PROTECTED]
 Subject: Can I do this with perl?
 
 
 Hi there,
 
 I have a problem which I would like to use perl to resolve, however I'm not
 sure if it is possible to do. 
 
 I need to scan a file and check some conditions, first if field 9 is
 duplicated on 1 or more rows, then I need to check field 10 to see which is
 the greater value and then only print the whole row where field 10 is the
 greater, if field 9 is not a duplicate then print the whole row.
 An example of the data is below.
 
 28525|U2|4CY0|50|6775.15|2002-02-07|10461|321.43|102040724|102040773|
 28526|U2|4CY0|25|3571.78|2002-02-07|6107|167.74|102040774|102040798|
 28527|U2|4CY0|50|6930.3|2002-02-07|11376|324.12|102040774|102040823|
 28528|U2|4CY0|25|4640.28|2002-02-07|4800|217.43|102040824|102040848|
 28529|U2|4CY0|50|8432.05|2002-02-07|9023|392.03|102040824|102040873|
 
 Dave
 
 
 
 The views and opinions expressed in this email message are the sender's
 own, and do not necessarily represent the views and opinions of Summit
 Systems Inc.
 
 
 -- 
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
-- 
Today is Pungenday the 63rd day of Chaos in the YOLD 3168
You are what you see.

Missile Address: 33:48:3.521N  84:23:34.786W


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Can I do this with perl?

2002-03-04 Thread Chas Owens

On Mon, 2002-03-04 at 10:32, Brett W. McCoy wrote:
 On Mon, 4 Mar 2002, Dave Adams wrote:
 
  I have a problem which I would like to use perl to resolve, however I'm not
  sure if it is possible to do.
 
  I need to scan a file and check some conditions, first if field 9 is
  duplicated on 1 or more rows, then I need to check field 10 to see which is
  the greater value and then only print the whole row where field 10 is the
  greater, if field 9 is not a duplicate then print the whole row.
  An example of the data is below.
 
  28525|U2|4CY0|50|6775.15|2002-02-07|10461|321.43|102040724|102040773|
  28526|U2|4CY0|25|3571.78|2002-02-07|6107|167.74|102040774|102040798|
  28527|U2|4CY0|50|6930.3|2002-02-07|11376|324.12|102040774|102040823|
  28528|U2|4CY0|25|4640.28|2002-02-07|4800|217.43|102040824|102040848|
  28529|U2|4CY0|50|8432.05|2002-02-07|9023|392.03|102040824|102040873|
 
 Of course this can be done with Perl, although the algorithm will take
 some thinking through.  You should be able to read these rows into an
 array (using split, et al).
 
 However, this will be much easier if you can get this into a real
 database system so you can use DBI.  In fact, a text file like this can
 even be used with DBI -- take a look at DBD:CSV.  It lets you create and
 manipulate tables via SQL, which would make your problem much simpler
 (although DBD::CSV may have problems enforcing unique constraints).
 Otherwise, if you have a good bit of data to deal with, take a look at a
 database system like PostgreSQL, which can easily handle the logic you are
 trying to implement.
 
 -- Brett
   http://www.chapelperilous.net/
 
 To do nothing is to be nothing.

As a DBA I disagree.  Text processing is often faster and easier to
write.  Relational Databases are very good at somethings: referential
integrity, interactivity, data mining, etc.  Relational Databases
absolutely suck at this sort of self referential question where one
value in the table .  The first obvious solution using a RDB (build a
cursor of the data and looking at the ninth and tenth fields) is no
better than the Perl solution -- in fact is much slower since there are
multiple sql calls that must execute.  Besides, based on the look of the
file (pipe delimited, with one pipe per column) I think the data was
already in a DB.



-- 
Today is Pungenday the 63rd day of Chaos in the YOLD 3168
Grudnuk demand sustenance!

Missile Address: 33:48:3.521N  84:23:34.786W


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Can I do this with perl?

2002-03-04 Thread Jenda Krynicky

From: Chas Owens [EMAIL PROTECTED]
 On Mon, 2002-03-04 at 10:32, Brett W. McCoy wrote:
  On Mon, 4 Mar 2002, Dave Adams wrote:
  
   I have a problem which I would like to use perl to resolve,
   however I'm not sure if it is possible to do.
  
   I need to scan a file and check some conditions, first if field 9
   is duplicated on 1 or more rows, then I need to check field 10 to
   see which is the greater value and then only print the whole row
   where field 10 is the greater, if field 9 is not a duplicate then
   print the whole row. An example of the data is below.
  
   28525|U2|4CY0|50|6775.15|2002-02-07|10461|321.43|102040724|1020407
   73|
   28526|U2|4CY0|25|3571.78|2002-02-07|6107|167.74|102040774|10204079
   8|
   28527|U2|4CY0|50|6930.3|2002-02-07|11376|324.12|102040774|10204082
   3|
   28528|U2|4CY0|25|4640.28|2002-02-07|4800|217.43|102040824|10204084
   8|
   28529|U2|4CY0|50|8432.05|2002-02-07|9023|392.03|102040824|10204087
   3|
  
  Of course this can be done with Perl, although the algorithm will
  take some thinking through.  You should be able to read these rows
  into an array (using split, et al).
  
  However, this will be much easier if you can get this into a real
  database system so you can use DBI.  In fact, a text file like this
  can even be used with DBI -- take a look at DBD:CSV.  It lets you
  create and manipulate tables via SQL, which would make your problem
  much simpler (although DBD::CSV may have problems enforcing unique
  constraints). Otherwise, if you have a good bit of data to deal
  with, take a look at a database system like PostgreSQL, which can
  easily handle the logic you are trying to implement.
  
  -- Brett
 
 As a DBA I disagree.  Text processing is often faster and easier to
 write. 

Depends. If you can go through the data once and mungle it as you 
go it will definitely be quicker if you do it from within Perl instead of 
pushing it into database and selecting something.

In this case though it's not that easy. The problem is that the 
original request was if field 9 is duplicated on 1 or more rows, then 
I need to check field 10 to see which is the greater value and then 
only print the whole row where field 10 is the greater, if field 9 is not 
a duplicate then print the whole row.

You could do that from within Perl, you just had to remember the 
rows you've read in a hash, check whether you've seen a row with 
the same Field_9, remember the one with greater Field_10 and go 
on. And you'd only started printing when done with reading (I'm 
assuming the data are NOT sorted on Field_9 !!!)

Or you could sort the data on Field_9 (any direction you like) and 
Field_10 (DESCending preferably) and then only print the first row 
with the same Field_9.

On the other hand if you had the data in the database you could 
write this:

SELECT Field_1, Field_2, Field_3, Field_4, Field_5, Field_6, 
Field_7, Field_8, Field_9, max(Field_10), Field_11
FROM MyData 
GROUP BY Field_1, Field_2, Field_3, Field_4, Field_5, Field_6, 
Field_7, Field_8, Field_9, Field_11

or

SELECT * 
FROM MyData, (SELECT Field_9, Max(Field_10) as Max_Field_10
FROM MyData
Group BY Field_9
) as Max_MyData
WHERE MyData.Field_9 = Max_MyData.Field_9
   AND MyData.Field_10 = Max_MyData.Max_Field_10

No need for cursors ... but if there is not an index on Field_9 it'll be 
terribly slow.

But still if you only need to do this it's not worth it to push the data 
into a database.

Jenda

=== [EMAIL PROTECTED] == http://Jenda.Krynicky.cz ==
There is a reason for living. There must be. I've seen it somewhere.
It's just that in the mess on my table ... and in my brain.
I can't find it.
--- me

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]