Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Difference in retrieving values from a varchar2 column and number column from DB

by Arun Kumar (Novice)
on Dec 03, 2013 at 13:01 UTC ( #1065407=perlquestion: print w/ replies, xml ) Need Help??
Arun Kumar has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

I have a perl script which queries a DB table and retrieves values and then uses it in some manipulation. Initially, the datatype of the particular columns were NUMBER. But for some reasons, I have changed it to VARCHAR2. Now the problem is my code stucks at a point where I try to create object for a package using the values retrieved using the SQL query.

Perl script statement where my code stucks

push @ipElement,(new MyPackage::NetAddr::IP::($row_ip->{IP}, '255.255.255.255'));

The NEW sub routine in the called package

sub new ($$;$) { my $invocant = shift; my $type = ref($invocant) || $invocant || __PACKAGE__; my $obj = bless({}, $type); my @args = (ref($invocant)) ? $invocant->cidr() : @_; return $obj->SUPER::new(@args); }

Any help would be highly appreciated

Comment on Difference in retrieving values from a varchar2 column and number column from DB
Select or Download Code
Re: Difference in retrieving values from a varchar2 column and number column from DB
by hdb (Prior) on Dec 03, 2013 at 13:16 UTC

    What is your error message? What happens if you remove the two colons between IP and ($row_ip->{IP}, '255.255.255.255')? What is the name of your package?

      Thanks for the quick reply

      I am not getting any error message. I am running the script through cron job which simply hangs after 5 to 10 seconds and at that time the CPU usage goes to 99.9 for this process.

      I tried removing the double colon in between IP and $row_ip->{IP}, but ended with same issue

        What I would try:

        Run the script from the command line.

        Run a simple script like this:

        my $obj = new MyPackage::NetAddr::IP('10.10.10.10', '255.255.255.255') +;

        with an IP address from your sample.

        Add a print statement to the sub new and re-run the simple script.

Re: Difference in retrieving values from a varchar2 column and number column from DB
by Anonymous Monk on Dec 03, 2013 at 13:17 UTC

    (I cannot comment on the stuck-ness as it is not obvious to me yet. Perhaps list the exact error message that is produced?.)

    But look at that: prototype specified for supposedly a method; calling with indirect method call; and then the last colon-colon -- what the hell does that do?!

      Do you mean the :: in return $obj->SUPER::new(@args);? SUPER calls the base class method of the object. For example:

      use strict; use warnings; package Base; sub method { my ($self) = @_; my $class = ref $self; print "In Base::method(). I'm a $class instance.\n"; } package Derived; push @Derived::ISA, 'Base'; sub new { my ($class) = @_; return bless {}, $class; } sub method { my ($self) = @_; print "In Derived::method()\n"; $self->SUPER::method(); } package main; my $obj = Derived->new(); $obj->method();

      Prints:

      In Derived::method() In Base::method(). I'm a Derived instance
      True laziness is hard work

        I am sorry for making you write an example as I referred to "the last colon-colon" in the push statement ...

        push @ipElement,(new MyPackage::NetAddr::IP::($row_ip->{IP}, '255.255. +255.255')); ...

        No, the

        ::

        in

        return $obj->SUPER::new(@args);

        returns the base class method of the containing class/package.

Re: Difference in retrieving values from a varchar2 column and number column from DB
by moritz (Cardinal) on Dec 03, 2013 at 13:57 UTC

    I doubt that the code you have shown us hangs. It doesn't use any loop constructs, recursion or IO, which are typically where hangs appear. Also the code you have shown us doesn't have anything to do with the title of your post, or with retrieving anything for a database.

    Please show the code that actually hangs, and tell us where it hangs (you can find out by inserting print statements).

      Actually the script which I am using is very big(nearly 700 lines) to paste. This line comes under multiple while loop and else if statements. I found that this particular statement is producing the issue by giving multiple print statements through the script.

      This was working fine when the column's datatype was NUMBER. When I changed it to VARCHAR2 the script hangs. This is the reason why I named this thread with this title.

Re: Difference in retrieving values from a varchar2 column and number column from DB
by Jenda (Abbot) on Dec 03, 2013 at 18:43 UTC

    What happened to the art of debugging? Is it dead? Not taught? Not described in books? Ignored?

    So you've got a 700 lines script using god only knows how long modules connecting to a database started by cron. So what? Start it directly. Add some debug prints. Trim it down. Do something!

    You can't expect us to spoonfeed you a fix in code we haven't seen, in a script we can't run.

    Jenda
    Enoch was right!
    Enjoy the last years of Rome.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1065407]
Approved by hdb
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2014-12-27 15:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (177 votes), past polls