Sponsored Content
Full Discussion: while loop in perl script
Top Forums Shell Programming and Scripting while loop in perl script Post 302415570 by rajdeep_paul on Friday 23rd of April 2010 12:53:08 AM
Old 04-23-2010
Problem with Loop

Use "ne" instead of "!=" in the condition. "!=" works out only for numbers.

Code:
 
#!/usr/bin/perl
 
$exp = "y";
 
while ($exp ne "n") { 
 
system "clear"; # clear the window 
 
print "\nEnter the number of Widgets ordered: "; 
$widgetcount = <STDIN>; #vairable to save the number of total widgerts ordered 
chop $widgetcount; 
 
print "\nEnter the number of Gidgets ordered: "; 
$gidgetcount = <STDIN>; #vairable to save total number of gidget ordered 
chop $gidgetcount; 
 
print "\nEnter the number of Gadgets ordered: "; 
$gadgetcount = <STDIN>; #variablet to save total number of gadget ordered 
chop $gadgetcount; 
 
print "\nEnter the number of Doodats ordered: "; 
$doodatcount = <STDIN>; #vatiable to save total number of doodats ordered 
chop $doodatcount; 
 
$widgetsub = $widgetcount * 10.25; #subtotal of widgets 
$widgetsub = sprintf("%0.2f", $widgetsub); #setprecesion two decimal places 
print ("\nThe total number of Widgets ordered is: $widgetcount"); 
print ("\nThe total value of Widgets ordered is \$$widgetsub\n"); 
 
$gidgetsub = $gidgetcount * 5.75; #subtotal of gidgets 
$gidgetsub = sprintf("%0.2f", $gidgetsub); #setprecesion two decimal places 
print ("\nThe total number of Gidgets ordered is: $gidgetcount"); 
print ("\nThe total value of Gidgets ordered is \$$gidgetsub\n"); 
 
$gadgetsub = $gadgetcount * 11.33; #subtoal of gadgets 
$gadgetsub = sprintf("%0.2f",$gadgetsub); #setprecesion two decimal places 
print ("\nThe total number of Gadgets ordered is: $gadgetcount"); 
print ("\nThe total value of Gadgets ordered is \$$gadgetsub\n"); 
 
$doodatsub = $doodatcount * 44.75; #subtotal of doodats 
$doodatsub =sprintf("%0.2f",$doodatsub); #setprecesion two decimal places 
print ("\nThe total number of doodats ordered is: $doodatcount"); 
print ("\nThe total value of doodats ordered is \$$doodatsub\n"); 
 
#total of all subtotals without taxes and shipping charges 
$total=($widgetsub + $gidgetsub + $gadgetsub + $doodatsub);
$total = sprintf("%0.2f", $total); 
print ("\nTotal of all products subtotal is \$$total "); 
 
$tax = $total*.10; #total tax on total amount 
$tax =sprintf("%0.2f", $tax); 
print ("\nThe total of all products tax is \$$tax"); 
 
$shipping = $total*.085; #total shipping charges 
$shipping = sprintf("%0.2f", $shipping); 
print ("\nThe total of all products shipping charges is \$$shipping"); 
 
$grandtotal = $total + $tax + $shipping; #grandtotal 
$grandtotal = sprintf("%0.2f", $grandtotal); 
print("\nThe grandtotal is \$$grandtotal \n"); 
 
print "Do you want to Continue(y/n): "; 
$exp = <STDIN>;
chop $exp; 
$exp = lc($exp);
 
}

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

help with perl while loop

Can anyone tell me why this program won't kick out when the time gets beyond time in the loop? sub showtime { local($format,$military)=@_; ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time); if ((! $military) &amp;&amp; ($hour &gt; 12)) {$hour-=12;} ... (2 Replies)
Discussion started by: methos
2 Replies

2. Shell Programming and Scripting

Creating loop for a script -Perl

Hi Guyz I designed a script that can compare 2 columns(values) of single file and gives the closest numbers to the first column by comparing the numbers in first column with second and it works in a single file. Now I'm trying to design a new script with 2 objectives for 2 files (not a single... (4 Replies)
Discussion started by: repinementer
4 Replies

3. UNIX for Dummies Questions & Answers

Foreach loop to run a perl script on multiple files

Hi, I have thousands of files in a directory that have the following 2 formats: 289620178.aln 289620179.aln 289620180.aln 289620183.aln 289620184.aln 289620185.aln 289620186.aln 289620187.aln 289620188.aln 289620189.aln 289620190.aln 289620192.aln.... and: alnCDS_1.fasta (1 Reply)
Discussion started by: greptastic
1 Replies

4. Shell Programming and Scripting

Perl - pass shell-vars into perl for input loop

I need to process a file line-by-line using some value from a shell variable Something like:perl -p -e 's/$shell_srch/$shell_replace/g' input.txt I can't make the '-s' work in the '-p' or '-n' input loop (or couldn't find a syntaxis.) I have searched and found... (4 Replies)
Discussion started by: alex_5161
4 Replies

