[28543] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 9907 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Oct 30 14:10:14 2006

Date: Mon, 30 Oct 2006 11:10:07 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Mon, 30 Oct 2006     Volume: 10 Number: 9907

Today's topics:
        Printing and Formatting data from hash (or array) <mikedawg@gmail.com>
    Re: Printing and Formatting data from hash (or array) <mikedawg@gmail.com>
    Re: Printing and Formatting data from hash (or array) <jl_post@hotmail.com>
    Re: Printing and Formatting data from hash (or array) <mikedawg@gmail.com>
    Re: Printing and Formatting data from hash (or array) <glex_no-spam@qwest-spam-no.invalid>
    Re: Printing and Formatting data from hash (or array) <jgibson@mail.arc.nasa.gov>
    Re: Printing and Formatting data from hash (or array) <jgibson@mail.arc.nasa.gov>
    Re: queston about appending a variable to a url <glex_no-spam@qwest-spam-no.invalid>
    Re: Sorting array of hash references <kalyanrajsista@gmail.com>
    Re: Windows services in PERL <Reply@NewsGroup.Please>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: 30 Oct 2006 08:31:31 -0800
From: "Mike" <mikedawg@gmail.com>
Subject: Printing and Formatting data from hash (or array)
Message-Id: <1162225891.850942.204730@m7g2000cwm.googlegroups.com>

I'm trying to format the data I have in a hash (or, I could throw it
into an array also) so I can produce a report.

I've attempted to throw that hash data into an array, but I'm not sure
how to arrange the data, because as it appears, the key would be $array
ofhash[0] and the value would be $arrayofhash[1] would be the value.
I'd like to throw a tab in between the matching keys and values.  The
only problem I'm having is figuring out how to throw that into a loop,
so it extracts all the data, for example, lets say there are 150
elements ( $arrayofhash[150] ) in that array.

Or, if you are more skilled than me (most people are), how could I
format that data from the hash?  I've been tinkering with printing the
values from hashes, but it seems like there is a lot of duplicated
data, for instance, I found the example of this to print all the values
I have in a hash, but it seems like it is a single array within the
hash repeating (not printing multiple items in hash):

while ( ($key,$value) = each %hash ) {
    print "$key => $value\n";
}

However, when I copy all the hash data to an array, and print the
array, it doesn't show all the duplicated data.

Thanks for the help

Mike

PS

I've learned how to (and how not to) multi-post and cross-post in
google groups, sorry for previous questions asked the group.



------------------------------

Date: 30 Oct 2006 08:47:22 -0800
From: "Mike" <mikedawg@gmail.com>
Subject: Re: Printing and Formatting data from hash (or array)
Message-Id: <1162226842.201440.263640@m7g2000cwm.googlegroups.com>


Mike wrote:
> I'm trying to format the data I have in a hash (or, I could throw it
> into an array also) so I can produce a report.
>
> I've attempted to throw that hash data into an array, but I'm not sure
> how to arrange the data, because as it appears, the key would be $array
> ofhash[0] and the value would be $arrayofhash[1] would be the value.
> I'd like to throw a tab in between the matching keys and values.  The
> only problem I'm having is figuring out how to throw that into a loop,
> so it extracts all the data, for example, lets say there are 150
> elements ( $arrayofhash[150] ) in that array.
>
> Or, if you are more skilled than me (most people are), how could I
> format that data from the hash?  I've been tinkering with printing the
> values from hashes, but it seems like there is a lot of duplicated
> data, for instance, I found the example of this to print all the values
> I have in a hash, but it seems like it is a single array within the
> hash repeating (not printing multiple items in hash):
>
> while ( ($key,$value) = each %hash ) {
>     print "$key => $value\n";
> }
>
> However, when I copy all the hash data to an array, and print the
> array, it doesn't show all the duplicated data.
>
> Thanks for the help
>
> Mike
>
> PS
>
> I've learned how to (and how not to) multi-post and cross-post in
> google groups, sorry for previous questions asked the group.

Ok, I think I've figured it out, this is what I'm doing (two tabs,
instead of one, yes, I know), is their a cleaner way to do this?:

my $n = 0;
while ($temphash[$n]) {
	print $temphash[$n];
	$n++;
	print "\t\t";
	print $temphash[$n];
	print "\n";
	$n++;
	}

Thanks

Mike



------------------------------

Date: 30 Oct 2006 09:29:13 -0800
From: "jl_post@hotmail.com" <jl_post@hotmail.com>
Subject: Re: Printing and Formatting data from hash (or array)
Message-Id: <1162229352.937555.90710@f16g2000cwb.googlegroups.com>

Mike wrote:
>
> I've attempted to throw that hash data into an array, but I'm not sure
> how to arrange the data, because as it appears, the key would be $array
> ofhash[0] and the value would be $arrayofhash[1] would be the value.
> I'd like to throw a tab in between the matching keys and values.  The
> only problem I'm having is figuring out how to throw that into a loop,
> so it extracts all the data, for example, lets say there are 150
> elements ( $arrayofhash[150] ) in that array.

   You might consider using the Data::Dumper module.  It's a standard
module, so you should already have it installed.

   With the Data::Dumper module, you can write your code like this:

      use Data::Dumper;
      print Dumper \%hash;

and your output will look like:

$VAR1 = {
          'cat' => 1,
          'dog' => 2,
          'bird' => 3
        };

which may or may not be what you want.  You can tweak how the output
appears -- to find out how, read the Data::Dumper's documentation with
"perldoc Data::Dumper".

   I hope this helps, Mike.

   -- Jean-Luc



------------------------------

Date: 30 Oct 2006 09:46:47 -0800
From: "Mike" <mikedawg@gmail.com>
Subject: Re: Printing and Formatting data from hash (or array)
Message-Id: <1162230407.451771.153230@m73g2000cwd.googlegroups.com>


jl_post@hotmail.com wrote:
> Mike wrote:
> >
> > I've attempted to throw that hash data into an array, but I'm not sure
> > how to arrange the data, because as it appears, the key would be $array
> > ofhash[0] and the value would be $arrayofhash[1] would be the value.
> > I'd like to throw a tab in between the matching keys and values.  The
> > only problem I'm having is figuring out how to throw that into a loop,
> > so it extracts all the data, for example, lets say there are 150
> > elements ( $arrayofhash[150] ) in that array.
>
>    You might consider using the Data::Dumper module.  It's a standard
> module, so you should already have it installed.
>
>    With the Data::Dumper module, you can write your code like this:
>
>       use Data::Dumper;
>       print Dumper \%hash;
>
> and your output will look like:
>
> $VAR1 = {
>           'cat' => 1,
>           'dog' => 2,
>           'bird' => 3
>         };
>
> which may or may not be what you want.  You can tweak how the output
> appears -- to find out how, read the Data::Dumper's documentation with
> "perldoc Data::Dumper".
>
>    I hope this helps, Mike.
>
>    -- Jean-Luc

Works perfect, thanks Jean-Luc.  Now on to my next problem ;-)



------------------------------

Date: Mon, 30 Oct 2006 12:02:55 -0600
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: Printing and Formatting data from hash (or array)
Message-Id: <45463e2f$0$503$815e3792@news.qwest.net>

Mike wrote:
> Mike wrote:

[...]
>  I've been tinkering with printing the
>> values from hashes, but it seems like there is a lot of duplicated
>> data, for instance, I found the example of this to print all the values
>> I have in a hash, but it seems like it is a single array within the
>> hash repeating (not printing multiple items in hash):

Correct. A hash has unique keys.

>> However, when I copy all the hash data to an array, and print the
>> array, it doesn't show all the duplicated data.
Post a short example of how you're doing that.

Possibly, you want to have a hash of arrays?

	push( @{ $report{ $key } }, 'some value' );
	push( @{ $report{ $key } }, 'another value' );

For many examples of data structures, see: perldoc perldsc

