Solved

Script Needed Urgent

Posted on 2011-03-06
5
418 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 500 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…

749 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