[27819] in Perl-Users-Digest
Perl-Users Digest, Issue: 9183 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Apr 20 21:05:36 2006
Date: Thu, 20 Apr 2006 18:05:05 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 20 Apr 2006 Volume: 10 Number: 9183
Today's topics:
[OT] (was: Re: How to find uploaded data size from cont <rvtol+news@isolution.nl>
[OT] C interpreter (was: Re: How to find uploaded data <rvtol+news@isolution.nl>
Re: clpmisc posting guidelines question <brian.d.foy@gmail.com>
Re: How to find uploaded data size from content-length <jgibson@mail.arc.nasa.gov>
Re: show hidden value in variable.. with mysql.. FIXED joe.henderson1@
Re: show hidden value in variable.. with mysql.. FIXED <someone@example.com>
Re: show hidden value in variable.. with mysql joe.henderson1@
Re: show hidden value in variable.. with mysql <1usa@llenroc.ude.invalid>
Re: show hidden value in variable.. with mysql joe.henderson1@
Re: show hidden value in variable.. with mysql joe.henderson1@
Re: Term::ReadKey on Win? 5.005 vs 5.8.8? <rvtol+news@isolution.nl>
Re: Term::ReadKey on Win? 5.005 vs 5.8.8? <sisyphus1@nomail.afraid.org>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 21 Apr 2006 01:03:39 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: [OT] (was: Re: How to find uploaded data size from content-length)
Message-Id: <e29b73.1b4.1@news.isolution.nl>
Asterbing schreef:
> DBraughler:
>> Asterbing:
>>> [attribution repaired] xhoster:
>>> [quoted text muted]
>>>>
>>>> That should probaby be changed. It does not immediately exit with
>>>> an error message. It first reads (and discards) the entire
>>>> contents of the POST, which apparently the OP doesn't want to
>>>> happen
>>
>> It would make sense to me to send an error message, close the
>> connection, and exit. Otherwise, a DoS attack indeed keeps streaming
>> bits to the server.
>>
>
> I didn't write this. You quote 'Asterbing' but it wasn't written by
> Asterbing in the referenced post.
Do you mean the "[quoted text muted]"? I guess that's put there by a
bot.
Text between "[]" is commonly a witty summary of what the poster chose
to read in what a previous poster wrote.
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: Fri, 21 Apr 2006 01:42:25 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: [OT] C interpreter (was: Re: How to find uploaded data size from content-length)
Message-Id: <e29dhs.1fk.1@news.isolution.nl>
Asterbing schreef:
> C is not an interpreted language !
I don't see why not. It is also a great language for writing scripts in:
http://www.tinycc.org
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: Thu, 20 Apr 2006 16:33:33 -0500
From: brian d foy <brian.d.foy@gmail.com>
Subject: Re: clpmisc posting guidelines question
Message-Id: <200420061633334991%brian.d.foy@gmail.com>
In article <e25vjr$6kv$1@ctb-nnrp2.saix.net>, Nico Coetzee
<blabla@yourguess.com> wrote:
> Recently ("autoincrement hex numbers" thread) an argument was started
> between what to use first as a solution to a problem: a Perl built-in or
> a CPAN module.
>
> Yet, in FAQ 4.45 (as an example, because it was posted recently) a
Please include question titles since the FAQ re-organizations every so
often. :)
> simple solution is provided by using the CPAN module first, then
> explaining how to do it in "pure" Perl.
>
> Now I am curious... What do we actually use first when giving advice?
You use whatever makes sense for the situation. There is no rule.
In the case of "How do I find the first array element for which a
condition is true?", the first() function from List::Util is more
efficient, takes up less space on the screen, and more clearly
communicates the intent of the code.
That might not be true in other cases though. As always, you have to
think, apply your experience, and come up with the answer that fits the
question. :)
*** Posted via a free Usenet account from http://www.teranews.com ***
------------------------------
Date: Thu, 20 Apr 2006 16:50:29 -0700
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: How to find uploaded data size from content-length
Message-Id: <200420061650292428%jgibson@mail.arc.nasa.gov>
In article <MPG.1eb216a46f4215d4989811@news.tiscali.fr>, Asterbing
<no@thanks.com> wrote:
> In article <dkjkh3xvqa.ln2@goaway.wombat.san-francisco.ca.us>, kkeller-
> usenet@wombat.san-francisco.ca.us says...
> > Copying isn't stealing if you're allowed to do it. Just don't
> > redistribute your program without also distributing the source.
> >
>
> Don't know if the author(s) of CGI.pm allow this. However, about Perl,
> source is always visible, by design.
If you read the documentation that the author of the CGI module
included with its distribution, you will find:
AUTHOR INFORMATION
Copyright 1995-1998, Lincoln D. Stein. All rights reserved.
This library is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
------------------------------
Date: Thu, 20 Apr 2006 22:53:21 GMT
From: joe.henderson1@
Subject: Re: show hidden value in variable.. with mysql.. FIXED
Message-Id: <oc3g42dkuohmut4gtpfq5hns9j045scr5l@4ax.com>
On Wed, 19 Apr 2006 22:11:29 GMT, joe.henderson1@ wrote:
>All,
>
>I run a mysql db 5.0.11. With a table that contains a few columns
>defined as type "text" with indexes..
>
>I running this on a Arch Linux 0.7.1.. 2.6.15 custom.. perl 5.8.8
>
>I run some scripts to parse data from cisco/network devices using snmp
>and telnet/ssh..
>
>I retrieve the name, mac, serial, location, description, interfaces,
>etc..
>
>The problem I have is the names I recieve from the
>devices I run threw a "clean subroutine"..
>
>##########
>sub clean
> {
> my $debug = 0;
> my $item = $_[0];
> $item =~ s/^\s+//; #remove Leading whitespace
> $item =~ s/\s+$//; #remove trailing whitespace
> $item =~ s/\r/ /g; #remove those Damn ^M
> $item =~ s/\f/ /g; #remove those Damn ^M
> $item =~ s/\t/ /g; #remove those Damn ^M
> $item =~ s/\n/ /g; #remove those Damn ^M
> $item =~ s/\s+/ /g; #replace multiple spaces with one
> chomp($item); #remove newline character
> return $item;
> }
>##########
>
>And for some reason when I compare to different names
>
>From DB: $name = "00a45fde0032(sw1)"
>
>And the name I pulled from the device $name: "00a45fde0032(sw1)"
>and compare them for exact match
>
>##########
>if($name eq $mname)
> { print "MATCH ON NAME: \"$name\" MNAME: \"$mname\"\n"; }
>else
> { print "NO MATCH\n"; }
>##########
>
>Nothing happens.. No Match.
>
>
>However when I did a
>##########
>if($name == $mname)
> { print "MATCH ON NAME: \"$name\" MNAME: \"$mname\"\n"; }
>else
> { print "NO MATCH\n"; }
>##########
>
>I recieved an error stating "cannot equal on non numeric" which is
>what I expected.. However it showed a hidden character of
>"MNAME: "00a45fde0032(sw1)\o"
>
>What does the "\o" mean? I have never seen this before..
>
>In the variable their has to be hidden characters that I cannot see.
>
>I thought about converting the string to hex then back to see if
>any characters show up..
>
>Or "$item =~ s/[^ A-Za-z0-9\-\:\.\(\)\@]//g;"
>
>
>A note.. I use the "sub clean" for everthing I receive from my
>scripts.. And then insert/update/replace into the database..
>I don't know if the column type is causing this error or the
>devices that are returning the value.. Due to I cannot see the
>hidden values...
>
>If their is a better way of "cleaning" the variables please let me
>know..
>
>
>
>Joe
All,
Thanks for all your help.. I found out what the problem was...
Their was a hidden "null" in the variable.. hex code of "00"..
This is the sub I wrote that fixes hidden characters...
########################################################
# Sub caschex
#
# USAGE: Removes hidden strings in variables.. Addition to Clean
#
# v1.0.0 -> 2006-04-20
# Born
#
######
# my ($item) = cipdec(1, $ip); #1 = A->H, 2 = H->A ######
#
sub caschex
{
# 1 = ASCII TO HEX
# 2 = HEX TO ASCII
##########
$debug = 0;
##########
if($debug == 1) { print "---------------------------------- ENTERED
SUB: \"caschex\"\n"; }
my $opt = undef; my $item = undef; my $ret = undef; my $val = undef;
$opt = shift(@_);
$item = shift(@_);
if($debug == 1)
{
print "\n\n";
print "OPT: \"$opt\"\n";
print "ITEM: \"$item\"\n";
}
############################# OPT 1
if($opt == 1)
{
if($debug == 1) { print "CONVERT ASCII TO HEX\n"; }
$key = undef; $val = undef;
foreach $key (split//,$item)
{
if($debug == 1) { print "KEY: \"$key\"\n"; }
($key) = sprintf("%02lx", ord $key);
if($debug == 1) { print "HEX KEY: \"$key\"\n"; }
if($key eq "00")
{
if($debug == 1) { print "FOUND NULL IN ASCII VARIABLE...
REPLACE WITH SPACE\n"; }
$key = " ";
#NOTE: A SPACE IN HEX IS "20"
($key) = sprintf("%02lx", ord $key);
if($debug == 1) { print "HEX KEY: \"$key\"\n"; }
}
$val .= $key;
if($debug == 1) { print "VAL: \"$val\"\n"; }
}
if($debug == 1) { print "COMPLETE VAL: \"$val\"\n"; }
}
############################# EO OPT 1
############################# OPT 2
if($opt == 2)
{
if($debug == 1) { print "CONVERT HEX TO ASCII\n"; }
$key = undef; $val = undef;
foreach $key ($item =~ /[a-fA-F0-9]{2}/g)
{
if($debug == 1) { print "HEX KEY: \"$key\"\n"; }
if($key eq "00")
{
if($debug == 1) { print "FOUND NULL IN HEX.. REPLACE WITH
SPACE\n"; }
$key = 20;
if($debug == 1) { print "HEX KEY: \"$key\"\n"; }
}
($key) = chr(hex $key);
if($debug == 1) { print "ASC KEY: \"$key\"\n"; }
$val .= $key;
if($debug == 1) { print "VAL: \"$val\"\n"; }
}
if($debug == 1) { print "COMPLETE VAL: \"$val\"\n"; }
}
############################# EO OPT 2
$ret = $val;
if($debug == 1) { print "RET: \"$ret\"\n"; }
if($debug == 1) { print "---------------------------------- LEAVING
SUB: \"caschex\"\n"; }
$debug = 0;
return($ret);
}
#
#
############################################## EO SUB CASCHEX
I also editted my "clean" sub...
########################################################
# Sub clean
# USAGE: Removes leading and trailing whitespace
#
# HIS: v1.0.5 -> 2005-01-24
# Added to "joes_pm";
#
# HIS: v1.0.6 -> 2005-07-28
# Added to "chomp";
# Added "s/\r/\n/g" for those damn ^Ms..
#
# HIS: v1.0.7 -> 2006-01-18
# Added "s/\s+/ /g" for replace multiple spaces with one
#
# HIS: v1.0.8 -> 2006-04-20
# Added "caschex" sub for removing hidden characters
#
# Usage: line below for results
######
# $line = &clean($line);
######
#
sub clean
{
my $debug = 0;
if($debug == 1) { print "ENTERED SUB \"CLEAN\"\n"; }
my $item = shift(@_);
if($debug == 1) { print "ITEM: \"$item\"\n"; }
$item =~ s/\r/ /g; #remove those Damn ^M
$item =~ s/\f/ /g; #remove those Damn ^M
$item =~ s/\t/ /g; #remove those Damn ^M
$item =~ s/\n/ /g; #remove those Damn ^M
$item = caschex(1, $item); #A->H
if($debug == 1) { print "HEX: \"$item\"\n"; }
$item = caschex(2, $item); #H->A
if($debug == 1) { print "ASCII: \"$item\"\n"; }
$item =~ s/^\s+//; #remove Leading whitespace
$item =~ s/\s+$//; #remove trailing whitespace
$item =~ s/\s+/ /g; #replace multiple spaces with one
chomp($item); #remove newline character
if($debug == 1) { print "RET: \"$item\"\n"; }
if($debug == 1) { print "LEAVING SUB \"CLEAN\"\n"; }
$debug = 0;
return $item;
}
################### EO SUB CLEAN ######################
It turns out the string Pulled from a cisco device from CDP (cdp name
from a snmp oid) has a hidden null character @ the end of the
string...
###
NOTE: The cisco devices I'm referring too are Menu/IOS/Cat based
from every model (around 200 different sysobject oids).
We had a problem with CiscoWorks getting us a complete inventory so I
wrote my own using Net::SNMP, Net::Telnet, DBI, Perl, Mysql 5.x,
Linux/Sun 2.9..
###
I did not see it until I converted it to hex and printed the output...
Their is where the devil was hiding..
When i reran all my scripts with the new subroutine it found hundreds
of instances where "null" characters where hidden in the variables..
Shame I didn't find out this problem until I went to remove duplicates
out of a few tables of mine and that is where I 1st noticed the
problem..
BTW.. In case someone wants to double check my work and has a stash of
cisco products on-hand they can use the following oids..
##########
my $cdpnintoid = ".1.3.6.1.4.1.9.9.23.1.2.1.1.3"; # CDP NEAR
INTERFACE OID
my $cdpfipoid = ".1.3.6.1.4.1.9.9.23.1.2.1.1.4"; # CDP FAR IP
ADD OID
my $cdpfsysdoid = ".1.3.6.1.4.1.9.9.23.1.2.1.1.5"; # CDP FAR
DESCRIPTION
my $cdpfsysnoid = ".1.3.6.1.4.1.9.9.23.1.2.1.1.6"; # CDP FAR
SYSN
my $cdpfintoid = ".1.3.6.1.4.1.9.9.23.1.2.1.1.7"; # CDP FAR
INT
my $cdpfsysmoid = ".1.3.6.1.4.1.9.9.23.1.2.1.1.8"; # CDP FAR
MODEL
##########
########## THe code for dumping the trees
if($debug == 1) { print "\n----- START CDPFSYSNOID\n"; }
$res = undef; $roid = undef;
if(defined($res = $sess->get_table(-baseoid => $cdpfsysnoid)))
{
foreach $roid (keys(%{$res}))
{
$key = undef; $val = undef;
if($debug == 1) { print "ROID: \"$roid\"\n"; }
$val = $res->{$roid};
$val = clean($val);
$val = lc($val);
#ROID: ".1.3.6.1.4.1.9.9.23.1.2.1.1.3.30.1"
@array = split(/\./, $roid);
$key .= "$array[$#array - 1].$array[$#array]";
if($debug == 1)
{
print "KEY: \"$key\"\n";
print "VAL: \"$val\"\n";
print "\n";
}
$key = clean($key);
$key = lc($key);
$key =~ s/\,//g;
$val = clean($val);
$val = lc($val);
$val =~ s/\,//g;
if($val =~ /\./)
{
$val = (split(/\./, $val))[0]; #GET ME THE EVERYTHING B4
THE 1ST PERIOD
}
if(exists $cdpfsysn{$key}) { print "KEY: \"$key\" EXISTS
IN HASH \"CDPFSYSN\".. NEXT\n"; next; }
else { $cdpfsysn{$key} = $val; }
if($debug == 1) { print "\n"; }
} #EO FE ROID
if($debug == 1) { print "--- START DUMP KEY/VAL\n";
$key = undef; $val = undef;
foreach $key (keys %cdpfsysn)
{ print "KEY: \"$key\"\nVAL: \"$cdpfsysn{$key}\"\n\n"; }
print "--- END DUMP KEY/VAL\n"; }
} #EO IF DEF CDPFSYSNOID
if($debug == 1) { print "----- DONE CDPFSYSNOID\n"; }
########## EO The code for dumping the trees
I don't know if the hidden null is vendor specific.. but you never
know....
Thanks again,
Joe
------------------------------
Date: Fri, 21 Apr 2006 01:02:53 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: show hidden value in variable.. with mysql.. FIXED
Message-Id: <1bW1g.213$8E1.2@clgrps13>
joe.henderson1@ wrote:
>
> All,
>
> Thanks for all your help.. I found out what the problem was...
>
> Their was a hidden "null" in the variable.. hex code of "00"..
That's what I thought, it was "\0" and not "\o". :-)
John
--
use Perl;
program
fulfillment
------------------------------
Date: Thu, 20 Apr 2006 22:20:11 GMT
From: joe.henderson1@
Subject: Re: show hidden value in variable.. with mysql
Message-Id: <452g421oogqqd2brtu9fc129jhhliuqrd2@4ax.com>
On Thu, 20 Apr 2006 01:55:47 GMT, "A. Sinan Unur"
<1usa@llenroc.ude.invalid> wrote:
>joe.henderson1@ wrote in news:afmd42po2t5kijm7psg2a4q9l7eaam2jtf@
>4ax.com:
>
>> On Thu, 20 Apr 2006 00:11:16 GMT, "A. Sinan Unur"
>> <1usa@llenroc.ude.invalid> wrote:
>>
>>>joe.henderson1@ wrote in news:gfcd429kaaot9ibb06l6ma1od1j5tf1q17@
>>>4ax.com:
>>>
>>>> sub clean
>>>> {
>>>> my $debug = 0;
>>>
>>>What does this line do?
>>
>> All the subs i write have a "magic" debug variable.. I spend more time
>> on debugging than writting code.. :(
>> When i turn this on I embed print statments with low level printouts..
>
>But that is tedious because you have to edit the body of each sub to
>turn debugging on.
Yes.. Believe it or not it has saved my A$$ more often than not.
>
>>>> my $item = $_[0];
>>>
>>>my ($item) = @_;
>>>
>>>would enable you to pass literal strings to this routine as well as
>>>variables.
>>
>> K. thanks.. Used a "$tem = shift;" but quit after some problem I don't
>> remember.. :(
>>
>> However How would you pass multiple Items..
>>
>> ex..
>> ########
>> like ($item) = clean($val1, $val2);
>>
>> sub clean
>> {
>> my $item1 = shift(@_);
>> my $item2 = shift(@_);
>
>my ($item1, $item2) = @_;
k.. I remember that
>
>Or, if you are applying the same transformation to an indefinite number
>of arguments:
>
>sub clean {
> my @args = @_;
> for ( @args ) {
> s/^\s+//;
> s/\s+$//;
> s/\s+/ /;
> }
> return @args;
>}
>
>>>use constant DEBUG => 1;
>>>
>>
>> I do not have experience with the debug command... Will use.. thanks
>> for the advise...
>
>There is no debug command. I am just proposing setting a global flag for
>debugging mode. You could have just as well called it CHEESE.
I figure that out today when I was testing it.. :p
>
>>>DEBUG and
>>> warn sprintf("\$name = '%s'\n\$mname = '%s'\n", $name, $mname);
>>
>> good idea
>
>Well, then, you might want
>
>>>sub hex_dump_string {
>>> my ($string) = @_;
>>> $string =~ s/(.)/sprintf '%2.2X', ord $1/ges;
>>> return $string;
>>>}
>>
>> Good stuff.. I'll read up on the "ord" "/ges"..
>>
>> don't know what that is... more advance regex..
>
>perldoc perlop
>
>Now, if you do post the contents of those variables, we might be able to
>help further.
Due to the nature of the content I cannot post exact variables... (no
further comment please..)
>
>Sinan
------------------------------
Date: Thu, 20 Apr 2006 22:27:32 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: show hidden value in variable.. with mysql
Message-Id: <Xns97ABBBC709E60asu1cornelledu@127.0.0.1>
joe.henderson1@ wrote in news:452g421oogqqd2brtu9fc129jhhliuqrd2@4ax.com:
> On Thu, 20 Apr 2006 01:55:47 GMT, "A. Sinan Unur"
> <1usa@llenroc.ude.invalid> wrote:
...
>>Now, if you do post the contents of those variables, we might be able to
>>help further.
>
> Due to the nature of the content I cannot post exact variables... (no
> further comment please..)
You can't expect to get help if you don't help those who are in a position
to help you.
Your wish is my command. I won't be seeing any more posts from you.
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
comp.lang.perl.misc guidelines on the WWW:
http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
Date: Thu, 20 Apr 2006 22:37:43 GMT
From: joe.henderson1@
Subject: Re: show hidden value in variable.. with mysql
Message-Id: <c63g42dkd13b800dibngmnk13duuaulqjq@4ax.com>
On Thu, 20 Apr 2006 00:26:09 -0400, Uri Guttman <uri@stemsystems.com>
wrote:
>>>>>> "jh" == joe henderson1 <joe.henderson1@> writes:
>
> jh> On Thu, 20 Apr 2006 00:11:16 GMT, "A. Sinan Unur"
> jh> <1usa@llenroc.ude.invalid> wrote:
>
> >> joe.henderson1@ wrote in news:gfcd429kaaot9ibb06l6ma1od1j5tf1q17@
> >> 4ax.com:
> >>
> >>> sub clean
> >>> {
> >>> my $debug = 0;
> >>
> >> What does this line do?
>
> jh> All the subs i write have a "magic" debug variable.. I spend more time
> jh> on debugging than writting code.. :(
>
>that is a bad sign. learn to analyze your problems better, improve your
>coding skills, etc. debugging should be maybe 20-40% maximum of your
>development time.
Statement Noted..
>
> jh> When i turn this on I embed print statments with low level printouts..
>
> jh> if($debug == 1) { print "Entered sub \"clean\"\n"; }
> jh> ... magic ...
> jh> if($debug == 1) { print "leaving sub returning: \"$ret\"\n"; }
>
>ewww. that is boring sub tracing. and slow in runtime.
Slow by the use of total compile? Or when the variable "debug" is set
to "1"... I know the printing to STDOUT slows the crunch time
>
> >> use constant DEBUG => 1;
> >>
>
> jh> I do not have experience with the debug command... Will use.. thanks
> jh> for the advise...
>
>
>that isn't a debug command. that just create a constant called DEBUG
> >>
> >> DEBUG and
> >> warn sprintf("\$name = '%s'\n\$mname = '%s'\n", $name, $mname);
>
> jh> good idea
>
>it also will run faster than your if you set DEBUG to 0
>
> >> to visually compare the strings during debugging.
> >>
> >>> However when I did a
> >>> ##########
> >>> if($name == $mname)
> >>> { print "MATCH ON NAME: \"$name\" MNAME: \"$mname\"\n"; }
>
>learn about alternate quote. but even better, why are you using ""
>inside a "" string? you can use '', [], <> or {} to demark the actual
>values. then you don't need those ugly backwhacks. i tend to use [] for
>this.
True.. Old habits bad to break.
>
>uri
------------------------------
Date: Thu, 20 Apr 2006 22:54:06 GMT
From: joe.henderson1@
Subject: Re: show hidden value in variable.. with mysql
Message-Id: <k74g42ls35e44l5co8tteh0l75kvulo25e@4ax.com>
On Wed, 19 Apr 2006 22:11:29 GMT, joe.henderson1@ wrote:
>All,
>
>I run a mysql db 5.0.11. With a table that contains a few columns
>defined as type "text" with indexes..
>
>I running this on a Arch Linux 0.7.1.. 2.6.15 custom.. perl 5.8.8
>
>I run some scripts to parse data from cisco/network devices using snmp
>and telnet/ssh..
>
>I retrieve the name, mac, serial, location, description, interfaces,
>etc..
>
>The problem I have is the names I recieve from the
>devices I run threw a "clean subroutine"..
>
>##########
>sub clean
> {
> my $debug = 0;
> my $item = $_[0];
> $item =~ s/^\s+//; #remove Leading whitespace
> $item =~ s/\s+$//; #remove trailing whitespace
> $item =~ s/\r/ /g; #remove those Damn ^M
> $item =~ s/\f/ /g; #remove those Damn ^M
> $item =~ s/\t/ /g; #remove those Damn ^M
> $item =~ s/\n/ /g; #remove those Damn ^M
> $item =~ s/\s+/ /g; #replace multiple spaces with one
> chomp($item); #remove newline character
> return $item;
> }
>##########
>
>And for some reason when I compare to different names
>
>From DB: $name = "00a45fde0032(sw1)"
>
>And the name I pulled from the device $name: "00a45fde0032(sw1)"
>and compare them for exact match
>
>##########
>if($name eq $mname)
> { print "MATCH ON NAME: \"$name\" MNAME: \"$mname\"\n"; }
>else
> { print "NO MATCH\n"; }
>##########
>
>Nothing happens.. No Match.
>
>
>However when I did a
>##########
>if($name == $mname)
> { print "MATCH ON NAME: \"$name\" MNAME: \"$mname\"\n"; }
>else
> { print "NO MATCH\n"; }
>##########
>
>I recieved an error stating "cannot equal on non numeric" which is
>what I expected.. However it showed a hidden character of
>"MNAME: "00a45fde0032(sw1)\o"
>
>What does the "\o" mean? I have never seen this before..
>
>In the variable their has to be hidden characters that I cannot see.
>
>I thought about converting the string to hex then back to see if
>any characters show up..
>
>Or "$item =~ s/[^ A-Za-z0-9\-\:\.\(\)\@]//g;"
>
>
>A note.. I use the "sub clean" for everthing I receive from my
>scripts.. And then insert/update/replace into the database..
>I don't know if the column type is causing this error or the
>devices that are returning the value.. Due to I cannot see the
>hidden values...
>
>If their is a better way of "cleaning" the variables please let me
>know..
>
>
>
>Joe
All,
Thanks for all your help.. I found out what the problem was...
Their was a hidden "null" in the variable.. hex code of "00"..
This is the sub I wrote that fixes hidden characters...
########################################################
# Sub caschex
#
# USAGE: Removes hidden strings in variables.. Addition to Clean
#
# v1.0.0 -> 2006-04-20
# Born
#
######
# my ($item) = cipdec(1, $ip); #1 = A->H, 2 = H->A ######
#
sub caschex
{
# 1 = ASCII TO HEX
# 2 = HEX TO ASCII
##########
$debug = 0;
##########
if($debug == 1) { print "---------------------------------- ENTERED
SUB: \"caschex\"\n"; }
my $opt = undef; my $item = undef; my $ret = undef; my $val = undef;
$opt = shift(@_);
$item = shift(@_);
if($debug == 1)
{
print "\n\n";
print "OPT: \"$opt\"\n";
print "ITEM: \"$item\"\n";
}
############################# OPT 1
if($opt == 1)
{
if($debug == 1) { print "CONVERT ASCII TO HEX\n"; }
$key = undef; $val = undef;
foreach $key (split//,$item)
{
if($debug == 1) { print "KEY: \"$key\"\n"; }
($key) = sprintf("%02lx", ord $key);
if($debug == 1) { print "HEX KEY: \"$key\"\n"; }
if($key eq "00")
{
if($debug == 1) { print "FOUND NULL IN ASCII VARIABLE...
REPLACE WITH SPACE\n"; }
$key = " ";
#NOTE: A SPACE IN HEX IS "20"
($key) = sprintf("%02lx", ord $key);
if($debug == 1) { print "HEX KEY: \"$key\"\n"; }
}
$val .= $key;
if($debug == 1) { print "VAL: \"$val\"\n"; }
}
if($debug == 1) { print "COMPLETE VAL: \"$val\"\n"; }
}
############################# EO OPT 1
############################# OPT 2
if($opt == 2)
{
if($debug == 1) { print "CONVERT HEX TO ASCII\n"; }
$key = undef; $val = undef;
foreach $key ($item =~ /[a-fA-F0-9]{2}/g)
{
if($debug == 1) { print "HEX KEY: \"$key\"\n"; }
if($key eq "00")
{
if($debug == 1) { print "FOUND NULL IN HEX.. REPLACE WITH
SPACE\n"; }
$key = 20;
if($debug == 1) { print "HEX KEY: \"$key\"\n"; }
}
($key) = chr(hex $key);
if($debug == 1) { print "ASC KEY: \"$key\"\n"; }
$val .= $key;
if($debug == 1) { print "VAL: \"$val\"\n"; }
}
if($debug == 1) { print "COMPLETE VAL: \"$val\"\n"; }
}
############################# EO OPT 2
$ret = $val;
if($debug == 1) { print "RET: \"$ret\"\n"; }
if($debug == 1) { print "---------------------------------- LEAVING
SUB: \"caschex\"\n"; }
$debug = 0;
return($ret);
}
#
#
############################################## EO SUB CASCHEX
I also editted my "clean" sub...
########################################################
# Sub clean
# USAGE: Removes leading and trailing whitespace
#
# HIS: v1.0.5 -> 2005-01-24
# Added to "joes_pm";
#
# HIS: v1.0.6 -> 2005-07-28
# Added to "chomp";
# Added "s/\r/\n/g" for those damn ^Ms..
#
# HIS: v1.0.7 -> 2006-01-18
# Added "s/\s+/ /g" for replace multiple spaces with one
#
# HIS: v1.0.8 -> 2006-04-20
# Added "caschex" sub for removing hidden characters
#
# Usage: line below for results
######
# $line = &clean($line);
######
#
sub clean
{
my $debug = 0;
if($debug == 1) { print "ENTERED SUB \"CLEAN\"\n"; }
my $item = shift(@_);
if($debug == 1) { print "ITEM: \"$item\"\n"; }
$item =~ s/\r/ /g; #remove those Damn ^M
$item =~ s/\f/ /g; #remove those Damn ^M
$item =~ s/\t/ /g; #remove those Damn ^M
$item =~ s/\n/ /g; #remove those Damn ^M
$item = caschex(1, $item); #A->H
if($debug == 1) { print "HEX: \"$item\"\n"; }
$item = caschex(2, $item); #H->A
if($debug == 1) { print "ASCII: \"$item\"\n"; }
$item =~ s/^\s+//; #remove Leading whitespace
$item =~ s/\s+$//; #remove trailing whitespace
$item =~ s/\s+/ /g; #replace multiple spaces with one
chomp($item); #remove newline character
if($debug == 1) { print "RET: \"$item\"\n"; }
if($debug == 1) { print "LEAVING SUB \"CLEAN\"\n"; }
$debug = 0;
return $item;
}
################### EO SUB CLEAN ######################
It turns out the string Pulled from a cisco device from CDP (cdp name
from a snmp oid) has a hidden null character @ the end of the
string...
###
NOTE: The cisco devices I'm referring too are Menu/IOS/Cat based
from every model (around 200 different sysobject oids).
We had a problem with CiscoWorks getting us a complete inventory so I
wrote my own using Net::SNMP, Net::Telnet, DBI, Perl, Mysql 5.x,
Linux/Sun 2.9..
###
I did not see it until I converted it to hex and printed the output...
Their is where the devil was hiding..
When i reran all my scripts with the new subroutine it found hundreds
of instances where "null" characters where hidden in the variables..
Shame I didn't find out this problem until I went to remove duplicates
out of a few tables of mine and that is where I 1st noticed the
problem..
BTW.. In case someone wants to double check my work and has a stash of
cisco products on-hand they can use the following oids..
##########
my $cdpnintoid = ".1.3.6.1.4.1.9.9.23.1.2.1.1.3"; # CDP NEAR
INTERFACE OID
my $cdpfipoid = ".1.3.6.1.4.1.9.9.23.1.2.1.1.4"; # CDP FAR IP
ADD OID
my $cdpfsysdoid = ".1.3.6.1.4.1.9.9.23.1.2.1.1.5"; # CDP FAR
DESCRIPTION
my $cdpfsysnoid = ".1.3.6.1.4.1.9.9.23.1.2.1.1.6"; # CDP FAR
SYSN
my $cdpfintoid = ".1.3.6.1.4.1.9.9.23.1.2.1.1.7"; # CDP FAR
INT
my $cdpfsysmoid = ".1.3.6.1.4.1.9.9.23.1.2.1.1.8"; # CDP FAR
MODEL
##########
########## THe code for dumping the trees
if($debug == 1) { print "\n----- START CDPFSYSNOID\n"; }
$res = undef; $roid = undef;
if(defined($res = $sess->get_table(-baseoid => $cdpfsysnoid)))
{
foreach $roid (keys(%{$res}))
{
$key = undef; $val = undef;
if($debug == 1) { print "ROID: \"$roid\"\n"; }
$val = $res->{$roid};
$val = clean($val);
$val = lc($val);
#ROID: ".1.3.6.1.4.1.9.9.23.1.2.1.1.3.30.1"
@array = split(/\./, $roid);
$key .= "$array[$#array - 1].$array[$#array]";
if($debug == 1)
{
print "KEY: \"$key\"\n";
print "VAL: \"$val\"\n";
print "\n";
}
$key = clean($key);
$key = lc($key);
$key =~ s/\,//g;
$val = clean($val);
$val = lc($val);
$val =~ s/\,//g;
if($val =~ /\./)
{
$val = (split(/\./, $val))[0]; #GET ME THE EVERYTHING B4
THE 1ST PERIOD
}
if(exists $cdpfsysn{$key}) { print "KEY: \"$key\" EXISTS
IN HASH \"CDPFSYSN\".. NEXT\n"; next; }
else { $cdpfsysn{$key} = $val; }
if($debug == 1) { print "\n"; }
} #EO FE ROID
if($debug == 1) { print "--- START DUMP KEY/VAL\n";
$key = undef; $val = undef;
foreach $key (keys %cdpfsysn)
{ print "KEY: \"$key\"\nVAL: \"$cdpfsysn{$key}\"\n\n"; }
print "--- END DUMP KEY/VAL\n"; }
} #EO IF DEF CDPFSYSNOID
if($debug == 1) { print "----- DONE CDPFSYSNOID\n"; }
########## EO The code for dumping the trees
I don't know if the hidden null is vendor specific.. but you never
know....
Thanks again,
Joe
------------------------------
Date: Fri, 21 Apr 2006 00:54:12 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: Term::ReadKey on Win? 5.005 vs 5.8.8?
Message-Id: <e29aj7.1ck.1@news.isolution.nl>
Ilya Zakharevich schreef:
> Now if could get a mental model of what kind of bug
> could cause this...
I read the code for a few minutes and then tested this:
C:\>perl -MTerm::ReadKey -wle "open $in, '+< CONIN$' or die $!;
ReadMode 4, $in;
$|=1;
print ord while defined($_=ReadKey 0)"
C:\>perl -MTerm::ReadKey -wle "open $in, '+< CONIN$' or die $!;
ReadMode 4, $in;
$|=1;
print ord while defined($_=ReadKey
'0E0')"
(perl, v5.8.8 built for MSWin32-x86-multi-thread)
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: Fri, 21 Apr 2006 09:15:12 +1000
From: "Sisyphus" <sisyphus1@nomail.afraid.org>
Subject: Re: Term::ReadKey on Win? 5.005 vs 5.8.8?
Message-Id: <444816be$0$29881$afc38c87@news.optusnet.com.au>
"Ilya Zakharevich" <nospam-abuse@ilyaz.org>
.
.
.
> Could you check the file name to
> which STDIN is connected? On OS/2 POSIX::ttyname() would work; do not
> know about Win*...
I don't know about Windows either. POSIX::ttyname() is not implemented.
>
> perl -wle "print ord getc while 1"
>
> and I do not see anything deserving attention in how you describe its
> effects. :-(
>
I thought it might be noteworthy that the ord() for the 'Enter' and 'Ctrl-M'
keys seemed to change from 13 to 10. No matter.
I *did* preface my post with 'fwiw' ...... with good reason, it seems :-)
Cheers,
Rob
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 9183
***************************************