Re: [SPAM] RE: How to: load array into Hash
Oh so it was working all along. U were just "testing" it wrong. ;) At 09:48 PM 7/16/2006 -0500, Michael D. Smith wrote: >The array was loaded from a file. All the keys (and data) had newlines on >the end. When I asked for a key without a newline -- it wasn't there -- and >I just assumed the statement was a little to cute -- but not for PERL :) -- REMEMBER THE WORLD TRADE CENTER ---=< WTC 911 >=-- "...ne cede malis" 0100 ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: How to: load array into Hash
$Bill wrote: Note the line above with ^^ under it. Isn't that setting %hash to @array ? > my %hash = @array; The code snippet was hardly sufficient if it doesn't compile or produce any output. Show me a complete code snippet that fails. Eric Edwards wrote: $Bill, you are right! I stand corrected. Eric ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: How to: load array into Hash
At 09:45 PM 7/16/2006, you wrote: >Eric Edwards wrote: > > > $Bill wrote: > > When you post code, post a small complete failing snippet with any input > > and output examples: > > use strict; > > use warnings; > > use Data::Dumper; $Data::Dumper::Indent=1; $Data::Dumper::Sortkeys=1; > > my @array = (Key1 => 'Value1', Key2 => 'Value2', Key3 => 'Value3', > > Key4 => 'Value4'); > > my %hash = @array; > > > > print Data::Dumper->Dump([\%hash], [qw(\%hash)]); > > > > __END__ > > > > Result: > > > > $\%hash = { > > 'Key1' => 'Value1', > > 'Key2' => 'Value2', > > 'Key3' => 'Value3', > > 'Key4' => 'Value4' > > }; > > > > Eric replied: > > Thanks for the feed back, but that is not what Michael is trying to do. > > The code snip he supplied was sufficient unto it self. > > He was trying to: > > %hash = @array; > >Note the line above with ^^ under it. >Isn't that setting %hash to @array ? > >The code snippet was hardly sufficient if it doesn't compile or >produce any output. > >Show me a complete code snippet that fails. Bill's right. I assumed that was the failing code snippet. Unfortunately most of my errors are not where I'm looking, so... I should've shown the whole thing. ms ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: [SPAM] RE: How to: load array into Hash
Michael D. Smith wrote: > Thanks again everyone. Data::Dumper was the "key" to the whole thing. > > The array was loaded from a file. All the keys (and data) had newlines on > the end. When I asked for a key without a newline -- it wasn't there -- and > I just assumed the statement was a little to cute -- but not for PERL :) That's what happens when you mis-state the problem (no mention of reading file) and no complete failing snippet. ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: [SPAM] RE: How to: load array into Hash
Thanks again everyone. Data::Dumper was the "key" to the whole thing. The array was loaded from a file. All the keys (and data) had newlines on the end. When I asked for a key without a newline -- it wasn't there -- and I just assumed the statement was a little to cute -- but not for PERL :) ms At 09:12 PM 7/16/2006, Eric Edwards wrote: >$Bill wrote: >When you post code, post a small complete failing snippet with any input >and output examples: >use strict; >use warnings; >use Data::Dumper; $Data::Dumper::Indent=1; $Data::Dumper::Sortkeys=1; >my @array = (Key1 => 'Value1', Key2 => 'Value2', Key3 => 'Value3', > Key4 => 'Value4'); >my %hash = @array; >print Data::Dumper->Dump([\%hash], [qw(\%hash)]); > >__END__ > >Result: > >$\%hash = { > 'Key1' => 'Value1', > 'Key2' => 'Value2', > 'Key3' => 'Value3', > 'Key4' => 'Value4' >}; > >Eric replied: >Thanks for the feed back, but that is not what Michael is trying to do. >The code snip he supplied was sufficient unto it self. >He was trying to: >%hash = @array; >Thanks, >Eric >___ >Perl-Win32-Users mailing list >Perl-Win32-Users@listserv.ActiveState.com >To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs > >___ >Perl-Win32-Users mailing list >Perl-Win32-Users@listserv.ActiveState.com >To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: How to: load array into Hash
Eric Edwards wrote: > $Bill wrote: > When you post code, post a small complete failing snippet with any input > and output examples: > use strict; > use warnings; > use Data::Dumper; $Data::Dumper::Indent=1; $Data::Dumper::Sortkeys=1; > my @array = (Key1 => 'Value1', Key2 => 'Value2', Key3 => 'Value3', > Key4 => 'Value4'); > my %hash = @array; > print Data::Dumper->Dump([\%hash], [qw(\%hash)]); > > __END__ > > Result: > > $\%hash = { > 'Key1' => 'Value1', > 'Key2' => 'Value2', > 'Key3' => 'Value3', > 'Key4' => 'Value4' > }; > > Eric replied: > Thanks for the feed back, but that is not what Michael is trying to do. > The code snip he supplied was sufficient unto it self. > He was trying to: > %hash = @array; Note the line above with ^^ under it. Isn't that setting %hash to @array ? The code snippet was hardly sufficient if it doesn't compile or produce any output. Show me a complete code snippet that fails. ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: [SPAM] RE: How to: load array into Hash
At 08:03 PM 7/16/2006, Charles K. Clarkson wrote: >Michael D. Smith wrote: > >: This is what I want to do: >: >: %hash = @array; >: >: But it don't work :) > >Define "it don't work". There is nothing in the hash after execution. It's defined, but empty. I printed the array, it's there, just as it's supposed to be. Knowing that statement is supposed to work and to look elsewhere is itself a big help. Thanks everyone. ms >#!/usr/bin/perl > >use strict; >use warnings; >use Data::Dumper 'Dumper'; > >my @foo = ( > foo => 1, > bar => 2, > baz => 'three', >); > >my %foo = @foo; > >print Dumper \%foo; > >__END__ > > >HTH, > >Charles K. Clarkson >-- >Mobile Homes Specialist >Free Market Advocate >Web Programmer > >254 968-8328 > >Don't tread on my bandwidth. Trim your posts. > >___ >Perl-Win32-Users mailing list >Perl-Win32-Users@listserv.ActiveState.com >To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: How to: load array into Hash
$Bill wrote: When you post code, post a small complete failing snippet with any input and output examples: use strict; use warnings; use Data::Dumper; $Data::Dumper::Indent=1; $Data::Dumper::Sortkeys=1; my @array = (Key1 => 'Value1', Key2 => 'Value2', Key3 => 'Value3', Key4 => 'Value4'); my %hash = @array; print Data::Dumper->Dump([\%hash], [qw(\%hash)]); __END__ Result: $\%hash = { 'Key1' => 'Value1', 'Key2' => 'Value2', 'Key3' => 'Value3', 'Key4' => 'Value4' }; Eric replied: Thanks for the feed back, but that is not what Michael is trying to do. The code snip he supplied was sufficient unto it self. He was trying to: %hash = @array; Thanks, Eric ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: How to: load array into Hash
At 07:25 PM 7/16/2006 -0500, Michael D. Smith wrote: >This is what I want to do: > > %hash = @array; > >But it don't work :) > > Every other array element is a key and every other one is data. A loop, >could be done, but this every other one thing could get complicated. I think what ur saying is that u want to transform the array into a hash. So e.g. $hash{$array[0]} = $array[1]; etc. Just do this: %hash = (@array); -- REMEMBER THE WORLD TRADE CENTER ---=< WTC 911 >=-- "...ne cede malis" 0100 ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: How to: load array into Hash
Eric Edwards wrote: > Michael, > As far as I know, that is the way to do it. > Have you tried accessing the hash? I didn't get the orig post yet, so I'll answer on yours. > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of > This is what I want to do: > > %hash = @array; > > But it don't work :) > > Every other array element is a key and every other one is data. A loop, > could be done, but this every other one thing could get complicated. > > Must be an easy way. When you post code, post a small complete failing snippet with any input and output examples: use strict; use warnings; use Data::Dumper; $Data::Dumper::Indent=1; $Data::Dumper::Sortkeys=1; my @array = (Key1 => 'Value1', Key2 => 'Value2', Key3 => 'Value3', Key4 => 'Value4'); my %hash = @array; print Data::Dumper->Dump([\%hash], [qw(\%hash)]); __END__ Result: $\%hash = { 'Key1' => 'Value1', 'Key2' => 'Value2', 'Key3' => 'Value3', 'Key4' => 'Value4' }; ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: How to: load array into Hash
Michael D. Smith wrote: : This is what I want to do: : : %hash = @array; : : But it don't work :) Define "it don't work". #!/usr/bin/perl use strict; use warnings; use Data::Dumper 'Dumper'; my @foo = ( foo => 1, bar => 2, baz => 'three', ); my %foo = @foo; print Dumper \%foo; __END__ HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 Don't tread on my bandwidth. Trim your posts. ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: How to: load array into Hash
Michael, As far as I know, that is the way to do it. Have you tried accessing the hash? Eric -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Michael D. Smith Sent: Sunday, July 16, 2006 7:26 PM To: perl-win32-users@listserv.ActiveState.com Subject: RE: How to: load array into Hash This is what I want to do: %hash = @array; But it don't work :) Every other array element is a key and every other one is data. A loop, could be done, but this every other one thing could get complicated. Must be an easy way. ms ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: How to: load array into Hash
This is what I want to do: %hash = @array; But it don't work :) Every other array element is a key and every other one is data. A loop, could be done, but this every other one thing could get complicated. Must be an easy way. ms ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs