Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Hi Monks, I'm a total newbie to perl, please be gentle on me. :-) (I'm reading Learning Perl at the moment.) I'm trying to fill an array with numeric data to use in my program, but 'warnings' say:
Argument "42 32 22" isn't numeric in multiplication (*) at ./multigear +.pl line 19, <STDIN> line 3. Argument "11 13 15 17 19 21" isn't numeric in division (/) at ./multig +ear.pl line 19, <STDIN> line 3. Use of uninitialized value in division (/) at ./multigear.pl line 20, +<STDIN> line 3. Illegal division by zero at ./multigear.pl line 20, <STDIN> line 3.
Below is my program, (which I will try to build & use nested loops in, when I can get it functioning).
#!/usr/bin/perl use strict; use warnings; print "\nMulti Gear Calculator\n\n"; print "Enter Wheelsize (inches): "; my $wheel = <STDIN>; #my $wheel = 26.5; chomp$wheel; print "Enter Chainwheel Teeth: "; my @chwhs = (<STDIN>); ###my $line; ###while($line = <STDIN>) { chomp $line; last unless $line =~ /\d/; pu +sh @chwhs, $line } #my @chwhs = qw (42 32 22); chomp@chwhs; print "Enter Cog Teeth: "; my @cogs = (<STDIN>); #my @cogs = qw (11 13 15 17 19 21 24 28 32); chomp@cogs; my $gear1 = $wheel*$chwhs[0]/$cogs[0]; my $gear2 = $wheel*$chwhs[0]/$cogs[1]; my $gear3 = $wheel*$chwhs[0]/$cogs[2]; my $gear4 = $wheel*$chwhs[0]/$cogs[3]; my $gear5 = $wheel*$chwhs[0]/$cogs[4]; my $gear6 = $wheel*$chwhs[0]/$cogs[5]; my $gear7 = $wheel*$chwhs[0]/$cogs[6]; my $gear8 = $wheel*$chwhs[0]/$cogs[7]; my $gear9 = $wheel*$chwhs[0]/$cogs[8]; my $gear10 = $wheel*$chwhs[1]/$cogs[0]; my $gear11 = $wheel*$chwhs[1]/$cogs[1]; my $gear12 = $wheel*$chwhs[1]/$cogs[2]; my $gear13 = $wheel*$chwhs[1]/$cogs[3]; my $gear14 = $wheel*$chwhs[1]/$cogs[4]; my $gear15 = $wheel*$chwhs[1]/$cogs[5]; my $gear16 = $wheel*$chwhs[1]/$cogs[6]; my $gear17 = $wheel*$chwhs[1]/$cogs[7]; my $gear18 = $wheel*$chwhs[1]/$cogs[8]; my $gear19 = $wheel*$chwhs[2]/$cogs[0]; my $gear20 = $wheel*$chwhs[2]/$cogs[1]; my $gear21 = $wheel*$chwhs[2]/$cogs[2]; my $gear22 = $wheel*$chwhs[2]/$cogs[3]; my $gear23 = $wheel*$chwhs[2]/$cogs[4]; my $gear24 = $wheel*$chwhs[2]/$cogs[5]; my $gear25 = $wheel*$chwhs[2]/$cogs[6]; my $gear26 = $wheel*$chwhs[2]/$cogs[7]; my $gear27 = $wheel*$chwhs[2]/$cogs[8]; my @gear1 = ($gear1, $gear2, $gear3, $gear4, $gear5, $gear6, $gear7, $ +gear8, $gear9); my @gear2 = ($gear10, $gear11, $gear12, $gear13, $gear14, $gear15, $ge +ar16, $gear17, $gear18); my @gear3 = ($gear19, $gear20, $gear21, $gear22, $gear23, $gear24, $ge +ar25, $gear26, $gear27); print "\nYour gears are:\n\n"; print "\nYour gears are:\n\n"; print "Wheelsize: $wheel\n"; print "Chainwheels: @chwhs\n"; print "Sprockets: @cogs\n\n"; print "@gear1\n\n"; print "@gear2\n\n"; print "@gear3\n\n";
This program should calculate cycle gear ratios from input entered from the keyboard. I have tried different ways to get the data, to no avail. Using data coded into the program, everything works fine. Can someone please point out my mistake(s).

In reply to I'm trying to get a numeric array by fatmac

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2024-04-23 07:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found