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 corresponding key indicated in my hash in the below program. Any help is appreciated. I just finished the Llama book and am getting a better idea on how to program perl, but I have quite a ways to go to feel comfortable. Thank you, #!/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;ac016d4a;;;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;1678442111;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;18;43243423;0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;1;;; Chris -----Original Message----- From: John Delacour [mailto:johndelac...@gmail.com] Sent: Thursday, January 06, 2011 2:16 PM To: beginners@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 = <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-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/