5. Shell Programming and Scripting

until loop Perl

I am trying to print out a section of a file begining at the start and printng until a character is found. My code and input file are below. This code is printing out every line except for the line with the character which is not what I want the out put should be a file with numbers 1-4. ... (3 Replies)
Discussion started by: cold_Que
3 Replies

6. Shell Programming and Scripting

Need help with perl script with a while loop reading file

Good morning, I appreciate any assistance that I can get from the monks out there. I am able to get this to work for me so that I can do a hostname lookup if I only specify one hostname in the script. What I want to do is have a file with hostnames and do lookups for each name in the file. Here is... (1 Reply)
Discussion started by: brianjb
1 Replies

7. Shell Programming and Scripting

Calling an interactive perl script from within a while-read loop

Hi, I have a perl script that prompts for a user to enter a password before doing what it does. This works well if I call it directly from a bash script #!/bin/bash /path/to/perl/script $arg1 $arg2 But, when I try to enclose this within a while read loop, the perl script is called but... (1 Reply)
Discussion started by: prafulnama
1 Replies

8. Shell Programming and Scripting

Perl loop until

I have a script that needs to wait on another script to finish. I created a sub routine to check the file for the number 0 but my until statement keeps on going. I tried eq, == and =~ but same thing. my $CHECKING_FILE = 1; do { sleep(5); $CHECKING_FILE = check_file(); ... (2 Replies)
Discussion started by: numele
2 Replies

9. Shell Programming and Scripting

PERL script loop problem

I have written the below PERL script to reprocess messages from a failure queue. It basically browses all the messages in the failure queue to individual files in a directory and then scans those files to determine the originating queue. The script will then move each message in turn from the... (0 Replies)
Discussion started by: chris01010
0 Replies

10. Programming

PERL: In a perl-scripttTrying to execute another perl-script that SETS SOME VARIABLES !

I have reviewed many examples on-line about running another process (either PERL or shell command or a program), but do not find any usefull for my needs way. (Reviewed and not useful the system(), 'back ticks', exec() and open()) I would like to run another PERL-script from first one, not... (1 Reply)
Discussion started by: alex_5161
1 Replies
size(1) 							   User Commands							   size(1)

NAME
size - print section sizes in bytes of object files SYNOPSIS
size [-f] [-F] [-n] [-o] [-V] [-x] filename... DESCRIPTION
The size command produces segment or section size information in bytes for each loaded section in ELF object files. size prints out the size of the text, data, and bss (uninitialized data) segments (or sections) and their total. size processes ELF object files entered on the command line. If an archive file is input to the size command, the information for each object file in the archive is displayed. When calculating segment information, the size command prints out the total file size of the non-writable segments, the total file size of the writable segments, and the total memory size of the writable segments minus the total file size of the writable segments. If it cannot calculate segment information, size calculates section information. When calculating section information, it prints out the total size of sections that are allocatable, non-writable, and not NOBITS, the total size of the sections that are allocatable, writable, and not NOBITS, and the total size of the writable sections of type NOBITS. NOBITS sections do not actually take up space in the filename. If size cannot calculate either segment or section information, it prints an error message and stops processing the file. OPTIONS
The following options are supported: -f Prints out the size of each allocatable section, the name of the section, and the total of the section sizes. If there is no sec- tion data, size prints out an error message and stops processing the file. -F Prints out the size of each loadable segment, the permission flags of the segment, then the total of the loadable segment sizes. If there is no segment data, size prints an error message and stops processing the file. -n Prints out non-loadable segment or non-allocatable section sizes. If segment data exists, size prints out the memory size of each loadable segment or file size of each non-loadable segment, the permission flags, and the total size of the segments. If there is no segment data, size prints out, for each allocatable and non-allocatable section, the memory size, the section name, and the total size of the sections. If there is no segment or section data, size prints an error message and stops processing. -o Prints numbers in octal, not decimal. -V Prints the version information for the size command on the standard error output. -x Prints numbers in hexadecimal, not decimal. EXAMPLES
The examples below are typical size output. Example 1: Producing size information example% size filename 2724 + 88 + 0 = 2812 Example 2: Producing allocatable section size information example% size -f filename 26(.text) + 5(.init) + 5(.fini) = 36 Example 3: Producing loadable segment size information example% size -F filename 2724(r-x) + 88(rwx) + 0(rwx) = 2812 ... (If statically linked) ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWbtool | +-----------------------------+-----------------------------+ SEE ALSO
as(1), cc(1B), ld(1), ar.h(3HEAD), a.out(4), attributes(5) NOTES
Since the size of bss sections is not known until link-edit time, the size command will not give the true total size of pre-linked objects. SunOS 5.10 16 Oct 1996 size(1)
All times are GMT -4. The time now is 07:54 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy