Solved

Script Needed Urgent

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
collecting information 2 179
Question about @INC variable in perl 1 65
PHP equivalent of opening a com object 5 89
PERL variable conundrum 9 94
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 …
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…

808 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