in reply to Re: huge problem!
in thread Inserting sequences without duplicates

my $in=join (", ", (map { $_ = "'$_'" } @one)); $sql="SELECT * FROM sistema WHERE codigo_inscripcion IN ($in) and mat +ricula='$matricula'"; $pdbh=$dbh->prepare($sql); $pdbh->execute(); # stuff here! while (my $ref = $pdbh->fetchrow_hashref()) { if($ref->{'mon'} != ''){$mon="Mon$ref->{'mon'})} if($ref->{'tue'} != ''){$mar="Tue$ref->{'tue'}"} if($ref->{'wed'} != ''){$mie="Wed$ref->{'wed'}"} if($ref->{'thu'} != ''){$jue="Thu$ref->{'thu'}"} if($ref->{'fri'} != ''){$vie="Fri$ref->{'fri'}"} if($ref->{'sat'} != ''){$sab="Sat$ref->{'sat'}"} if($ref->{'sun'} != ''){$dom="Sun$ref->{'sun'}"} } $pdbh->finish(); exit; if ($mon ne ''){ $lun=~ /([A-Za-z]*)([0-9]*)\/([0-9]*)/; for($z=$2;$z<$3;$z++) { push (@soft, "$1$z"); } push (@soft, "$1$3"); print @soft; exit;
Im trying with this... this is actually printing only 1 of
the selections how I want... but I think this code stinks!
If I select more than one row, it overwrites the value of
$mon and only shows me the last... I dunno how to do
this! Please HELP!

Replies are listed 'Best First'.
Re: Re: Re: huge problem!
by rdfield (Priest) on Sep 10, 2002 at 15:19 UTC
    You might want to start with
    use strict; use warnings; use diagnostics;
    and see what happens - I can see at least one typo that is causing you problems.

    rdfield

Re: Re: Re: huge problem!
by Joost (Canon) on Sep 10, 2002 at 15:28 UTC
    You could change the while loop to something like:
    my %seen; while (my $ref = $pdbh->fetchrow_hashref()) { for (qw(mon tue wed thu fri sat sun)) { my $result = lcfirst($_).$ref->{$_} if $ref->{$_}; if ($seen{$result}++) { warn "$seen found already"; } else { push @results,$result; } } } print join("\n",@results);
    That should print out the results with duplicates removed in the format you seem to want.
    -- Joost downtime n. The period during which a system is error-free and immune from user input.