On 08/01/2011 04:26, Chris Stinemetz wrote:
From: Brandon McCaig [mailto:bamcc...@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;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;;;



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) = @{$market_info{$k}}{qw/start end/};
    return $k if $start <= $val and $val <= $end;
  }

  return "";
}

while (<DATA>) {
  chomp;

  if (/;/) {
    my @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;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;;;


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to