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

runtime problem

by jonagondos (Novice)
on Nov 14, 2012 at 17:13 UTC ( #1003864=perlquestion: print w/ replies, xml ) Need Help??
jonagondos has asked for the wisdom of the Perl Monks concerning the following question:

why doesn't this piece code run correctly at runtime i probably dont understand the small arrow ->? compile error during runtime is Scalar::Util::looks_like_number(sv) at test.pl line 16, <STDIN> line 1.

if ($numeral = Scalar::Util->looks_like_number($user_radius)) {
full code
#!/usr/bin/perl use warnings; use Scalar::Util; $radius_times = 2; $radius_times_2 = 3.141592654; $radius_times_2 *= $radius_times; while (1) { print "enter the radius\n"; $user_radius = <STDIN>; chomp($user_radius); if (my $numeral = Scalar::Util->looks_like_number($user_radius)) { $user_radius *= $radius_times_2; print "circumference is equal to $user_radius\n"; } else { print "no user input\n"; } }

Comment on runtime problem
Select or Download Code
Re: runtime problem
by toolic (Chancellor) on Nov 14, 2012 at 17:27 UTC
    Use :: instead of ->
    if (my $numeral = Scalar::Util::looks_like_number($user_radius)) {

    Scalar::Util does not have an object-oriented interface.

    Similarly, you can also import the sub:

    use Scalar::Util qw(looks_like_number); ... if (my $numeral = looks_like_number($user_radius)) {
Re: runtime problem
by tobyink (Abbot) on Nov 14, 2012 at 18:36 UTC

    toolic is correct. This is cool though...

    sub FakeOO { eval "require $_[0]"; bless \($_[0]), "FakeOO"; } sub FakeOO::AUTOLOAD { my $pkg = ${+shift}; $pkg->can($FakeOO::AUTOLOAD =~ /::(\w+)$/)->(@_); } my $scalar_util = FakeOO("Scalar::Util"); $scalar_util->looks_like_number(123);
    perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
      thanks guys
      Yes, pretty cool.

      And it also pretty much sums up why Perl is so loved and hated by so many people. You can do any insane, ill-advised thing you want :)



      When's the last time you used duct tape on a duct? --Larry Wall

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1003864]
Approved by toolic
Front-paged by 2teez
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (16)
As of 2014-08-29 16:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (282 votes), past polls