Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Script Needed Urgent

Posted on 2011-03-06
5
Medium Priority
?
441 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
  • 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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

927 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