Trying to "map" an array into a hash
am 03.01.2008 17:55:11 von Deane.RothenmaierThis is a multipart message in MIME format.
--===============0281807353==
Content-Type: multipart/alternative;
boundary="=_alternative 005CF22E862573C5_="
This is a multipart message in MIME format.
--=_alternative 005CF22E862573C5_=
Content-Type: text/plain; charset="US-ASCII"
Gurus,
I'm trying to use map--instead of a for loop--to split an array into a
hash. As you can see by the output I'm getting, it ain't workin'. Am I
doing something wrong, or am I just trying the impossible? Here's the
code, followed by what I get, followed by what I *want* to get.
TIA!
#####
# program:
#####
use strict;
use warnings;
my @data = (
'########################################',
'# jhsdkjfhh - Copyright 2005, #',
'# #',
'# Name : asdfsdfsdas #',
'# #',
'# Description : This is the Inlue set) #',
'# file used byasder. #',
'# #',
'# Notes : Its somewhat pdded to #',
'# #',
'# Modification Log: #',
'# Rev. Date Init. Ch #',
'# ---- ----------- ----- ---------- #',
'# 1.0 31 Jan 2005 dcr Initial #',
'# 2.0 18 Jan 2006 dcr Windsdf, #',
'# and reo #',
'# 3.0 02 Jan 2008 dcr Add four #',
'########################################',
'',
'000 |Somewhere/something/thisplace/someplace/Things/here//Value' ,
'001 |Somewhere/something/thisplace/someplace/Things/here//Value' ,
'002 |Somewhere/something/thisplace/someplace/Things/here//Value' ,
'003 |Somewhere/something/thisplace/someplace/Things/here//Value' ,
'004 |Somewhere/something/thisplace/someplace/Things/here//Value' ,
'005 |Somewhere/something/thisplace/someplace/Things/here//Value' ,
'006 |Somewhere/something/thisplace/someplace/Things/here//Value' ,
'007 |Somewhere/something/thisplace/someplace/Things/here//Value' ,
'008 |Somewhere/something/thisplace/someplace/Things/here//Value' ,
'009 |Somewhere/something/thisplace/someplace/Things/here//Value' ,
'',
'# This is a COMMENT LINE!',
'010 |Somewhere/something/thisplace/someplace/Things/here//Value' ,
'011 |Somewhere/something/thisplace/someplace/Things/here//Value' ,
'012 |Somewhere/something/thisplace/someplace/Things/here//Value' ,
'013 |Somewhere/something/thisplace/someplace/Things/here//Value' ,
'014 |Somewhere/something/thisplace/someplace/Things/here//Value' ,
'015 |Somewhere/something/thisplace/someplace/Things/here//Value' ,
'016 |Somewhere/something/thisplace/someplace/Things/here//Value' ,
'017 |Somewhere/something/thisplace/someplace/Things/here//Value' ,
'018 |Somewhere/something/thisplace/someplace/Things/here//Value' ,
'019 |Somewhere/something/thisplace/someplace/Things/here//Value' ,
'',
);
my %hash = map { split /\s\|/ } @ary; # line 76
foreach my $key (sort( keys( %hash ))) {
print "$key: $hash{$key}\n"; # line 93
}
#####
# program output:
#####
STDERR:
Odd number of elements in hash assignment at E:\WSUp_Dev\map_test.pl line
76.
Use of uninitialized value in concatenation (.) or string at map_test.pl
line 93.
STDOUT:
------------------------------------------------------------ ---------------
Actual:
# #: # Description : This is the
Inlue set) #
# file used byasder. #: # #
# ---- ----------- ----- ---------- #: # 1.0 31 Jan 2005 dcr
Initial #
# 2.0 18 Jan 2006 dcr Windsdf, #: # and
reo #
# 3.0 02 Jan 2008 dcr Add four #:
########################################
# Modification Log: #: # Rev. Date Init. Ch
#
# Notes : Its somewhat pdded to #: # #
# This is a COMMENT LINE!: 010
########################################: # jhsdkjfhh - Copyright 2005,
#
000: Somewhere/something/thisplace/someplace/Things/here//Value
001: Somewhere/something/thisplace/someplace/Things/here//Value
002: Somewhere/something/thisplace/someplace/Things/here//Value
003: Somewhere/something/thisplace/someplace/Things/here//Value
004: Somewhere/something/thisplace/someplace/Things/here//Value
005: Somewhere/something/thisplace/someplace/Things/here//Value
006: Somewhere/something/thisplace/someplace/Things/here//Value
007: Somewhere/something/thisplace/someplace/Things/here//Value
008: Somewhere/something/thisplace/someplace/Things/here//Value
009: Somewhere/something/thisplace/someplace/Things/here//Value
Somewhere/something/thisplace/someplace/Things/here//Value:
------------------------------------------------------------ ---------------
Desired:
000: Somewhere/something/thisplace/someplace/Things/here//Value
001: Somewhere/something/thisplace/someplace/Things/here//Value
002: Somewhere/something/thisplace/someplace/Things/here//Value
003: Somewhere/something/thisplace/someplace/Things/here//Value
004: Somewhere/something/thisplace/someplace/Things/here//Value
005: Somewhere/something/thisplace/someplace/Things/here//Value
006: Somewhere/something/thisplace/someplace/Things/here//Value
007: Somewhere/something/thisplace/someplace/Things/here//Value
008: Somewhere/something/thisplace/someplace/Things/here//Value
009: Somewhere/something/thisplace/someplace/Things/here//Value
010: Somewhere/something/thisplace/someplace/Things/here//Value
011: Somewhere/something/thisplace/someplace/Things/here//Value
012: Somewhere/something/thisplace/someplace/Things/here//Value
013: Somewhere/something/thisplace/someplace/Things/here//Value
014: Somewhere/something/thisplace/someplace/Things/here//Value
015: Somewhere/something/thisplace/someplace/Things/here//Value
016: Somewhere/something/thisplace/someplace/Things/here//Value
017: Somewhere/something/thisplace/someplace/Things/here//Value
018: Somewhere/something/thisplace/someplace/Things/here//Value
019: Somewhere/something/thisplace/someplace/Things/here//Value
Deane Rothenmaier
Programmer/Analyst
Walgreens Corp.
847-914-5150
Oh, what a tangled web do parents weave, when they think their children
are naive. -- Ogden Nash
--=_alternative 005CF22E862573C5_=
Content-Type: text/html; charset="US-ASCII"
Gurus,
I'm trying to use map--instead of a
for loop--to split an array into a hash. As you can see by the output I'm
getting, it ain't workin'. Am I doing something wrong, or am I just trying
the impossible? Here's the code, followed by what I get, followed
by what I *want* to get.
TIA!
#####
# program:
#####
use strict;
use warnings;
my @data = (
'########################################',
'# jhsdkjfhh - Copyright
2005, #',
'#
#',
'# Name
: asdfsdfsdas #',
'#
#',
'# Description : This
is the Inlue set) #',
'#
file used byasder. #',
'#
#',
'# Notes
: Its somewhat pdded to #',
'#
#',
'# Modification Log:
#',
'# Rev.
Date Init. Ch #',
'# ---- -----------
----- ---------- #',
'# 1.0 31 Jan 2005
dcr Initial #',
'# 2.0 18 Jan 2006
dcr Windsdf, #',
'#
and
reo #',
'# 3.0 02 Jan 2008
dcr Add four #',
'########################################',
'',
'000 |Somewhere/something/thisplace/someplace/Things/here//Value' ,
'001 |Somewhere/something/thisplace/someplace/Things/here//Value' ,
'002 |Somewhere/something/thisplace/someplace/Things/here//Value' ,
'003 |Somewhere/something/thisplace/someplace/Things/here//Value' ,
'004 |Somewhere/something/thisplace/someplace/Things/here//Value' ,
'005 |Somewhere/something/thisplace/someplace/Things/here//Value' ,
'006 |Somewhere/something/thisplace/someplace/Things/here//Value' ,
'007 |Somewhere/something/thisplace/someplace/Things/here//Value' ,
'008 |Somewhere/something/thisplace/someplace/Things/here//Value' ,
'009 |Somewhere/something/thisplace/someplace/Things/here//Value' ,
'',
'# This is a COMMENT LINE!',
'010 |Somewhere/something/thisplace/someplace/Things/here//Value' ,
'011 |Somewhere/something/thisplace/someplace/Things/here//Value' ,
'012 |Somewhere/something/thisplace/someplace/Things/here//Value' ,
'013 |Somewhere/something/thisplace/someplace/Things/here//Value' ,
'014 |Somewhere/something/thisplace/someplace/Things/here//Value' ,
'015 |Somewhere/something/thisplace/someplace/Things/here//Value' ,
'016 |Somewhere/something/thisplace/someplace/Things/here//Value' ,
'017 |Somewhere/something/thisplace/someplace/Things/here//Value' ,
'018 |Somewhere/something/thisplace/someplace/Things/here//Value' ,
'019 |Somewhere/something/thisplace/someplace/Things/here//Value' ,
'',
);
my %hash = map { split /\s\|/ } @ary;
# line 76
foreach my $key (sort( keys( %hash
))) {
print "$key: $hash{$key}\n";
# line 93
}
#####
# program output:
#####
STDERR:
Odd number of elements in hash assignment
at E:\WSUp_Dev\map_test.pl line 76.
Use of uninitialized value in concatenation
(.) or string at map_test.pl line 93.
STDOUT:
------------------------------------------------------------ ---------------
Actual:
#
#: # Description : This is the Inlue set) #
#
file used byasder. #: #
#
# ---- ----------- -----
---------- #: # 1.0 31 Jan 2005 dcr Initial
#
# 2.0 18 Jan 2006 dcr
Windsdf, #: #
and reo #
# 3.0 02 Jan 2008 dcr
Add four #: ########################################
# Modification Log:
#: # Rev.
Date Init. Ch #
# Notes : Its
somewhat pdded to #: #
#
# This is a COMMENT LINE!: 010
########################################:
# jhsdkjfhh - Copyright 2005, #
000: Somewhere/something/thisplace/someplace/Things/here//Value
001: Somewhere/something/thisplace/someplace/Things/here//Value
002: Somewhere/something/thisplace/someplace/Things/here//Value
003: Somewhere/something/thisplace/someplace/Things/here//Value
004: Somewhere/something/thisplace/someplace/Things/here//Value
005: Somewhere/something/thisplace/someplace/Things/here//Value
006: Somewhere/something/thisplace/someplace/Things/here//Value
007: Somewhere/something/thisplace/someplace/Things/here//Value
008: Somewhere/something/thisplace/someplace/Things/here//Value
009: Somewhere/something/thisplace/someplace/Things/here//Value
Somewhere/something/thisplace/someplace/Things/here//Value:
------------------------------------------------------------ ---------------
Desired:
000: Somewhere/something/thisplace/someplace/Things/here//Value
001: Somewhere/something/thisplace/someplace/Things/here//Value
002: Somewhere/something/thisplace/someplace/Things/here//Value
003: Somewhere/something/thisplace/someplace/Things/here//Value
004: Somewhere/something/thisplace/someplace/Things/here//Value
005: Somewhere/something/thisplace/someplace/Things/here//Value
006: Somewhere/something/thisplace/someplace/Things/here//Value
007: Somewhere/something/thisplace/someplace/Things/here//Value
008: Somewhere/something/thisplace/someplace/Things/here//Value
009: Somewhere/something/thisplace/someplace/Things/here//Value
010: Somewhere/something/thisplace/someplace/Things/here//Value
011: Somewhere/something/thisplace/someplace/Things/here//Value
012: Somewhere/something/thisplace/someplace/Things/here//Value
013: Somewhere/something/thisplace/someplace/Things/here//Value
014: Somewhere/something/thisplace/someplace/Things/here//Value
015: Somewhere/something/thisplace/someplace/Things/here//Value
016: Somewhere/something/thisplace/someplace/Things/here//Value
017: Somewhere/something/thisplace/someplace/Things/here//Value
018: Somewhere/something/thisplace/someplace/Things/here//Value
019: Somewhere/something/thisplace/someplace/Things/here//Value
Deane Rothenmaier
Programmer/Analyst
Walgreens Corp.
847-914-5150
Oh, what a tangled web do parents weave, when they think their children
are naive. -- Ogden Nash
--=_alternative 005CF22E862573C5_=--
--===============0281807353==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============0281807353==--