Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

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 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"; } }

Replies are listed 'Best First'.
Re: runtime problem
by toolic (Bishop) 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'
      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
      thanks guys

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1003864]
Approved by toolic
Front-paged by 2teez
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2018-05-25 17:25 GMT
Find Nodes?
    Voting Booth?