Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2018-05-23 13:37 GMT
Find Nodes?
    Voting Booth?