Re: Repetead values

2005-10-14 Thread John W. Krahn
Rafael Morales wrote:
> Yes it works but I also need to print the files with values with
> '0', and your code just prints the files that have values different
> of '0', for example when I use your code I got this:
> 
> 2005-09-19 - NA - 56 - 788
> 2005-09-19 - NA - 43 - 540
> 2005-09-19 - NE - 10 - 975
> 2005-09-19 - SP - 23 - 321
> 
> 
> But I need these too:
> 
> 2005-09-19 - NCW - 0 - 0
> 2005-09-19 - S - 0 - 0
> 2005-09-19 - SE - 0 - 0
> 
> How can I get them all ???

I don't know.  I don't know what your data looks like or how you are parsing
it or what the contents of %hash really are.


John
-- 
use Perl;
program
fulfillment

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




Re: Repetead values

2005-10-14 Thread Rafael Morales
Yes it works but I also need to print the files with values with '0', and your 
code just prints the files that have values different of '0', for example when 
I use your code I got this:

2005-09-19 - NA - 56 - 788
2005-09-19 - NA - 43 - 540
2005-09-19 - NE - 10 - 975
2005-09-19 - SP - 23 - 321


But I need these too:

2005-09-19 - NCW - 0 - 0
2005-09-19 - S - 0 - 0
2005-09-19 - SE - 0 - 0

How can I get them all ???
Thanks for your help John :).


- Original Message -
From: "John W. Krahn" <[EMAIL PROTECTED]>
To: "Perl Beginners" 
Subject: Re: Repetead values
Date: Fri, 14 Oct 2005 14:39:16 -0700

