Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re^2: new to perl, need some help

by bimleshsharma (Beadle)
on Oct 02, 2012 at 12:05 UTC ( #996851=note: print w/replies, xml ) Need Help??

in reply to Re: new to perl, need some help
in thread new to perl, need some help

Here is issue with initialisation of array(@values = ();). It is reinitialising on every iteration of loop and ultimately storing last value. Use below hope that will fulfil your requirement

!#/usr/bin/perl use strict; use warnings; @number = qw(1 2 3 4 5 10 11 12 13 14); print "The values within the array are @number\n\n"; print "We will now print the square root of each number in the array a +s long as it falls between the range of 100-200 \n\n"; my @values = (); foreach $num (@number) { $sq = $num * $num; if ($sq >= 100 && $sq <= 200) { push(@values, $sq); } } print "Obtaining square values using foreach loop: @values\n";

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://996851]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (8)
As of 2016-10-28 19:18 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (386 votes). Check out past polls.