Beefy Boxes and Bandwidth Generously Provided by pair Networks httptech
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Can't get GCD to work in Bit::Vector module

by tperdue (Sexton)
on Jun 18, 2004 at 10:33 UTC ( [id://367958]=perlquestion: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.

tperdue has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to obtain the GCD from 2 codewords using the GCD function in the Bit::Vector module. I have assigned 2 vectors as follows:
$veca = Bit::Vector->new_Bin(64, $a); $vecb = Bit::Vector->new_Bin(64, $b);
$a and $b are both 64 bit codewords I entered as binary.

When printed $veca is Bit::Vector=SCALAR(0x224ef0)
and $vecb is Bit::Vector=SCALAR(0x224fa4).

I try to get the GCD by using the following code: $vecgcd->GCD($veca,$vecb);

I get the error:
'Can't call method on and undefined value at C:\test.pl line 27'. Any ideas as to why this won't work.

Edited by Chady -- some formatting and code tags.

Replies are listed 'Best First'.
Re: Can't get GCD to work in Bit::Vector module
by antirice (Priest) on Jun 18, 2004 at 10:57 UTC

    You should probably define $vecgcd. The following works:

    use Bit::Vector; my $veca = Bit::Vector->new_Bin(5,"00101"); # 5 my $vecb = Bit::Vector->new_Bin(5,"01010"); # 10 my $vecgcd = Bit::Vector->new(5); $vecgcd->GCD($veca,$vecb); # should be 5 print $vecgcd->to_Bin(); __END__ 00101

    Hope this helps.

    antirice    
    The first rule of Perl club is - use Perl
    The
    ith rule of Perl club is - follow rule i - 1 for i > 1

      Worked perfectly. Thanks for the help.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://367958]
Approved by Thelonius
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.