> 
> Rafael Morales wrote:
> > Hi.
> 
> Hello,
> 
> > My trouble is with a value duplicated value on a nested foreach, 
> > these are my variables:
> >
> > %names=(
> > 1=>'NA'
> > 2=>'NCW'
> > 3=>'NE'
> > 4=>'S'
> > 5=>'SE'
> > 6=>'SP'
> >);
> >
> > %hash{'2005-09-19'}{'1'}{'56'}=788;
> > %hash{'2005-09-19'}{'1'}{'43'}=540;
> > %hash{'2005-09-19'}{'6'}{'23'}=321;
> > %hash{'2005-09-19'}{'3'}{'10'}=975;
> >
> > And I want an output like this:
> > 2005-09-19 - NA - 56 - 788
> > 2005-09-19 - NA - 43 - 540
> > 2005-09-19 - NCW - 0 - 0
> > 2005-09-19 - NE - 10 - 975
> > 2005-09-19 - S - 0 - 0
> > 2005-09-19 - SE - 0 - 0
> > 2005-09-19 - SP - 23 - 321
> >
> > I do it by this way:
> >
> > my %final;
> > my $match = 0;
> > foreach my $date(sort keys %hash) {
> >   foreach my $num_name(sort {$a <=> $b}(keys %{$hash{$date}}) ) {
> > foreach my $names(sort {$a <=> $b}(keys %names) ) {
> >   if ($num_name == $names) {  $match = 1;
> > foreach my $values(sort {$a <=> $b}(keys 
> > %{$hash{$date}{$num_state}}) ) {
> >
> > $final{$date}{$names{$names}}{$values}=$hash{$date}{$num_state}{$values};   
> >  
> >  } #end values
> >   } #end if
> >   else {$match = 0;}
> > }end names
> > if ($match == 0){
> >$final{$date}{$names{$names}}{0}=0;
> > }#end if
> >   }end num_name
> > }end date
> >
> > However this is what I get:
> > 2005-09-19 - NA - 0 - 0 <- Repeated value :(
> > 2005-09-19 - NA - 56 - 788
> > 2005-09-19 - NA - 43 - 540
> > 2005-09-19 - NCW - 0 - 0
> > 2005-09-19 - NE - 10 - 975
> > 2005-09-19 - S - 0 - 0
> > 2005-09-19 - SE - 0 - 0
> > 2005-09-19 - SP - 23 - 321
> 
> It looks like you want something like:
> 
> for my $date ( keys %hash ) {
>  for my $num_name ( keys %{ $hash{ $date } } ) {
>  if ( exists $names{ $num_name } ) {
>  $hash{ $date }{ $names{ $num_name } }
>  = delete $hash{ $date }{ $num_name };
>  }
>  }
>  }
> 
> 
> 
> John
> --
> use Perl;
> program
> fulfillment
> 
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> <http://learn.perl.org/> <http://learn.perl.org/first-response>


-- 
___
Get your free email from http://mymail.bsdmail.com

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




Re: Repetead values

2005-10-14 Thread John W. Krahn
Rafael Morales wrote:
> Hi.

Hello,

> My trouble is with a value duplicated value on a nested foreach, these are my 
> variables:
> 
> %names=(
> 1=>'NA'
> 2=>'NCW'
> 3=>'NE'
> 4=>'S'
> 5=>'SE'
> 6=>'SP'
>);
> 
> %hash{'2005-09-19'}{'1'}{'56'}=788;
> %hash{'2005-09-19'}{'1'}{'43'}=540;
> %hash{'2005-09-19'}{'6'}{'23'}=321;
> %hash{'2005-09-19'}{'3'}{'10'}=975;
> 
> And I want an output like this:
> 2005-09-19 - NA - 56 - 788
> 2005-09-19 - NA - 43 - 540
> 2005-09-19 - NCW - 0 - 0
> 2005-09-19 - NE - 10 - 975
> 2005-09-19 - S - 0 - 0
> 2005-09-19 - SE - 0 - 0
> 2005-09-19 - SP - 23 - 321
> 
> I do it by this way:
> 
> my %final;
> my $match = 0;
> foreach my $date(sort keys %hash) {
>   foreach my $num_name(sort {$a <=> $b}(keys %{$hash{$date}}) ) {
> foreach my $names(sort {$a <=> $b}(keys %names) ) {
>   if ($num_name == $names) {  
> $match = 1;
> foreach my $values(sort {$a <=> $b}(keys %{$hash{$date}{$num_state}}) 
> ) {
>
> $final{$date}{$names{$names}}{$values}=$hash{$date}{$num_state}{$values}; 
> } #end values
>   } #end if
>   else {$match = 0;}
> }end names
> if ($match == 0){
>$final{$date}{$names{$names}}{0}=0;
> }#end if
>   }end num_name
> }end date
> 
> However this is what I get:
> 2005-09-19 - NA - 0 - 0 <- Repeated value :(
> 2005-09-19 - NA - 56 - 788
> 2005-09-19 - NA - 43 - 540
> 2005-09-19 - NCW - 0 - 0
> 2005-09-19 - NE - 10 - 975
> 2005-09-19 - S - 0 - 0
> 2005-09-19 - SE - 0 - 0
> 2005-09-19 - SP - 23 - 321

It looks like you want something like:

for my $date ( keys %hash ) {
for my $num_name ( keys %{ $hash{ $date } } ) {
if ( exists $names{ $num_name } ) {
$hash{ $date }{ $names{ $num_name } }
= delete $hash{ $date }{ $num_name };
}
}
}



John
-- 
use Perl;
program
fulfillment

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




Repetead values

2005-10-14 Thread Rafael Morales
Hi. My trouble is with a value duplicated value on a nested foreach, these are 
my variables:

%names=(
1=>'NA'
2=>'NCW'
3=>'NE'
4=>'S'
5=>'SE'
6=>'SP'
   );

%hash{'2005-09-19'}{'1'}{'56'}=788;
%hash{'2005-09-19'}{'1'}{'43'}=540;
%hash{'2005-09-19'}{'6'}{'23'}=321;
%hash{'2005-09-19'}{'3'}{'10'}=975;

And I want an output like this:
2005-09-19 - NA - 56 - 788
2005-09-19 - NA - 43 - 540
2005-09-19 - NCW - 0 - 0
2005-09-19 - NE - 10 - 975
2005-09-19 - S - 0 - 0
2005-09-19 - SE - 0 - 0
2005-09-19 - SP - 23 - 321

I do it by this way:

my %final;
my $match = 0;
foreach my $date(sort keys %hash) {
  foreach my $num_name(sort {$a <=> $b}(keys %{$hash{$date}}) ) {
foreach my $names(sort {$a <=> $b}(keys %names) ) {
  if ($num_name == $names) {  
$match = 1;
foreach my $values(sort {$a <=> $b}(keys %{$hash{$date}{$num_state}}) ) 
{
   
$final{$date}{$names{$names}}{$values}=$hash{$date}{$num_state}{$values}; 
} #end values
  } #end if
  else {$match = 0;}
}end names
if ($match == 0){
   $final{$date}{$names{$names}}{0}=0;
}#end if
  }end num_name
}end date

However this is what I get:
2005-09-19 - NA - 0 - 0 <- Repeated value :(
2005-09-19 - NA - 56 - 788
2005-09-19 - NA - 43 - 540
2005-09-19 - NCW - 0 - 0
2005-09-19 - NE - 10 - 975
2005-09-19 - S - 0 - 0
2005-09-19 - SE - 0 - 0
2005-09-19 - SP - 23 - 321

I hope someone help me please.
Regards and thanks !!!.




-- 
___
Get your free email from http://mymail.bsdmail.com

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