Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Script Needed Urgent

Posted on 2011-03-06
5
Medium Priority
?
438 Views
Last Modified: 2012-05-11
simple script in a scripting language  that prints the numbers from 1 to 100. But for multiples of three print "Site" instead of the number and for the multiples of five print "Host". For numbers which are multiples of both three and five print "SiteHost".
0
Comment
Question by:Reddy4U-Solaris
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 16

Accepted Solution

by:
sjklein42 earned 2000 total points
ID: 35053406
for ($n=1; $n <= 100; $n++)
{
    if ( ( $n % 15 ) == 0 ) { print "SiteHost\n"; }
    elsif (( $n % 3 ) == 0 )  { print "Site\n"; }
    elsif (( $n % 5 ) == 0 )  { print "Host\n"; }
    else { print "$n\n"; }
}

Open in new window



c:\temp>perl foo.pl
1
2
Site
4
Host
Site
7
8
Site
Host
11
Site
13
14
SiteHost
16
17
Site
19
Host
Site
22
23
Site
Host
26
Site
28
29
SiteHost
31
32
Site
34
Host
Site
37
38
Site
Host
41
Site
43
44
SiteHost
46
47
Site
49
Host
Site
52
53
Site
Host
56
Site
58
59
SiteHost
61
62
Site
64
Host
Site
67
68
Site
Host
71
Site
73
74
SiteHost
76
77
Site
79
Host
Site
82
83
Site
Host
86
Site
88
89
SiteHost
91
92
Site
94
Host
Site
97
98
Site
Host

Open in new window

0
 

Author Comment

by:Reddy4U-Solaris
ID: 35053413
thanks thats usefull can u tell me which scripting u r using
0
 

Author Closing Comment

by:Reddy4U-Solaris
ID: 35053414
Excellent Response
0
 
LVL 16

Expert Comment

by:sjklein42
ID: 35053421
That's PERL.

Thanks.
0
 
LVL 48

Expert Comment

by:Tintin
ID: 35054997
bash version is virtually the same

#!/bin/bash
for i in $(seq 1 100)
do
  if [ $(($i%15)) -eq 0 ]
  then
     echo SiteHost
  elif [ $(($i%3)) -eq 0 ]
  then
     echo Site
  elif [ $(($i%5)) -eq 0 ]
  then
     echo Host
  else
     echo $i
  fi

don

Open in new window

e
0

Featured Post

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question