stuck and need some direction

stuck and need some direction

am 15.10.2011 07:08:37 von Chris Stinemetz

Hello,

I am trying to create a Perl script that will scan a file using regex
to match certain patterns and return uniq names and the total count of
each match.

With the sample input data (on the far bottom) the return value should
be CELL 20 in Column 1 with 2 Counts of CDM HEH in the third column.

So far I have two scripts. I am using one to allocate the subroutines
for each type of regex match, and the other script will call the
routines and populate the table that I am trying to create.

I think once I figure out how to handle the first subrountine I should
be able to get the rest, but I can't seem to wrap my head around it.

Thanks in advance,

Chris

My scripts thus far:

heh.pl
#!/usr/bin/perl

use warnings;
use strict;
requuire "heh.lib";

# my $filepath =
sprintf("/omp/omp-data/logs/OMPROP1/%s.APX",strftime("%y%m%d %H",localtime));
my $filepath = ("/tmp/110923.APX"); # for testing

my $runTime = sprintf("/home/cstinemetz/programs/%s.txt",strftime("%Y-%m-% d-%H:%M",localtime));

my $fileDate = strftime("%y%m%d%H%",localtime);

open my $fh, '<', $filepath or die "ERROR opening $filepath: $!";
open my $out, '>', $runTime or die "ERROR opening $runTime: $!";

while(<$fh>) {
if (/,HEH/);
}

print $out form
" ^>>>>>> HR 17-21 HEH Report @<<<<<<<<<<<<<<<<<<",

" Cell CBR CDM1 CDM2 CDM3 TFU1 TFU2
CCU EVM TXAMP CTRM ",
"--------- -------- -------- --------- --------- -------- ---------
-------- -------- -------- --------";





heh_lib.pl

#!/usr/bin/perl

use warnings;
use strict;

sub getCell {
my $str = "REPT:CELL, HEH";
}

input file:

10/13/11 00:00:57 #023342

00 REPT:CELL 20 CDM 1, CRC, HEH
SUPPRESSED MSGS: 0
ERROR TYPE: ONEBTS MODULAR CELL ERROR
SET: DS1-MLG ASSOCIATION CHANGE
MLG 1 DS1 1,2

00 00 00 00 00 00 00 00
03 00 00 00 00 00 05 05
05 05 05 05



10/13/11 00:00:58 #023345

00 REPT:CELL 20 CDM 1, CRC, HEH
SUPPRESSED MSGS: 0
ERROR TYPE: ONEBTS MODULAR CELL ERROR
SET: MLG BANDWIDTH CHANGE
MLG 1 BANDWIDTH = 3072

00 00 0C 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00



10/13/11 00:00:59 #023346

00 REPT: EVDO: RNC 20 CP FAILURE SUMMARY CONNECTION RELEASE
MAI OR FDI NOT RECEIVED, ERROR CODE 40000
BTS VAR, BAND CLASS 1, CHANNEL 1175, SECTOR VAR
TOTAL MESSAGES FOR 30-MINUTE INTERVAL: 9
SERVICE NODE 19, TP 310
IMSI VAR, HW TYPE 00ffff, HW ID VAR
UATI VAR
PERCEIVED SEVERITY: WARN
2011-10-13 00:01:41 REPORT #000001 FINAL

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

Re: stuck and need some direction

am 15.10.2011 07:55:20 von Leo Susanto

Not sure how to answer this, could you please give more information?

> With the sample input data (on the far bottom) the return value should
> be CELL 20 in Column 1 with 2 Counts of CDM HEH in the third column.

Is not sufficient for me.