> Ok, I think I've figured it out, this is what I'm doing (two tabs,
> instead of one, yes, I know), is their a cleaner way to do this?:
> 
> my $n = 0;
> while ($temphash[$n]) {

Is this an array or a hash??  Review the differences and name your 
variables accordingly.

> 	print $temphash[$n];
> 	$n++;
> 	print "\t\t";
> 	print $temphash[$n];
> 	print "\n";
> 	$n++;
> 	}

If that actually prints the values you want. You may put the print on 
one line:

	print "$tmphash[$n++]\t\t$temphash[$n++]\n";


------------------------------

Date: Mon, 30 Oct 2006 10:03:32 -0800
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: Printing and Formatting data from hash (or array)
Message-Id: <301020061003325965%jgibson@mail.arc.nasa.gov>

In article <1162225891.850942.204730@m7g2000cwm.googlegroups.com>, Mike
<mikedawg@gmail.com> wrote:

> I'm trying to format the data I have in a hash (or, I could throw it
> into an array also) so I can produce a report.
> 
> I've attempted to throw that hash data into an array, but I'm not sure
> how to arrange the data, because as it appears, the key would be $array
> ofhash[0] and the value would be $arrayofhash[1] would be the value.
> I'd like to throw a tab in between the matching keys and values.  The
> only problem I'm having is figuring out how to throw that into a loop,
> so it extracts all the data, for example, lets say there are 150
> elements ( $arrayofhash[150] ) in that array.
> 
> Or, if you are more skilled than me (most people are), how could I
> format that data from the hash?  I've been tinkering with printing the
> values from hashes, but it seems like there is a lot of duplicated
> data, for instance, I found the example of this to print all the values
> I have in a hash, but it seems like it is a single array within the
> hash repeating (not printing multiple items in hash):
> 
> while ( ($key,$value) = each %hash ) {
>     print "$key => $value\n";
> }
> 
> However, when I copy all the hash data to an array, and print the
> array, it doesn't show all the duplicated data.

Please post a complete, working program that illustrates this. The
above loop should definitely print all of the keys and values in %hash.

> 
> Thanks for the help
> 
> Mike
> 
> PS
> 
> I've learned how to (and how not to) multi-post and cross-post in
> google groups, sorry for previous questions asked the group.
> 

Great! Thanks for paying attention. Next thing to learn: post complete,
working, short programs that demonstrate the problem you are having,
including data if required, and a description of what the program is
doing or not doing that you expect it should.


------------------------------

Date: Mon, 30 Oct 2006 10:06:14 -0800
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: Printing and Formatting data from hash (or array)
Message-Id: <301020061006145691%jgibson@mail.arc.nasa.gov>

In article <1162226842.201440.263640@m7g2000cwm.googlegroups.com>, Mike
<mikedawg@gmail.com> wrote:

> Mike wrote:
> > I'm trying to format the data I have in a hash (or, I could throw it
> > into an array also) so I can produce a report.

[...]

> 
> Ok, I think I've figured it out, this is what I'm doing (two tabs,
> instead of one, yes, I know), is their a cleaner way to do this?:
> 
> my $n = 0;
> while ($temphash[$n]) {
>  print $temphash[$n];
>  $n++;
>  print "\t\t";
>  print $temphash[$n];
>  print "\n";
>  $n++;
>  }

There is definitely a cleaner way to do what you are doing, but it is
not clear exactly what you are attempting to do, or what values are in
@temphash. Please post a complete, working, short program.

Thanks.


------------------------------

Date: Mon, 30 Oct 2006 10:28:16 -0600
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: queston about appending a variable to a url
Message-Id: <454627ff$0$496$815e3792@news.qwest.net>

Nospam wrote:

> #usr/bin/perl

Also, the shebang line should be more like:

   #!/usr/bin/perl


------------------------------

Date: 30 Oct 2006 06:06:32 -0800
From: "alwaysonnet" <kalyanrajsista@gmail.com>
Subject: Re: Sorting array of hash references
Message-Id: <1162217192.221319.221370@m73g2000cwd.googlegroups.com>

