
problems hashing
--_000_D225040F2D0F75448937B83D9527991A01230E5342denex1crick et_
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
Hello all,
I am having problems using hash function. I would like to only extract 4 co=
lumns of data from a text file that is ; delimited.
Below is my code along with the errors I am receiving. Any help is apprecia=
ted.
-Chris
1. #!/usr/bin/perl
2. use warnings;
3. use strict;
4. my $data =3D (<>);
5. my %fieldMap =3D (
6. "Mtype" =3D> 5,
7. "Cell" =3D> 31,
8. "Sector" =3D> 32,
9. "RLPtxAT" =3D> 44,
10. );
11. %fieldMap =3D split(/;/, $data);
12. foreach my $data (keys %fieldMap) {
13. print "$fieldMap{$data}\t";
14. }
Odd number of elements in hash assignment at./beta2.pl line 15, <> line 1.
Use of uninitialized value within %fieldMap in concatenation (.) or string =
at ./beta2.pl line 18, <> line 1.
First 3 lines of data looks like:
PACE | EVDOPCMD | 33.0 | 101218 | 07 |
8;1023240136;1218;0;1;00a000001a2bcdc7;0310003147702376;ac01 6d4a;;;5.6.128.=
8;0;;;;;43234169;43234349;;;10000;1;1;;0;;19;5.6.128.22;172. 30.151.5;304;3;=
304;3;;;;;15;175;15;175;15;175;1;1798;1251;0;0;2;19;20;;;;;1 ;1;1;0;128;5.6.=
128.8;;;;;;;301;5.6.128.8;;;8;304;3;;;;1;43244037;;;1;18;432 34169;0;;;;;;;;=
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;1;;;;;;43234416; 0;0;304;3;21;19=
;175;15;405;1;1;1;1;0;125;1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;=
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;|;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;=
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;|
8;1023240137;1218;0;1;00a000001db74ace;;ac0174ca;43243423;16 78442111;5.6.12=
8.8;1;0;;43242544;43244207;43243423;43243647;;;1000;1;1;;0;; 19;5.6.128.26;;=
372;2;372;2;;43243012;0;43243562;15;175;15;175;15;175;1;;;;; 5;48;19;20;49;5=
0;;0;1;2;0;68;5.6.128.8;;;;;;;301;5.6.128.8;;;8;372;2;;;;1;4 3244207;;;1;18;=
43243423;0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;1;;;
--_000_D225040F2D0F75448937B83D9527991A01230E5342denex1crick et_--
Re: problems hashing
--0016e65c86dcfb274b049931f506
Content-Type: text/plain; charset=ISO-8859-1
On Thu, Jan 6, 2011 at 12:25 PM, Chris Stinemetz <
cstinemetz [at] cricketcommunications.com> wrote:
> 11. %fieldMap = split(/;/, $data);
>
>
> 12. foreach my $data (keys %fieldMap) {
>
> 13. print "$fieldMap{$data}\t";
>
> 14. }
>
> Odd number of elements in hash assignment at./beta2.pl line 15, <> line 1.
> Use of uninitialized value within %fieldMap in concatenation (.) or string
> at ./beta2.pl line 18, <> line 1.
>
Line 11 treats the result of "split" as a list of "key => value" pairs. You
end up with something like this...
$fieldMap{8} = 1023240136
$fieldMap{1218} = 0
$fieldMap{1} ="00a000001a2bcdc7"
Perl expects the data to have a value for every key. The first error - odd
number of elements - means that Perl saw a key without a corresponding
value. The data has an odd number of elements. To save into a hash, it
should have an even number of elements.
--
Robert Wohlfarth
--0016e65c86dcfb274b049931f506--
Re: problems hashing
#!/usr/local/bin/perl
use strict;
while (<>) {
chomp;
my [at] values =3D split(/;/);
my ($mtype,$cell,$sector,$rlptxat) =3D
($values[5],$values[31],$values[32],$values[44]);
print "$mtype - $cell - $sector - $rlptxat\n";
}
i dont know if that is over simplified, you may have to add or
subtract from the array indexes i provided.
-jose
On Thu, Jan 6, 2011 at 12:49 PM, Robert Wohlfarth <rbwohlfarth [at] gmail.com> w=
rote:
> On Thu, Jan 6, 2011 at 12:25 PM, Chris Stinemetz <
> cstinemetz [at] cricketcommunications.com> wrote:
>
>> 11. =A0 %fieldMap =3D split(/;/, $data);
>>
>>
>> 12. =A0 foreach my $data (keys %fieldMap) {
>>
>> 13. =A0 print "$fieldMap{$data}\t";
>>
>> 14. =A0 }
>>
>> Odd number of elements in hash assignment at./beta2.pl line 15, <> line =
1.
>> Use of uninitialized value within %fieldMap in concatenation (.) or stri=
ng
>> at ./beta2.pl line 18, <> line 1.
>>
>
> Line 11 treats the result of "split" as a list of "key =3D> value" pairs.=
You
> end up with something like this...
> $fieldMap{8} =3D 1023240136
> $fieldMap{1218} =3D 0
> $fieldMap{1} =3D"00a000001a2bcdc7"
>
> Perl expects the data to have a value for every key. The first error - od=
d
> number of elements - means that Perl saw a key without a corresponding
> value. The data has an odd number of elements. To save into a hash, it
> should have an even number of elements.
>
> --
> Robert Wohlfarth
>
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Re: problems hashing
Chris Stinemetz wrote:
> Hello all,
Hello,
> I am having problems using hash function. I would like to only extract
> 4 columns of data from a text file that is ; delimited.
>
> Below is my code along with the errors I am receiving. Any help is
> appreciated.
>
> -Chris
>
>
> 1. #!/usr/bin/perl
> 2. use warnings;
> 3. use strict;
>
> 4. my $data = (<>);
You read the first line only and assign it to $data. So $data now
contains "PACE | EVDOPCMD | 33.0 | 101218 | 07 |".
> 5. my %fieldMap = (
> 6. "Mtype" => 5,
> 7. "Cell" => 31,
> 8. "Sector" => 32,
> 9. "RLPtxAT" => 44,
> 10. );
You create a hash %fieldMap and assign some values to it.
> 11. %fieldMap = split(/;/, $data);
You now overwrite any previous data by assigning to the hash again. The
data "PACE | EVDOPCMD | 33.0 | 101218 | 07 |" in $data appears to
contain no ';' characters so that is the same as:
%fieldMap = $data;
And that is why you get "Odd number of elements in hash assignment"
because you are assigning a key with no value (a list of one element.)
> 12. foreach my $data (keys %fieldMap) {
>
> 13. print "$fieldMap{$data}\t";
And when you try to interpolate that non-existent value you get "Use of
uninitialized value within %fieldMap in concatenation (.) or string".
> 14. }
>
> Odd number of elements in hash assignment at./beta2.pl line 15,<>
> line 1.
> Use of uninitialized value within %fieldMap in concatenation (.) or
> string at ./beta2.pl line 18,<> line 1.
>
> First 3 lines of data looks like:
>
> PACE | EVDOPCMD | 33.0 | 101218 | 07 |
> 8;1023240136;1218;0;1;00a000001a2bcdc7;0310003147702376;ac01 6d4a;;;5.6.128.8;0;;;;;43234169;43234349;;;10000;1;1;;0;;19; 5.6.128.22;172.30.151.5;304;3;304;3;;;;;15;175;15;175;15;175 ;1;1798;1251;0;0;2;19;20;;;;;1;1;1;0;128;5.6.128.8;;;;;;;301 ;5.6.128.8;;;8;304;3;;;;1;43244037;;;1;18;43234169;0;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;1;;;;;;43234416; 0;0;304;3;21;19;175;15;405;1;1;1;1;0;125;1;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;|;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;|
> 8;1023240137;1218;0;1;00a000001db74ace;;ac0174ca;43243423;16 78442111;5.6.128.8;1;0;;43242544;43244207;43243423;43243647; ;;1000;1;1;;0;;19;5.6.128.26;;372;2;372;2;;43243012;0;432435 62;15;175;15;175;15;175;1;;;;;5;48;19;20;49;50;;0;1;2;0;68;5 .6.128.8;;;;;;;301;5.6.128.8;;;8;372;2;;;;1;43244207;;;1;18; 43243423;0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;1;;;
John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction. -- Albert Einstein
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Re: problems hashing
Hi Chris,
On Thu, Jan 6, 2011 at 7:25 PM, Chris Stinemetz
<cstinemetz [at] cricketcommunications.com> wrote:
> I am having problems using hash function. I would like to only extract 4 columns of data from a text file that is ; delimited.
>
> Below is my code along with the errors I am receiving. Any help is appreciated.
Actually I would always recommend to use a CSV parser like Text::CSV -
there are many ways in which CSV files can be tricky (line feeds in
fields, quotes around text containing semicolons or commas, etc).
Text::CSV takes care of all this nastiness for you and you can
leverage it's clean interface and only have to worry about your own
code.
--
Mike
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Re: problems hashing
At 11:25 -0700 06/01/2011, Chris Stinemetz wrote:
>I am having problems using hash function. I would like to only
>extract 4 columns of data from a text file that is ; delimited.
>
>Below is my code along with the errors I am receiving. Any help is
>appreciated.
>
>
>1. #!/usr/bin/perl
>2. use warnings;...
Well, let's you suppose you really wrote this and didn't write the
unnecessary brackets etc. and require people to remove line numbers:
#!/usr/bin/perl
use warnings;
use strict;
my $data = <DATA>;
my %fieldMap = (
"Mtype" => 5,
"Cell" => 31,
"Sector" => 32,
"RLPtxAT" => 44,
);
%fieldMap = split /;/, $data;
for (keys %fieldMap) {
print "$fieldMap{$_}\t";
}
__DATA__
PACE | EVDOPCMD | 33.0 | 101218 | 07 |
8;1023240136;1218;0;1;00a000001a2bcdc7;;;|
8;1023240137;1218;0;1;00a000001db74ace;;;
Your $data ends up as the first line of your three lines of _DATA_,
which contains none of the semicolons you hope later to break it up
with into an array containing an unknown number of elements with a
50/50 chance of not qualifying for conversion to the hash that you
seem to intend but which would be useless even if you succeeded.
In the process of creating this useless hash you destroy the valid
hash you have already painstakingly created at the beginning of the
script. I think you need to make it clear just what you are
intending to do, but to deal simply with the data issue, my $data =
<DATA> means $data is the contents of __DATA__ up to the first $/ and
you can see what I mean if you run this script:
#!/usr/local/bin/perl
use strict;
my $data = (<DATA>);
print "\$data: $data\________\n\n";
$data = (<DATA>);
print "\$data: $data\________\n\n";
my $delimiter = $/;
undef $/;
$data = <DATA>;
$/ = $delimiter;
print "\$data: $data\________\n\n";
__DATA__
a
b
c
d
e
f
END
JD
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
RE: problems hashing
Thank you all for you help. I am still having issues getting hash to work. =
I have taken a different approach in extracting the data e.g different hash=
..
What I would like to accomplish is for each 31st index (Ignoring the first =
line " PACE | EVDOPCMD | 33.0 | 101218 | 07 |" I would like to assign the c=
orresponding key indicated in my hash in the below program. Any help is app=
reciated.
I just finished the Llama book and am getting a better idea on how to progr=
am perl, but I have quite a ways to go to feel comfortable.
Thank you,
#!/usr/bin/perl
use warnings;
use strict;
my $data =3D (<>);
#Market configurations has for cells
my %marketInfo =3D (
"STL" =3D> { "start" =3D> 300,
"end" =3D> 599, },
"MCI" =3D> { "start" =3D> 1,
"end" =3D> 299, },
"ICT" =3D> { "start" =3D> 800,
"end" =3D> 850, },
);
%marketInfo =3D split /;/, $data;
for (keys %marketInfo) {
print "$marketInfo{$_}\n";
}
Below is a few lines of the data I am working with from text file:
PACE | EVDOPCMD | 33.0 | 101218 | 07 |
8;1023240136;1218;0;1;00a000001a2bcdc7;0310003147702376;ac01 6d4a;;;5.6.128.=
8;0;;;;;43234169;43234349;;;10000;1;1;;0;;19;5.6.128.22;172. 30.151.5;304;3;=
304;3;;;;;15;175;15;175;15;175;1;1798;1251;0;0;2;19;20;;;;;1 ;1;1;0;128;5.6.=
128.8;;;;;;;301;5.6.128.8;;;8;304;3;;;;1;43244037;;;1;18;432 34169;0;;;;;;;;=
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;1;;;;;;43234416; 0;0;304;3;21;19=
;175;15;405;1;1;1;1;0;125;1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;=
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;|;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;=
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;|
8;1023240137;1218;0;1;00a000001db74ace;;ac0174ca;43243423;16 78442111;5.6.12=
8.8;1;0;;43242544;43244207;43243423;43243647;;;1000;1;1;;0;; 19;5.6.128.26;;=
372;2;372;2;;43243012;0;43243562;15;175;15;175;15;175;1;;;;; 5;48;19;20;49;5=
0;;0;1;2;0;68;5.6.128.8;;;;;;;301;5.6.128.8;;;8;372;2;;;;1;4 3244207;;;1;18;=
43243423;0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;1;;;
Chris
-----Original Message-----
From: John Delacour [mailto:johndelacour [at] gmail.com]
Sent: Thursday, January 06, 2011 2:16 PM
To: beginners [at] perl.org
Subject: Re: problems hashing
At 11:25 -0700 06/01/2011, Chris Stinemetz wrote:
>I am having problems using hash function. I would like to only
>extract 4 columns of data from a text file that is ; delimited.
>
>Below is my code along with the errors I am receiving. Any help is
>appreciated.
>
>
>1. #!/usr/bin/perl
>2. use warnings;...
Well, let's you suppose you really wrote this and didn't write the
unnecessary brackets etc. and require people to remove line numbers:
#!/usr/bin/perl
use warnings;
use strict;
my $data =3D <DATA>;
my %fieldMap =3D (
"Mtype" =3D> 5,
"Cell" =3D> 31,
"Sector" =3D> 32,
"RLPtxAT" =3D> 44,
);
%fieldMap =3D split /;/, $data;
for (keys %fieldMap) {
print "$fieldMap{$_}\t";
}
__DATA__
PACE | EVDOPCMD | 33.0 | 101218 | 07 |
8;1023240136;1218;0;1;00a000001a2bcdc7;;;|
8;1023240137;1218;0;1;00a000001db74ace;;;
Your $data ends up as the first line of your three lines of _DATA_,
which contains none of the semicolons you hope later to break it up
with into an array containing an unknown number of elements with a
50/50 chance of not qualifying for conversion to the hash that you
seem to intend but which would be useless even if you succeeded.
In the process of creating this useless hash you destroy the valid
hash you have already painstakingly created at the beginning of the
script. I think you need to make it clear just what you are
intending to do, but to deal simply with the data issue, my $data =3D
<DATA> means $data is the contents of __DATA__ up to the first $/ and
you can see what I mean if you run this script:
#!/usr/local/bin/perl
use strict;
my $data =3D (<DATA>);
print "\$data: $data\________\n\n";
$data =3D (<DATA>);
print "\$data: $data\________\n\n";
my $delimiter =3D $/;
undef $/;
$data =3D <DATA>;
$/ =3D $delimiter;
print "\$data: $data\________\n\n";
__DATA__
a
b
c
d
e
f
END
JD
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Re: problems hashing
On Fri, Jan 7, 2011 at 10:51 PM, Chris Stinemetz
<cstinemetz [at] cricketcommunications.com> wrote:
> #!/usr/bin/perl
>
> use warnings;
> use strict;
>
> my $data =3D (<>);
>
> #Market configurations has for cells
> my %marketInfo =3D (
> =C2=A0 "STL" =3D> { "start" =3D> 300,
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0"end" =C2=A0 =3D> 599, },
> =C2=A0 "MCI" =3D> { =C2=A0"start" =3D> 1,
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0"end" =C2=A0 =3D> 299, },
> =C2=A0 "ICT" =3D> { "start" =3D> 800,
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0"end" =C2=A0 =3D> 850, },
> );
>
> %marketInfo =3D split /;/, $data;
>
> for (keys %marketInfo) {
> =C2=A0 print "$marketInfo{$_}\n";
> }
>
> Below is a few lines of the data I am working with from text file:
>
> PACE | EVDOPCMD | 33.0 | 101218 | 07 |
> 8;1023240136;1218;0;1;00a000001a2bcdc7;0310003147702376;ac01 6d4a;;;5.6.12=
8.8;0;;;;;43234169;43234349;;;10000;1;1;;0;;19;5.6.128.22;17 2.30.151.5;304;=
3;304;3;;;;;15;175;15;175;15;175;1;1798;1251;0;0;2;19;20;;;; ;1;1;1;0;128;5.=
6.128.8;;;;;;;301;5.6.128.8;;;8;304;3;;;;1;43244037;;;1;18;4 3234169;0;;;;;;=
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;1;;;;;;4323441 6;0;0;304;3;21;=
19;175;15;405;1;1;1;1;0;125;1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;=
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;|;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;=
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;|
> 8;1023240137;1218;0;1;00a000001db74ace;;ac0174ca;43243423;16 78442111;5.6.=
128.8;1;0;;43242544;43244207;43243423;43243647;;;1000;1;1;;0 ;;19;5.6.128.26=
;;372;2;372;2;;43243012;0;43243562;15;175;15;175;15;175;1;;; ;;5;48;19;20;49=
;50;;0;1;2;0;68;5.6.128.8;;;;;;;301;5.6.128.8;;;8;372;2;;;;1 ;43244207;;;1;1=
8;43243423;0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;1;;;
I don't think you've explicitly told us what you intend for your code
to do yet. Start there. Assuming you had a working program, and the
data sample that I'm quoting above, what would you expect to be in
%marketinfo?
--
Brandon McCaig <http://www.bamccaig.com> <bamccaig [at] gmail.com>
V zrna gur orfg jvgu jung V fnl. Vg qbrfa'g nyjnlf fbhaq gung jnl.
Castopulence Software <http://www.castopulence.org/> <bamccaig [at] castopulence=
..org>
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-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IHRoaW5r IHlvdSd2ZSBleHBs
aWNpdGx5IHRvbGQgdXMgd2hhdCB5b3UgaW50ZW5kIGZvciB5b3VyIGNvZGUN CnRvIGRvIHlldC4g
U3RhcnQgdGhlcmUuIEFzc3VtaW5nIHlvdSBoYWQgYSB3b3JraW5nIHByb2dy YW0sIGFuZCB0aGUN
CmRhdGEgc2FtcGxlIHRoYXQgSSdtIHF1b3RpbmcgYWJvdmUsIHdoYXQgd291 bGQgeW91IGV4cGVj
dCB0byBiZSBpbg0KJW1hcmtldGluZm8/DQoNCg0KLS0gDQpCcmFuZG9uIE1j Q2FpZyA8aHR0cDov
L3d3dy5iYW1jY2FpZy5jb20+IDxiYW1jY2FpZ0BnbWFpbC5jb20+DQpWIHpy bmEgZ3VyIG9yZmcg
anZndSBqdW5nIFYgZm5sLiBWZyBxYnJmYSdnIG55am5sZiBmYmhhcSBndW5n IGpubC4NCkNhc3Rv
cHVsZW5jZSBTb2Z0d2FyZSA8aHR0cDovL3d3dy5jYXN0b3B1bGVuY2Uub3Jn Lz4gPGJhbWNjYWln
QGNhc3RvcHVsZW5jZS5vcmc+DQo=
RE: problems hashing
At 9:26 PM -0700 1/7/11, Chris Stinemetz wrote:
>Thanks Brandon,
>
>Ultimately I am trying to take the value from the input data in
>index position "31" and assign one of the three keys to it. For
>example if index 31 has the value 801 it should be assigned "ICT"
>when I run the program. I hope I explained it better. Thank you for
>your help!
What should be done with the value "ICT"? Do you want to write a new
version of the file?
>
>On Fri, Jan 7, 2011 at 10:51 PM, Chris Stinemetz
><cstinemetz [at] cricketcommunications.com> wrote:
>> #!/usr/bin/perl
>>
>> use warnings;
>> use strict;
>>
>> my $data = (<>);
>>
>> #Market configurations has for cells
>> my %marketInfo = (
>> "STL" => { "start" => 300,
>> "end" => 599, },
>> "MCI" => { "start" => 1,
>> "end" => 299, },
>> "ICT" => { "start" => 800,
>> "end" => 850, },
>> );
>>
>> %marketInfo = split /;/, $data;
Do not do this! You have just overwritten and destroyed your market
information.
> >
>> for (keys %marketInfo) {
>> print "$marketInfo{$_}\n";
>> }
Presuming that you do not destroy the information in %marketinfo, why
do you want to print it? Are you trying to replace part of the
%marketinfo hash with data from the file? Are you trying to replace
data in the file with data from the %marketinfo hash?
> >
>> Below is a few lines of the data I am working with from text file:
>>
>> PACE | EVDOPCMD | 33.0 | 101218 | 07 |
>>
>>8;1023240136;1218;0;1;00a000001a2bcdc7;0310003147702376;ac 016d4a;;;5.6.128.8;0;;;;;43234169;43234349;;;10000;1;1;;0;;1 9;5.6.128.22;172.30.151.5;304;3;304;3;;;;;15;175;15;175;15;1 75;1;1798;1251;0;0;2;19;20;;;;;1;1;1;0;128;5.6.128.8;;;;;;;3 01;5.6.128.8;;;8;304;3;;;;1;43244037;;;1;18;43234169;0;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;1;;;;;;4323441 6;0;0;304;3;21;19;175;15;405;1;1;1;1;0;125;1;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;|;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;|
> >
>8;1023240137;1218;0;1;00a000001db74ace;;ac0174ca;43243423;1 678442111;5.6.128.8;1;0;;43242544;43244207;43243423;43243647 ;;;1000;1;1;;0;;19;5.6.128.26;;372;2;372;2;;43243012;0;43243 562;15;175;15;175;15;175;1;;;;;5;48;19;20;49;50;;0;1;2;0;68; 5.6.128.8;;;;;;;301;5.6.128.8;;;8;372;2;;;;1;43244207;;;1;18 ;43243423;0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;1;;;
You might use a loop something like this (untested):
while( my $line = <> ) {
next if $line =~ /^PACE/;
chomp($line);
my [at] data = split(';',$line);
my $entry = $data[30]; # or 31 if you are using zero-based indexing
for my $key ( keys %marketinfo ) {
if( $entry >= $marketinfo{$key}->{start} &&
$entry <= $marketinfo{$key}->{end}
) {
$entry = $key;
last;
}
}
# do something with $entry
}
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
RE: problems hashing
Thanks Jim,
I would like to create a new file with new column name "Market" with the va=
lue "ICT, "MCI", "STL" from the hash where index "32" meets the condition. =
Leaving the original file unaltered.
Thank you,
________________________________________
From: Jim Gibson [jimsgibson [at] gmail.com]
Sent: Saturday, January 08, 2011 1:32 AM
To: Chris Stinemetz; Brandon McCaig
Cc: John Delacour; beginners [at] perl.org
Subject: RE: problems hashing
At 9:26 PM -0700 1/7/11, Chris Stinemetz wrote:
>Thanks Brandon,
>
>Ultimately I am trying to take the value from the input data in
>index position "31" and assign one of the three keys to it. For
>example if index 31 has the value 801 it should be assigned "ICT"
>when I run the program. I hope I explained it better. Thank you for
>your help!
What should be done with the value "ICT"? Do you want to write a new
version of the file?
>
>On Fri, Jan 7, 2011 at 10:51 PM, Chris Stinemetz
><cstinemetz [at] cricketcommunications.com> wrote:
>> #!/usr/bin/perl
>>
>> use warnings;
>> use strict;
>>
>> my $data =3D (<>);
>>
>> #Market configurations has for cells
>> my %marketInfo =3D (
>> "STL" =3D> { "start" =3D> 300,
>> "end" =3D> 599, },
>> "MCI" =3D> { "start" =3D> 1,
>> "end" =3D> 299, },
>> "ICT" =3D> { "start" =3D> 800,
>> "end" =3D> 850, },
>> );
>>
>> %marketInfo =3D split /;/, $data;
Do not do this! You have just overwritten and destroyed your market
information.
> >
>> for (keys %marketInfo) {
>> print "$marketInfo{$_}\n";
>> }
Presuming that you do not destroy the information in %marketinfo, why
do you want to print it? Are you trying to replace part of the
%marketinfo hash with data from the file? Are you trying to replace
data in the file with data from the %marketinfo hash?
> >
>> Below is a few lines of the data I am working with from text file:
>>
>> PACE | EVDOPCMD | 33.0 | 101218 | 07 |
>>
>>8;1023240136;1218;0;1;00a000001a2bcdc7;0310003147702376;ac 016d4a;;;5.6.12=
8.8;0;;;;;43234169;43234349;;;10000;1;1;;0;;19;5.6.128.22;17 2.30.151.5;304;=
3;304;3;;;;;15;175;15;175;15;175;1;1798;1251;0;0;2;19;20;;;; ;1;1;1;0;128;5.=
6.128.8;;;;;;;301;5.6.128.8;;;8;304;3;;;;1;43244037;;;1;18;4 3234169;0;;;;;;=
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;1;;;;;;4323441 6;0;0;304;3;21;=
19;175;15;405;1;1;1;1;0;125;1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;=
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;|;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;=
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;|
> >
>8;1023240137;1218;0;1;00a000001db74ace;;ac0174ca;43243423;1 678442111;5.6.1=
28.8;1;0;;43242544;43244207;43243423;43243647;;;1000;1;1;;0; ;19;5.6.128.26;=
;372;2;372;2;;43243012;0;43243562;15;175;15;175;15;175;1;;;; ;5;48;19;20;49;=
50;;0;1;2;0;68;5.6.128.8;;;;;;;301;5.6.128.8;;;8;372;2;;;;1; 43244207;;;1;18=
;43243423;0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;1;;;
You might use a loop something like this (untested):
while( my $line =3D <> ) {
next if $line =3D~ /^PACE/;
chomp($line);
my [at] data =3D split(';',$line);
my $entry =3D $data[30]; # or 31 if you are using zero-based indexing
for my $key ( keys %marketinfo ) {
if( $entry >=3D $marketinfo{$key}->{start} &&
$entry <=3D $marketinfo{$key}->{end}
) {
$entry =3D $key;
last;
}
}
# do something with $entry
}
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Re: problems hashing
On 08/01/2011 04:26, Chris Stinemetz wrote:
> From: Brandon McCaig [mailto:bamccaig [at] gmail.com]
>> On Fri, Jan 7, 2011 at 10:51 PM, Chris Stinemetz wrote:
>>>
>>> #!/usr/bin/perl
>>>
>>> use warnings;
>>> use strict;
>>>
>>> my $data = (<>);
>>>
>>> #Market configurations has for cells
>>> my %marketInfo = (
>>> "STL" => { "start" => 300,
>>> "end" => 599, },
>>> "MCI" => { "start" => 1,
>>> "end" => 299, },
>>> "ICT" => { "start" => 800,
>>> "end" => 850, },
>>> );
>>>
>>> %marketInfo = split /;/, $data;
>>>
>>> for (keys %marketInfo) {
>>> print "$marketInfo{$_}\n";
>>> }
>>>
>>> Below is a few lines of the data I am working with from text file:
>>>
>>> PACE | EVDOPCMD | 33.0 | 101218 | 07 |
>>> 8;1023240136;1218;0;1;00a000001a2bcdc7;0310003147702376;ac01 6d4a;;;5.6.128.8;0;;;;;43234169;43234349;;;10000;1;1;;0;;19; 5.6.128.22;172.30.151.5;304;3;304;3;;;;;15;175;15;175;15;175 ;1;1798;1251;0;0;2;19;20;;;;;1;1;1;0;128;5.6.128.8;;;;;;;301 ;5.6.128.8;;;8;304;3;;;;1;43244037;;;1;18;43234169;0;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;1;;;;;;43234416; 0;0;304;3;21;19;175;15;405;1;1;1;1;0;125;1;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;|;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;|
>>> 8;1023240137;1218;0;1;00a000001db74ace;;ac0174ca;43243423;16 78442111;5.6.128.8;1;0;;43242544;43244207;43243423;43243647; ;;1000;1;1;;0;;19;5.6.128.26;;372;2;372;2;;43243012;0;432435 62;15;175;15;175;15;175;1;;;;;5;48;19;20;49;50;;0;1;2;0;68;5 .6.128.8;;;;;;;301;5.6.128.8;;;8;372;2;;;;1;43244207;;;1;18; 43243423;0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;1;;;
>>
>>
>>
>> I don't think you've explicitly told us what you intend for your code
>> to do yet. Start there. Assuming you had a working program, and the
>> data sample that I'm quoting above, what would you expect to be in
>> %marketinfo?
>
> Thanks Brandon,
>
> Ultimately I am trying to take the value from the input data in
> index position "31" and assign one of the three keys to it. For
> example if index 31 has the value 801 it should be assigned "ICT"
> when I run the program. I hope I explained it better. Thank you for
> your help!
Hi Chris
Please bottom-post. It is the standard for this list, and with an
extended thread like this the messages get very messy if you are adding
to the beginning while all your replies are going at the end.
I hope the program below helps you. It shows a market of STL for both of
the records you have provided.
Cheers,
Rob
use strict;
use warnings;
# Market configurations has for cells
my %market_info = (
MCI => { start => 1,
end => 299, },
STL => { start => 300,
end => 599, },
ICT => { start => 800,
end => 850, },
);
sub market_for {
my $val = shift;
foreach my $k (keys %market_info) {
my ($start, $end) = [at] {$market_info{$k}}{qw/start end/};
return $k if $start <= $val and $val <= $end;
}
return "";
}
while (<DATA>) {
chomp;
if (/;/) {
my [at] data = split /;/;
my $mkt = market_for($data[31]);
print $mkt, "\n";
}
}
__DATA__
PACE | EVDOPCMD | 33.0 | 101218 | 07 |
8;1023240136;1218;0;1;00a000001a2bcdc7;0310003147702376;ac01 6d4a;;;5.6.128.8;0;;;;;43234169;43234349;;;10000;1;1;;0;;19; 5.6.128.22;172.30.151.5;304;3;304;3;;;;;15;175;15;175;15;175 ;1;1798;1251;0;0;2;19;20;;;;;1;1;1;0;128;5.6.128.8;;;;;;;301 ;5.6.128.8;;;8;304;3;;;;1;43244037;;;1;18;43234169;0;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;1;;;;;;43234416; 0;0;304;3;21;19;175;15;405;1;1;1;1;0;125;1;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;|;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;|
8;1023240137;1218;0;1;00a000001db74ace;;ac0174ca;43243423;16 78442111;5.6.128.8;1;0;;43242544;43244207;43243423;43243647; ;;1000;1;1;;0;;19;5.6.128.26;;372;2;372;2;;43243012;0;432435 62;15;175;15;175;15;175;1;;;;;5;48;19;20;49;50;;0;1;2;0;68;5 .6.128.8;;;;;;;301;5.6.128.8;;;8;372;2;;;;1;43244207;;;1;18; 43243423;0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;1;;;
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/