Re: Perl

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 <mhoward@xxxxxxxxxx>
Superior Insurance - Technical Services

-
: send the line "unsubscribe linux-admin" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Newbie]     [Audio]     [Hams]     [Kernel Newbies]     [Util Linux NG]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Device Drivers]     [Samba]     [Video 4 Linux]     [Git]     [Fedora Users]

  Powered by Linux