From mboxrd@z Thu Jan 1 00:00:00 1970 From: Matt Howard Subject: Re: Perl Date: Mon, 19 Apr 2004 14:47:01 -0500 Sender: linux-admin-owner@vger.kernel.org Message-ID: References: <016b01c417ad$d246e8a0$020aa8c0@Scott> Mime-Version: 1.0 Content-Transfer-Encoding: 7Bit Return-path: List-Id: Content-Type: text/plain; charset="us-ascii" To: linux-admin@vger.kernel.org Scott@Charter wrote: > Can anyone please help me with a short example Perl script that will print > out all the odd numbers between 1 and 10? I don't know Perl and am trying > to learn it. I wrote a bash script to do the same thing and wanted to > compare it. > > There must be a Perl expert out there somewhere who can help me? > > Thanks- > Scott foreach ( 1 .. 10 ) { print "$_ " if ($_ % 2 == 1); } ".." is an operator that will return a list that is the range between left and right. foreach will run the code block for each item of the list, setting $_ to that item. print ... if does like it sounds, and % is the modulo operator, in other words, it returns the remainder if the % had been a /. I hope this helps you, and I apologize for the unkind responses you have received from the list here. If you have any perl questions, you may try http://www.perlmonks.org -- Matt Howard Superior Insurance - Technical Services