Sorry if I'm putting more no of keys. This is my final requirement.

For a particular "Type", if two or more records are having the same
status and same currency then sort them according to their a/c no's
where a/c no is a unique.

Here , Data is displayed for every "Type"  in sorted order of their
"ZCurrency" based on their "Status".

for ex : For "Type", Payment where A/C Status are "Y" , with a/c no's
2247,2244 ,records are displayed based on Currencies "AUS","BEL".

Similarly, for the "Type", Payment where A/C Status are "N" , with a/c
no's 56546,44444 are having the same currency "EUR".

So my requirement is that I want these two records with a/c no's
56546,44444 in sorted order.

#!/usr/bin/perl
use Data::Dumper;

my %type_order = qw/Prefund 1 Receipt 2 Payment 3/;

my @records = (
        {'Type'=>'Prefund' , 'A/C No'=>12345 , 'Status active'=>'Y',
'ZCurrency' =>'GBP'},
        {'Type'=>'Prefund' , 'A/C No'=>45678 , 'Status active'=>'N',
'ZCurrency' =>'SEK'},
        {'Type'=>'Prefund' , 'A/C No'=>33333 , 'Status active'=>'N',
'ZCurrency' =>'ZAR'},
        {'Type'=>'Receipt' , 'A/C No'=>32365 , 'Status active'=>'Y',
'ZCurrency' =>'EUR'},
        {'Type'=>'Receipt' , 'A/C No'=>78878 , 'Status active'=>'N',
'ZCurrency' =>'AIR'},
        {'Type'=>'Receipt' , 'A/C No'=>64237 , 'Status active'=>'N',
'ZCurrency' =>'GBP'},
        {'Type'=>'Payment' , 'A/C No'=>2247 , 'Status active'=>'Y',
'ZCurrency' =>'AUS'},
        {'Type'=>'Payment' , 'A/C No'=>2244 , 'Status active'=>'Y',
'ZCurrency' =>'BEL'},
        {'Type'=>'Payment' , 'A/C No'=>56546 , 'Status active'=>'N',
'ZCurrency' =>'EUR'},
        {'Type'=>'Payment' , 'A/C No'=>44444 , 'Status active'=>'N',
'ZCurrency' =>'EUR'},
);

my @sorted = sort { $type_order{$a->{'batype'}} <=>
$type_order{$b->{'batype'}}
                                           ||
                                   $b->{'baactive'} cmp
$a->{'baactive'}
                                           ||
                                   $a->{'banum'} <=> $b->{'banum'}
                                           ||
                                   $a->{'bacur'} eq $b->{'bacur'}
                } @records;

print Dumper \@sorted;

Thanks a ton.
Raj



------------------------------

Date: Mon, 30 Oct 2006 10:37:23 -0600
From: "William" <Reply@NewsGroup.Please>
Subject: Re: Windows services in PERL
Message-Id: <P6-dnQ-faqrZt9vYnZ2dnUVZ_tSdnZ2d@giganews.com>

<harvar007@yahoo.com> wrote in message
news:1152813368.512910.284680@p79g2000cwp.googlegroups.com...
> Hi
>
> I am trying to create a win32 service using the module win32:deamon. I
> wrote a simple code and tried to get that running before I went to the
> actual one. I am actually able to successfully create the service and
> see the same in the Management Console, but when I try to right click
> and say Start  I get "error :1053 the service did not respond or start
> to the control request in a timely fashion"

Have you googled the error? If you do, you'll find that there are a
couple of possible ways to generate that error. Some under the
control of your code (like not responding to the start before the
SCM timeout) or caused by OS issues such as the wrong account or
rights. Some of these depend on which version of Windows you are
using.

At a guess, if the error appears in a few seconds it's probably a
user account issue on the machine. If it takes 30 seconds or more,
then it's probably the SCM timeout.

-Wm






------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 9907
***************************************


home help back first fref pref prev next nref lref last post