Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

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
[Corion]: Yay. Traditional finance situation averted. Bonds can be quoted in amounts (1_000_000 EUR) or per unit (1 unit). And a traditional error is to trade 2_000_000 piece when you meant to trade 2_000_000 EUR.
[Corion]: (one of my scripts simply catches high amounts and I phone people making that trade, ideally before the payment is due)
[Corion]: The sad thing is that my script sits at the end of the pipeline and can only look at the payments due today or tomorrow basically, while there are many more systems further up in the pipeline

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (13)
As of 2017-03-29 11:29 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (347 votes). Check out past polls.