Re: How to replace a literal with a variable

2002-07-31 Thread Larry Steinberg

Timothy,

Yes, thanks!

"Timothy Johnson" <[EMAIL PROTECTED]> wrote in message
C0FD5BECE2F0C84EAA97D7300A500D50046DC99B@SMILEY">news:C0FD5BECE2F0C84EAA97D7300A500D50046DC99B@SMILEY...
>
> Do you mean something like this?
>
> 
> open(LOG,"log.txt");
> my %errs = ();
> while(){
>   chomp $_;
>   my($details,$err) = split(/\|/,$_);
>   $err =~ s/^\s+//;
>   $errs{$err}++ if $err;
> }
>
> print "Total for each error:\n";
> print "-\n\n";
>
> foreach(sort keys %errs){
>   print "$_.$errs{$_}\n";
> }
>
> 
>
> That will split each line on a pipe, then remove whitespaces at the
> beginning of the variable, then store it as a hash key.
>
> -Original Message-
> From: Larry Steinberg [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, July 30, 2002 10:17 AM
> To: [EMAIL PROTECTED]
> Subject: Re: How to replace a literal with a variable
>
>
> Here is what I need. I hope this explains it better.
>
> I have a script which creates a report for No Listings Found errors. I'd
> like to adapt it to create a report for any "ERR " code condition in the
> log. The errors and values are below. TIA!
>
> >>>Error | Value<<<
>
> city not in state | TSE
>
> ZIP not in state | ZSE
>
> ZIP not in city | ZTE
>
> can't find address in distance search | BAD
>
> not enough address info in distance search | DBK
>
> keyword but no category or name | KEY
>
> more than one address in distance search | MUL
>
> network problem | NET
>
> no such category | CAT
>
> no such category and no such city | NCC
>
> no such category and city not in state | NCG
>
> no such city | CIT
>
> no listings found | NLF
>
> no listings found and no such phone number | NSP
>
> no fields, state only, or no state | NST
>
> no such state | NSS
>
> no such ZIP | ZIP
>
> only one phone field | PHN
>
> too many listings | TML
>
> search timeout | TIM
>
> no state and no ZIP | MSZ
>
> no coverage | MCV
>
> search failure | MSF
>
> failure to connect to server | MSV
>
> unknown error ("oops" page) | UNK
>
> no results found | NRF
>
> "Nkuipers" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> > I'm probably not understanding what exactly you needbut...as I see
it,
> > $err holds whatever error message that you captured with a regex.  So if
> you
> > want to make a variable with the same name as the literal, dereference a
> > variable with the name held in $err and the new var will autovivify:
> >
> > ($err) = ( $line =~ / ERR (\w+) /i );
> > my $$err;
> >
> > I think.
> >
>
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: How to replace a literal with a variable

2002-07-30 Thread Timothy Johnson


Do you mean something like this?


open(LOG,"log.txt");
my %errs = ();
while(){
  chomp $_;
  my($details,$err) = split(/\|/,$_);
  $err =~ s/^\s+//;
  $errs{$err}++ if $err;
}

print "Total for each error:\n";
print "-\n\n";

foreach(sort keys %errs){
  print "$_.$errs{$_}\n";
}



That will split each line on a pipe, then remove whitespaces at the
beginning of the variable, then store it as a hash key.

-Original Message-
From: Larry Steinberg [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, July 30, 2002 10:17 AM
To: [EMAIL PROTECTED]
Subject: Re: How to replace a literal with a variable


Here is what I need. I hope this explains it better.

I have a script which creates a report for No Listings Found errors. I'd
like to adapt it to create a report for any "ERR " code condition in the
log. The errors and values are below. TIA!

>>>Error | Value<<<

city not in state | TSE

ZIP not in state | ZSE

ZIP not in city | ZTE

can't find address in distance search | BAD

not enough address info in distance search | DBK

keyword but no category or name | KEY

more than one address in distance search | MUL

network problem | NET

no such category | CAT

no such category and no such city | NCC

no such category and city not in state | NCG

no such city | CIT

no listings found | NLF

no listings found and no such phone number | NSP

no fields, state only, or no state | NST

no such state | NSS

no such ZIP | ZIP

only one phone field | PHN

too many listings | TML

search timeout | TIM

no state and no ZIP | MSZ

no coverage | MCV

search failure | MSF

failure to connect to server | MSV

unknown error ("oops" page) | UNK

no results found | NRF

"Nkuipers" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> I'm probably not understanding what exactly you needbut...as I see it,
> $err holds whatever error message that you captured with a regex.  So if
you
> want to make a variable with the same name as the literal, dereference a
> variable with the name held in $err and the new var will autovivify:
>
> ($err) = ( $line =~ / ERR (\w+) /i );
> my $$err;
>
> I think.
>



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: How to replace a literal with a variable

2002-07-30 Thread Larry Steinberg

Here is what I need. I hope this explains it better.

I have a script which creates a report for No Listings Found errors. I'd
like to adapt it to create a report for any "ERR " code condition in the
log. The errors and values are below. TIA!

>>>Error | Value<<<

city not in state | TSE

ZIP not in state | ZSE

ZIP not in city | ZTE

can't find address in distance search | BAD

not enough address info in distance search | DBK

keyword but no category or name | KEY

more than one address in distance search | MUL

network problem | NET

no such category | CAT

no such category and no such city | NCC

no such category and city not in state | NCG

no such city | CIT

no listings found | NLF

no listings found and no such phone number | NSP

no fields, state only, or no state | NST

no such state | NSS

no such ZIP | ZIP

only one phone field | PHN

too many listings | TML

search timeout | TIM

no state and no ZIP | MSZ

no coverage | MCV

search failure | MSF

failure to connect to server | MSV

unknown error ("oops" page) | UNK

no results found | NRF

"Nkuipers" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> I'm probably not understanding what exactly you needbut...as I see it,
> $err holds whatever error message that you captured with a regex.  So if
you
> want to make a variable with the same name as the literal, dereference a
> variable with the name held in $err and the new var will autovivify:
>
> ($err) = ( $line =~ / ERR (\w+) /i );
> my $$err;
>
> I think.
>



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: How to replace a literal with a variable

2002-07-30 Thread Jeff 'japhy' Pinyan

On Jul 30, Larry Steinberg said:

>How can I replace the literal "nlf" with a variable in the code below?

This was asked and answered in CLPM, but I'll answer anyway.

>sub parseLogLine {
>$line = $_;
>
>%searchInfo = ();
>@searchInfo = split / +/, $line;
>
># found any listings?
>$numListings = $searchInfo[8];
>$numCategories = $searchInfo[10];
>
># did I detect any errors or exceptions
>($err) = ( $line =~ / ERR (\w+) /i );
>
>if ( $err ne "") {
>$err =~ tr/A-Z/a-z/;
> if ($err eq "nlf") {
> $NLFerr++;
> }
> elsif ($err eq "cat") {
> $CATerr++;
> }

You'll want to make a hash, %count let's call it:

  if ($err ne "") {
$count{lc $err}++;
  }

You should use lc() instead of tr/A-Z/a-z/.

>}

-- 
Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
 what does y/// stand for?   why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: How to replace a literal with a variable

2002-07-30 Thread Jeff 'japhy' Pinyan

On Jul 30, nkuipers said:

>I'm probably not understanding what exactly you needbut...as I see it,
>$err holds whatever error message that you captured with a regex.  So if you
>want to make a variable with the same name as the literal, dereference a
>variable with the name held in $err and the new var will autovivify:
>
>($err) = ( $line =~ / ERR (\w+) /i );
>my $$err;

No.  First, symbolic references are EVIL.  Second, you can't do that with
my().

-- 
Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
 what does y/// stand for?   why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: How to replace a literal with a variable

2002-07-30 Thread Timothy Johnson


If you just want to repolace "nlf" with a variable, you can just replace it
with a variable?

if ($err eq $variable){

Or else you need to be more specific about what you need.

-Original Message-
From: Larry Steinberg [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, July 30, 2002 8:06 AM
To: [EMAIL PROTECTED]
Subject: How to replace a literal with a variable


Hi,

How can I replace the literal "nlf" with a variable in the code below?
Thanks in advance.

sub parseLogLine {
$line = $_;

%searchInfo = ();
@searchInfo = split / +/, $line;

# found any listings?
$numListings = $searchInfo[8];
$numCategories = $searchInfo[10];

# did I detect any errors or exceptions
($err) = ( $line =~ / ERR (\w+) /i );

if ( $err ne "") {
$err =~ tr/A-Z/a-z/;
 if ($err eq "nlf") {
 $NLFerr++;
 }
 elsif ($err eq "cat") {
 $CATerr++;
 }
}


-Larry



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: How to replace a literal with a variable

2002-07-30 Thread nkuipers

I'm probably not understanding what exactly you needbut...as I see it, 
$err holds whatever error message that you captured with a regex.  So if you 
want to make a variable with the same name as the literal, dereference a 
variable with the name held in $err and the new var will autovivify:

($err) = ( $line =~ / ERR (\w+) /i );
my $$err;

I think.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




How to replace a literal with a variable

2002-07-30 Thread Larry Steinberg

Hi,

How can I replace the literal "nlf" with a variable in the code below?
Thanks in advance.

sub parseLogLine {
$line = $_;

%searchInfo = ();
@searchInfo = split / +/, $line;

# found any listings?
$numListings = $searchInfo[8];
$numCategories = $searchInfo[10];

# did I detect any errors or exceptions
($err) = ( $line =~ / ERR (\w+) /i );

if ( $err ne "") {
$err =~ tr/A-Z/a-z/;
 if ($err eq "nlf") {
 $NLFerr++;
 }
 elsif ($err eq "cat") {
 $CATerr++;
 }
}


-Larry



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]