Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

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


Comment on Re^2: new to perl, need some help
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2015-07-05 05:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (60 votes), past polls