On Fri, Oct 14, 2011 at 10:08 PM, Chris Stinemetz
wrote:
> Hello,
>
> I am trying to create a Perl script that will scan a file using regex
> to match certain patterns and return uniq names and the total count of
> each match.
>
> With the sample input data (on the far bottom) the return value should
> be CELL 20 in Column 1 with 2 Counts of CDM HEH in the third column.
>
> So far I have two scripts. I am using one to allocate the subroutines
> for each type of regex match, and the other script will call the
> routines and populate the table that I am trying to create.
>
> I think once I figure out how to handle the first subrountine I should
> be able to get the rest, but I can't seem to wrap my head around it.
>
> Thanks in advance,
>
> Chris
>
> My scripts thus far:
>
> heh.pl
> #!/usr/bin/perl
>
> use warnings;
> use strict;
> requuire "heh.lib";
>
> # my $filepath =3D
> sprintf("/omp/omp-data/logs/OMPROP1/%s.APX",strftime("%y%m%d %H",localtime=
));
> my $filepath =3D ("/tmp/110923.APX"); =A0 =A0 # for testing
>
> my $runTime =3D sprintf("/home/cstinemetz/programs/%s.txt",strftime("%Y-%=
m-%d-%H:%M",localtime));
>
> my $fileDate =3D strftime("%y%m%d%H%",localtime);
>
> open my $fh, '<', $filepath or die "ERROR opening $filepath: $!";
> open my $out, '>', $runTime or die "ERROR opening $runTime: $!";
>
> while(<$fh>) {
> =A0if (/,HEH/);
> }
>
> print $out form
> " =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0^>>>>>> HR 17-21 HEH Rep=
ort @<<<<<<<<<<<<<<<<<<",
>
> " =A0Cell =A0 =A0 =A0CBR =A0 =A0 =A0CDM1 =A0 =A0 CDM2 =A0 =A0 =A0 CDM3 =
=A0 =A0 TFU1 =A0 =A0 TFU2
> CCU =A0 =A0 EVM =A0 =A0 TXAMP =A0 =A0 CTRM =A0",
> "--------- -------- -------- --------- --------- -------- ---------
> -------- -------- -------- --------";
>
>
>
>
>
> heh_lib.pl
>
> #!/usr/bin/perl
>
> use warnings;
> use strict;
>
> sub getCell {
> =A0my $str =3D "REPT:CELL, HEH";
> }
>
> input file:
>
> 10/13/11 00:00:57 #023342
>
> =A000 REPT:CELL 20 CDM 1, CRC, HEH
> =A0 =A0 SUPPRESSED MSGS: 0
> =A0 =A0 ERROR TYPE: ONEBTS MODULAR CELL ERROR
> =A0 =A0 SET: DS1-MLG ASSOCIATION CHANGE
> =A0 =A0 MLG 1 DS1 1,2
>
> =A0 =A0 =A0 00 =A000 =A000 =A000 =A000 =A000 =A000 =A000
> =A0 =A0 =A0 03 =A000 =A000 =A000 =A000 =A000 =A005 =A005
> =A0 =A0 =A0 05 =A005 =A005 =A005
>
>
>
> 10/13/11 00:00:58 #023345
>
> =A000 REPT:CELL 20 CDM 1, CRC, HEH
> =A0 =A0 SUPPRESSED MSGS: 0
> =A0 =A0 ERROR TYPE: ONEBTS MODULAR CELL ERROR
> =A0 =A0 SET: MLG BANDWIDTH CHANGE
> =A0 =A0 MLG 1 BANDWIDTH =3D 3072
>
> =A0 =A0 =A0 00 =A000 =A00C =A000 =A000 =A000 =A000 =A000
> =A0 =A0 =A0 00 =A000 =A000 =A000 =A000 =A000 =A000 =A000
> =A0 =A0 =A0 00 =A000 =A000 =A000
>
>
>
> 10/13/11 00:00:59 #023346
>
> =A000 REPT: EVDO: RNC 20 CP FAILURE SUMMARY CONNECTION RELEASE
> =A0 =A0 MAI OR FDI NOT RECEIVED, ERROR CODE 40000
> =A0 =A0 BTS VAR, BAND CLASS 1, CHANNEL 1175, SECTOR VAR
> =A0 =A0 TOTAL MESSAGES FOR 30-MINUTE INTERVAL: 9
> =A0 =A0 SERVICE NODE 19, TP 310
> =A0 =A0 IMSI VAR, HW TYPE 00ffff, HW ID VAR
> =A0 =A0 UATI VAR
> =A0 =A0 PERCEIVED SEVERITY: WARN
> =A0 =A0 2011-10-13 00:01:41 REPORT #000001 FINAL
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> http://learn.perl.org/
>
>
>

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

Re: stuck and need some direction

am 15.10.2011 15:36:49 von Brock

On 2011.10.15.00.08, Chris Stinemetz wrote:
> My scripts thus far:
>
> heh.pl
> #!/usr/bin/perl
>
> use warnings;
> use strict;
> requuire "heh.lib";

Couple things here -- "require" is spelled wrong. But also you have to
say "heh.lib.pl". I will let someone else suggest that you organize this
using modules (.pm files and "use" statements).

> open my $fh, '<', $filepath or die "ERROR opening $filepath: $!";
> open my $out, '>', $runTime or die "ERROR opening $runTime: $!";

Nice use of 3-arg open and error handling.

> if (/,HEH/);

I believe you mean:

if (/, HEH/) { ... }

with a space after the comma. (my "..." is just a placeholder for what
you need to do in there).

Are all the data you want to extract always contained on this one line?

> print $out form
> " ^>>>>>> HR 17-21 HEH Report @<<<<<<<<<<<<<<<<<<",
>
> " Cell CBR CDM1 CDM2 CDM3 TFU1 TFU2
> CCU EVM TXAMP CTRM ",
> "--------- -------- -------- --------- --------- -------- ---------
> -------- -------- -------- --------";

Formats! Neat. I've only used those once In Real Life.

> heh_lib.pl
>
> #!/usr/bin/perl
>
> use warnings;
> use strict;
>
> sub getCell {
> my $str = "REPT:CELL, HEH";
> }

OK -- so I think you want to call getCell on each line that contains
", HEH" eh? So what you want to do is pass the line into getCell for it
to pull stuff out of, and then get the good bits back out.

I wasn't entirely clear on what you want to get back out, but here is an
example:

my $input_line = "00 REPT:CELL 20 CDM 1, CRC, HEH\n";

my ($cell, $cdm) = getCell($input_line);

print "Cell: $cell CDM: $cdm\n";

sub getCell {
my ($input_line) = @_; # gets the $input_line parameter
if($input_line =~ /Cell: (\d+) CDM (\d+),/) {
# We found something that looks like "Cell: XXX CDM YYY,"
# These are in parenthesis, so go into $1 and $2
my $cell = $1;
my $cdm = $2;
return ($cell, $cdm);
# I could have done: return ($1, $2)
} else {
die "BAD LINE: $input_line\n";
}
}

Since this is a teaching list -- I ran this and got:

BAD LINE: 00 REPT:CELL 20 CDM 1, CRC, HEH

Digression: So... that didn't work. I then noticed that my regex says
"Cell:" but the output (and the input) say "CELL". Not only does mine
have a ":" when it should't, but also regexes are case-sensitive by
default. I changed my regex to use "CELL"

my $input_line = "00 REPT:CELL 20 CDM 1, CRC, HEH\n";

my ($cell, $cdm) = getCell($input_line);

print "Cell: $cell CDM: $cdm\n";

sub getCell {
my ($input_line) = @_; # gets the $input_line parameter
if($input_line =~ /CELL (\d+) CDM (\d+),/) {
# We found something that looks like "Cell: XXX CDM YYY,"
# These are in parenthesis, so go into $1 and $2
my $cell = $1;
my $cdm = $2;
return ($cell, $cdm);
# I could have done: return ($1, $2)
} else {
die "BAD LINE: $input_line\n";
}
}

And now I get:

Cell: 20 CDM: 1

This will be a bit more complex if you need to extract data from other
lines as well.

--Brock


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

Re: stuck and need some direction

am 15.10.2011 15:53:24 von Brock

On 2011.10.15.00.08, Chris Stinemetz wrote:
> I am trying to create a Perl script that will scan a file using regex
> to match certain patterns and return uniq names and the total count of
> each match.
>
> With the sample input data (on the far bottom) the return value should
> be CELL 20 in Column 1 with 2 Counts of CDM HEH in the third column.

Now I'm starting to think you weren't asking for help on the matching,
but rather on the summarizing. What would really help is if you could
also give an example of the output you want.

For that you probably want a hash (or hash-of-hashes or ... some data
structure with a hash) -- I think of a hash anytime I see words like
"unique".

I'll just pretend that you will have a unique cell, and then a count of
the CDM type for each. This might not actually make sense for your data
though.

So we can build such a hash by hand:

my $summary = {};

# Line: 00 REPT:CELL 20 CDM 1, CRC, HEH
$summary->{"20"}->{"CDM"}->{"HEH"}++; # Cell 20, CDM HEH

# Line: 00 REPT:CELL 20 CDM 1, CRC, HEH
$summary->{"20"}->{"CDM"}->{"HEH"}++; # Cell 20, CDM HEH

But really I am probably speaking gibberish until you provide some
sample output. Especially it would be good to have other test cases --
like what other cells would look like, or if there could be non-HEH
CDMs.

--Brock


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

Re: stuck and need some direction

am 15.10.2011 20:12:26 von Leo Susanto

Chris, You need to let us know what do you want the script to do,
believe me, writing the script is the easy part.

>
> But really I am probably speaking gibberish until you provide some
> sample output. Especially it would be good to have other test cases --
> like what other cells would look like, or if there could be non-HEH
> CDMs.
>
> --Brock

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

Re: stuck and need some direction

am 15.10.2011 20:55:12 von Chris Stinemetz

On Sat, Oct 15, 2011 at 1:12 PM, Leo Susanto wrote:
> Chris, You need to let us know what do you want the script to do,
> believe me, writing the script is the easy part.
>


Okay I will try to clarify. For right now there is only one type of
line that I am interested in from the input file.

I will try to break this down sequentually in how I am trying to
construct this program:

Read the input file and only keep lines that have a line with the
text pattern: HEH

Now the tricky part I am having some difficulty with:

sort and count each occurence of different types of HEH grouped by the
CELL number.

And finally datafill the format table with the results.

So for example:

00 REPT:CELL 20 CDM 1, CRC, HEH
SUPPRESSED MSGS: 0
ERROR TYPE: ONEBTS MODULAR CELL ERROR
SET: DS1-MLG ASSOCIATION CHANGE
MLG 1 DS1 1,2

00 REPT:CELL 20 CDM 1, CRC, HEH
SUPPRESSED MSGS: 0
ERROR TYPE: ONEBTS MODULAR CELL ERROR
SET: DS1-MLG ASSOCIATION CHANGE
MLG 1 DS1 1,2

Would output something like:

Cell CBR CDM1 CDM2 CDM3 TFU1 TFU2 CCU EVM TXAMP CTRM
--------- -------- -------- --------- --------- -------- --------- -------- -------- -------- --------
20 2


I hope this helps clarify.

Thanks for all the help,

Chris

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

Re: stuck and need some direction

am 15.10.2011 21:28:38 von timothy adigun

--f46d04426a6875868b04af5b6125
Content-Type: text/plain; charset=ISO-8859-1

Hi Chris,
I really believe people would like to help here, but if no one can make head
of what you posted, they may as well ignore your codes and call for help all
together.
Fine you have showed, what your raw data are, but please can you show how
you want your output to look like? Because going by your code, I really
can't figure out what " Cell CBR CDM1 CDM2 CDM3
TFU1 TFU2 CCU EVM TXAMP CTRM " are, even from your raw
data. I suppose you want to use format in perl.
The following are my observations in your codes:
1. 'require' is spelt wrongly,
2. require will look out for heh_lib.pm, and what you have is heh_lib.pl, so
you need to specify that fully in your code i.e require 'heh_lib.pl',
3. the required script name as indicated from your code is also wrong,
according to your mail. In the code you have < requuire "heh.lib">,
meanwhile, the script is called ,
4. heh_lib.pl has only one subroutine, why not include that in your
heh.plscript and use it directly. In other words, why
heh_lib.pl?
5. strftime(...) subroutine is not shown in any script here?
6. if (/,HEH/); is also wrong, maybe you want to say print $_ if /HEH/;?
7. Also check the use of sprintf in void context.
I think you will have to make a whole lot of things clear, however, like Leo
said maybe if you specify what and how your output will look like, the
"coding" part might just be so easy or people in the forum might know how to
advise.
regards,
--
Tim

--f46d04426a6875868b04af5b6125--

Re: stuck and need some direction

am 15.10.2011 21:37:36 von Leo Susanto

use strict;
my %CELL;
my %CELL_TYPE_COUNT;
while (my $line =3D ) {
if ($line =3D~ /CELL\s+(\d+)\s+(.+?),.+?HEH/) { # take CELL number into
$1 and the information after the number (and before the first comma)
into $2
$CELL{$1}{$2}++;
$CELL_TYPE_COUNT{$2}++;
}
}

# header
print "CELL,".join(",",sort keys %CELL_TYPE_COUNT)."\n";
# body
foreach my $cellNo (sort keys %CELL) { # you can use map function, but
it never sits well on my brain
print "$cellNo";
foreach my $info (sort keys %CELL_TYPE_COUNT) {
print ", $CELL{$cellNo}{$info}";
}
print "\n";
}

__DATA__
00 REPT:CELL 20 CDM 1, CRC, HEH
SUPPRESSED MSGS: 0
ERROR TYPE: ONEBTS MODULAR CELL ERROR
SET: DS1-MLG ASSOCIATION CHANGE
MLG 1 DS1 1,2

00 REPT:CELL 20 CDM 1, CRC, HEH
SUPPRESSED MSGS: 0
ERROR TYPE: ONEBTS MODULAR CELL ERROR
SET: DS1-MLG ASSOCIATION CHANGE
MLG 1 DS1 1,2

Output:
CELL,CDM 1
20, 2

Let me know if it's correct.

On Sat, Oct 15, 2011 at 11:55 AM, Chris Stinemetz
wrote:
> On Sat, Oct 15, 2011 at 1:12 PM, Leo Susanto wrote=
:
>> Chris, You need to let us know what do you want the script to do,
>> believe me, writing the script is the easy part.
>>
>
>
> Okay I will try to clarify. For right now there is only one type of
> line that I am interested in from the input file.
>
> I will try to break this down sequentually in how I am trying to
> construct this program:
>
> Read the input file and only keep lines that =A0have a line with the
> text pattern: HEH
>
> Now the tricky part I am having some difficulty with:
>
> sort and count each occurence of different types of HEH grouped by the
> CELL number.
>
> And finally datafill the format table with the results.
>
> So for example:
>
> =A000 REPT:CELL 20 CDM 1, CRC, HEH
> =A0 =A0 SUPPRESSED MSGS: 0
> =A0 =A0 ERROR TYPE: ONEBTS MODULAR CELL ERROR
> =A0 =A0 SET: DS1-MLG ASSOCIATION CHANGE
> =A0 =A0 MLG 1 DS1 1,2
>
> =A000 REPT:CELL 20 CDM 1, CRC, HEH
> =A0 =A0 SUPPRESSED MSGS: 0
> =A0 =A0 ERROR TYPE: ONEBTS MODULAR CELL ERROR
> =A0 =A0 SET: DS1-MLG ASSOCIATION CHANGE
> =A0 =A0 MLG 1 DS1 1,2
>
> Would output something like:
>
> Cell =A0 =A0CBR =A0 =A0 CDM1 =A0 =A0CDM2 =A0 =A0CDM3 =A0 =A0TFU1 =A0 =A0T=
FU2 =A0 =A0CCU =A0 =A0 EVM =A0 =A0 TXAMP =A0 CTRM
> --------- =A0 =A0 =A0 -------- =A0 =A0 =A0 =A0-------- =A0 =A0 =A0 =A0---=
------ =A0 =A0 =A0 --------- =A0 =A0 =A0 -------- =A0 =A0 =A0 =A0--------- =
=A0 =A0 =A0 -------- =A0 =A0 =A0 =A0-------- =A0 =A0 =A0 =A0-------- =A0 =
=A0 =A0 =A0--------
> 20 =A0 =A0 =A0 =A0 =A0 =A0 =A02
>
>
> I hope this helps clarify.
>
> Thanks for all the help,
>
> Chris
>

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

Re: stuck and need some direction

am 15.10.2011 21:40:53 von Leo Susanto

use strict;
my %CELL;
my %CELL_TYPE_COUNT;
while (my $line =3D ) {
if ($line =3D~ /CELL\s+(\d+)\s+(.+?),.+?HEH/) { # take CELL number into
$1 and the information after the number (and before the first comma)
into $2
$CELL{$1}{$2}++;
$CELL_TYPE_COUNT{$2}++;
}
}

# header
print "CELL,".join(",",sort keys %CELL_TYPE_COUNT)."\n";
# body
foreach my $cellNo (sort keys %CELL) { # you can use map function, but
it never sits well on my brain
print "$cellNo";
foreach my $info (sort keys %CELL_TYPE_COUNT) {
if (exists $CELL{$cellNo}{$info}) {
print ", $CELL{$cellNo}{$info}";
}
else {
print ", 0";
}
}
print "\n";
}


__DATA__
00 REPT:CELL 20 CDM 1, CRC, HEH
SUPPRESSED MSGS: 0
ERROR TYPE: ONEBTS MODULAR CELL ERROR
SET: DS1-MLG ASSOCIATION CHANGE
MLG 1 DS1 1,2

00 REPT:CELL 20 CDM 1, CRC, HEH
SUPPRESSED MSGS: 0
ERROR TYPE: ONEBTS MODULAR CELL ERROR
SET: DS1-MLG ASSOCIATION CHANGE
MLG 1 DS1 1,2

00 REPT:CELL 21 CDM 2, CRC, HEH <- my own test data

CELL,CDM 1,CDM 2
20, 2, 0
21, 0, 1

>
> Let me know if it's correct.
>
> On Sat, Oct 15, 2011 at 11:55 AM, Chris Stinemetz
> wrote:
>> On Sat, Oct 15, 2011 at 1:12 PM, Leo Susanto wrot=
e:
>>> Chris, You need to let us know what do you want the script to do,
>>> believe me, writing the script is the easy part.
>>>
>>
>>
>> Okay I will try to clarify. For right now there is only one type of
>> line that I am interested in from the input file.
>>
>> I will try to break this down sequentually in how I am trying to
>> construct this program:
>>
>> Read the input file and only keep lines that =A0have a line with the
>> text pattern: HEH
>>
>> Now the tricky part I am having some difficulty with:
>>
>> sort and count each occurence of different types of HEH grouped by the
>> CELL number.
>>
>> And finally datafill the format table with the results.
>>
>> So for example:
>>
>> =A000 REPT:CELL 20 CDM 1, CRC, HEH
>> =A0 =A0 SUPPRESSED MSGS: 0
>> =A0 =A0 ERROR TYPE: ONEBTS MODULAR CELL ERROR
>> =A0 =A0 SET: DS1-MLG ASSOCIATION CHANGE
>> =A0 =A0 MLG 1 DS1 1,2
>>
>> =A000 REPT:CELL 20 CDM 1, CRC, HEH
>> =A0 =A0 SUPPRESSED MSGS: 0
>> =A0 =A0 ERROR TYPE: ONEBTS MODULAR CELL ERROR
>> =A0 =A0 SET: DS1-MLG ASSOCIATION CHANGE
>> =A0 =A0 MLG 1 DS1 1,2
>>
>> Would output something like:
>>
>> Cell =A0 =A0CBR =A0 =A0 CDM1 =A0 =A0CDM2 =A0 =A0CDM3 =A0 =A0TFU1 =A0 =A0=
TFU2 =A0 =A0CCU =A0 =A0 EVM =A0 =A0 TXAMP =A0 CTRM
>> --------- =A0 =A0 =A0 -------- =A0 =A0 =A0 =A0-------- =A0 =A0 =A0 =A0--=
------- =A0 =A0 =A0 --------- =A0 =A0 =A0 -------- =A0 =A0 =A0 =A0---------=
=A0 =A0 =A0 -------- =A0 =A0 =A0 =A0-------- =A0 =A0 =A0 =A0-------- =A0 =
=A0 =A0 =A0--------
>> 20 =A0 =A0 =A0 =A0 =A0 =A0 =A02
>>
>>
>> I hope this helps clarify.
>>
>> Thanks for all the help,
>>
>> Chris
>>
>

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

Re: stuck and need some direction

am 15.10.2011 23:36:28 von timothy adigun

--bcaec52161cf9ce3d904af5d2aa0
Content-Type: text/plain; charset=ISO-8859-1

Hi Chris,
Check this if it helps.


#!\usr\bin\perl -w
use strict;
use Carp;


my( $Cell,$CBR,$CDM1,$CDM2,$CDM3,$TFU1,$TFU2,$CCU,$EVM,$TXAMP,$C TRM )

=('Cell','CBR','CDM1','CDM2','CDM3','TFU1','TFU2','CCU','EVM ','TXAMP','CTRM');
my $header='HR 17-21 HEH Report';

croak "please, specify input file" unless $ARGV[0];
my $filename=$ARGV[0];
my($cell,$count)=0;
open my $fh, '<', $filename or croak "ERROR opening $filename: $!";
open FILE,">",'output.txt' or croak "can't open file:$!";
while(my $line=<$fh>) {chomp $cell;
if ($line=~/HEH/sixmg){
++$count; # NOTE: this might not be the
best way to go in case your $cell values changes

($cell=$line)=~s/(?:.*?)CELL\s+([0-9]+)\s+(.+?),.*?HEH$/$1/i xmg;
}
}write FILE;
close FILE or croak"can't close file";
close $fh or croak"can't close file";


format FILE_TOP=
@||||||||||||||||||||||||||
$header
@<<<< @<<<< @<<<< @<<<< @<<<< @<<<< @<<<< @<<<< @<<<< @<<<<
@<<<<
$Cell, $CBR, $CDM1 , $CDM2 , $CDM3, $TFU1, $TFU2, $CCU, $EVM,
$TXAMP, $CTRM
------------------------------------------------------------ ------------------------------------------------------------ ---
..
format FILE=
@<<<<<<<<<< @###
$cell, $count
..



Please note the dot in the format 'template'.
regards,
Tim

--bcaec52161cf9ce3d904af5d2aa0--

Re: stuck and need some direction

am 15.10.2011 23:38:03 von timothy adigun

--bcaec520f5c1485a7604af5d3018
Content-Type: text/plain; charset=ISO-8859-1

> Hi Chris,
> Check this if it helps.
>
>
> #!\usr\bin\perl -w
> use strict;
> use Carp;
>
>
> my( $Cell,$CBR,$CDM1,$CDM2,$CDM3,$TFU1,$TFU2,$CCU,$EVM,$TXAMP,$C TRM )
>
> =('Cell','CBR','CDM1','CDM2','CDM3','TFU1','TFU2','CCU','EVM ','TXAMP','CTRM');
> my $header='HR 17-21 HEH Report';
>
> croak "please, specify input file" unless $ARGV[0];
> my $filename=$ARGV[0];
> my($cell,$count)=0;
> open my $fh, '<', $filename or croak "ERROR opening $filename: $!";
> open FILE,">",'output.txt' or croak "can't open file:$!";
> while(my $line=<$fh>) {chomp $cell;
> if ($line=~/HEH/sixmg){
> ++$count; # NOTE: this might not be
> the best way to go in case your $cell values changes
>
> ($cell=$line)=~s/(?:.*?)CELL\s+([0-9]+)\s+(.+?),.*?HEH$/$1/i xmg;
> }
> }write FILE;
> close FILE or croak"can't close file";
> close $fh or croak"can't close file";
>
>
> format FILE_TOP=
> @||||||||||||||||||||||||||
> $header
> @<<<< @<<<< @<<<< @<<<< @<<<< @<<<< @<<<< @<<<< @<<<< @<<<<
> @<<<<
> $Cell, $CBR, $CDM1 , $CDM2 , $CDM3, $TFU1, $TFU2, $CCU, $EVM,
> $TXAMP, $CTRM
>
> ------------------------------------------------------------ ------------------------------------------------------------ ---
> .
> format FILE=
> @<<<<<<<<<< @###
> $cell, $count
> .
>
>

>
> Please note the dot in the format 'template'.
>
> output.txt
HR 17-21 HEH Report
Cell CBR CDM1 CDM2 CDM3 TFU1 TFU2 CCU EVM TXAMP
CTRM
------------------------------------------------------------ ------------------------------------------------------------ ---
20 2




--
Tim

--bcaec520f5c1485a7604af5d3018--

Re: stuck and need some direction

am 15.10.2011 23:47:58 von timothy adigun

--bcaec520e5a7be1e0504af5d53fa
Content-Type: text/plain; charset=ISO-8859-1

Oopss my error! chomp $cell in the code above should be chomp $line. thanks

--bcaec520e5a7be1e0504af5d53fa--

Re: stuck and need some direction

am 16.10.2011 06:34:58 von Chris Stinemetz

Thank you everyone for your suggestions. They were very helpful!

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

Re: stuck and need some direction

am 16.10.2011 14:59:00 von Chris Stinemetz

On Sat, Oct 15, 2011 at 2:40 PM, Leo Susanto wrote:
> use strict;
> my %CELL;
> my %CELL_TYPE_COUNT;
> while (my $line =3D ) {
> =A0 =A0 =A0 =A0if ($line =3D~ /CELL\s+(\d+)\s+(.+?),.+?HEH/) { # take CEL=
L number into
> $1 and the information after the number (and before the first comma)
> into $2
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0$CELL{$1}{$2}++;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0$CELL_TYPE_COUNT{$2}++;
> =A0 =A0 =A0 =A0}
> }
>
> # header
> print "CELL,".join(",",sort keys %CELL_TYPE_COUNT)."\n";
> # body
> foreach my $cellNo (sort keys %CELL) { # you can use map function, but
> it never sits well on my brain
> =A0 =A0 =A0 =A0print "$cellNo";
> =A0 =A0 =A0 =A0foreach my $info (sort keys %CELL_TYPE_COUNT) {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if (exists $CELL{$cellNo}{$info}) {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0print ", $CELL{$cellNo}{$i=
nfo}";
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0}
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0else {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0print ", 0";
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0}
> =A0 =A0 =A0 =A0}
> =A0 =A0 =A0 =A0print "\n";
> }
>
>
> __DATA__
> =A000 REPT:CELL 20 CDM 1, CRC, HEH
> =A0 =A0SUPPRESSED MSGS: 0
> =A0 =A0ERROR TYPE: ONEBTS MODULAR CELL ERROR
> =A0 =A0SET: DS1-MLG ASSOCIATION CHANGE
> =A0 =A0MLG 1 DS1 1,2
>
> =A000 REPT:CELL 20 CDM 1, CRC, HEH
> =A0 =A0SUPPRESSED MSGS: 0
> =A0 =A0ERROR TYPE: ONEBTS MODULAR CELL ERROR
> =A0 =A0SET: DS1-MLG ASSOCIATION CHANGE
> =A0 =A0MLG 1 DS1 1,2
>
> =A000 REPT:CELL 21 CDM 2, CRC, HEH =A0<- my own test data
>
> CELL,CDM 1,CDM 2
> 20, 2, 0
> 21, 0, 1
>
>>

Any advice on how to apply the results to a perlform mechenism?

I have never used hashes in perlform before.

Thanks,

Chris

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

Re: stuck and need some direction

am 16.10.2011 17:10:37 von Shlomi Fish

On Sun, 16 Oct 2011 07:59:00 -0500
Chris Stinemetz wrote:

> On Sat, Oct 15, 2011 at 2:40 PM, Leo Susanto wrote:
> > CELL,CDM 1,CDM 2
> > 20, 2, 0
> > 21, 0, 1
> >
> >>
>
> Any advice on how to apply the results to a perlform mechenism?
>

Simple: don't use perlform, but one of the superior and saner user-land
alternatives on CPAN:

http://perl-begin.org/tutorials/bad-elements/#perlform

Regards,

Shlomi Fish

--
------------------------------------------------------------ -----
Shlomi Fish http://www.shlomifish.org/
Freecell Solver - http://fc-solve.berlios.de/

Larry Wall can program in his sleep.

Please reply to list if it's a mailing list post - http://shlom.in/reply .

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

Re: stuck and need some direction

am 16.10.2011 20:10:13 von Leo Susanto

On Sun, Oct 16, 2011 at 8:10 AM, Shlomi Fish wrote=
:
> On Sun, 16 Oct 2011 07:59:00 -0500
> Chris Stinemetz wrote:
>
>> On Sat, Oct 15, 2011 at 2:40 PM, Leo Susanto wrot=
e:
>> > CELL,CDM 1,CDM 2
>> > 20, 2, 0
>> > 21, 0, 1
>> >

Well, the problem with perlform is: it expects a certain number of column.

My question to you is: is the number of cell type constant or is it
indeterminate?

If it's indeterminate then it's better to stick with print, or printf
if you want some formatting.
If you have to use perlform, then you need to see if you can install a
new module on your system (Perl6::Form based on Shlomi's
recommendation), i.e.: if you are running Perl on windows ActiveState,
then you can execute: "ppm install Perl6::Form". Other than that you
need to talk to your sys admin or setup your dev environment.

>>
>> Any advice on how to apply the results to a perlform mechenism?
>>
>
> Simple: don't use perlform, but one of the superior and saner user-land
> alternatives on CPAN:
>
> http://perl-begin.org/tutorials/bad-elements/#perlform
>
> Regards,
>
> =A0 =A0 =A0 =A0Shlomi Fish
>
> --
> ------------------------------------------------------------ -----
> Shlomi Fish =A0 =A0 =A0 http://www.shlomifish.org/
> Freecell Solver - http://fc-solve.berlios.de/
>
> Larry Wall can program in his sleep.
>
> Please reply to list if it's a mailing list post - http://shlom.in/reply =
..
>

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

Re: stuck and need some direction

am 16.10.2011 21:08:17 von Chris Stinemetz

>
> Well, the problem with perlform is: it expects a certain number of column.
>
> My question to you is: is the number of cell type constant or is it
> indeterminate?
>
> If it's indeterminate then it's better to stick with print, or printf
> if you want some formatting.

Cell is indeterminate. Always different.

Is it possible to create a header subroutine and call it when I create
the format?

I am getting the following error:

$ perl -c hehTest.pl
syntax error at hehTest.pl line 34, near "print format
header "
hehTest.pl had compilation errors.
..
What I have so far is below.

#!/usr/bin/perl

use warnings;
use strict;
use POSIX;
use Perl6::Form;

# my $filepath =
sprintf("/omp/omp-data/logs/OMPROP1/%s.APX",strftime("%y%m%d %H",localtime));
my $filepath = ("/tmp/110923.APX"); # for testing

my $runTime = sprintf("/home/cstinemetz/programs/%s.txt",strftime("%Y-%m-% d-%H:%M",localtime));

my $fileDate = strftime("%y%m%d%H%",localtime);

open my $fh, '<', $filepath or die "ERROR opening $filepath: $!";
open my $out, '>', $runTime or die "ERROR opening $runTime: $!";

sub header {
my $header = "CELL\t".join("\t",sort keys my %CELL_TYPE_COUNT)."\n";
return $_;
}

my %CELL;
my %CELL_TYPE_COUNT;
while (my $line = ) {
if ($line =~ /CELL\s+(\d+)\s+(.+?),.+?HEH/) {
$CELL{$1}{$2}++;
$CELL_TYPE_COUNT{$2}++;
}
}

print format
header => sub { return &header; }

# header
print "CELL\t".join("\t",sort keys %CELL_TYPE_COUNT)."\n";
# body
foreach my $cellNo (sort keys %CELL) {
print "$cellNo";
foreach my $info (sort keys %CELL_TYPE_COUNT) {
if (exists $CELL{$cellNo}{$info}) {
print "\t $CELL{$cellNo}{$info}";
}
else {
print "\t 0";
}
}
print "\n";
}

__DATA__
EPT:CELL 20 CDM 1, CRC, HEH
SUPPRESSED MSGS: 0
ERROR TYPE: ONEBTS MODULAR CELL ERROR
SET: DS1-MLG ASSOCIATION CHANGE
MLG 1 DS1 1,2

00 REPT:CELL 20 CDM 1, CRC, HEH
SUPPRESSED MSGS: 0
ERROR TYPE: ONEBTS MODULAR CELL ERROR
SET: DS1-MLG ASSOCIATION CHANGE
MLG 1 DS1 1,2

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