473,473 Members | 2,008 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Perl Division Problem

1 New Member
I've been out of perl for a while, so I am starting from scratch. I have a small applet which scans a set of directories, getting information from some files in each one, and displaying selected data.

The script works good, but I need to set in some tabbing on the terminal, and that is where the problem comes in. as soon as I attempt a division, the applet blows up, and it is not a divide by 0 error.

I have tested the particular line of code with all arithmetic operators, and the code only refuses to compile when I use the division operator.

The error display is:

Bareword found where operator expected at ./ideaStatus line 51, near "case"
(Missing semicolon on previous line?)
Bareword found where operator expected at ./ideaStatus line 52, near "case"
(Missing semicolon on previous line?)
Bareword found where operator expected at ./ideaStatus line 53, near "case"
(Missing semicolon on previous line?)
syntax error at ./ideaStatus line 49, near ") {"
syntax error at ./ideaStatus line 51, near "/^"
syntax error at ./ideaStatus line 52, near "/^"
syntax error at ./ideaStatus line 53, near "/^"
syntax error at ./ideaStatus line 53, near "; }"
Execution of ./ideaStatus aborted due to compilation errors.

The code is:

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. use Switch;
  3. use integer;
  4.  
  5.  
  6. $baseDir = "~/Desktop/IdeaBin";
  7. $tablen = 8;
  8.  
  9. #-----------
  10. # list existing project ideas
  11.  
  12. print "locating existing project ideas from $baseDir\n";
  13. $listIdx = 0;
  14.  
  15. opendir(DIRHANDLE, $baseDir) || die "Cannot opendir $baseDir: $!";
  16. foreach $name (sort readdir(DIRHANDLE)) {
  17.     # --- make sure it is a directory
  18.     if (-d "$baseDir/$name") {
  19.         # --- and it's not the . .. dir links
  20.         if ( $name !~ /^\./ ) {
  21.             @Ideas[$listIdx]=$name;
  22.             $listIdx++;
  23.         }
  24.     }
  25. }
  26. closedir(DIRHANDLE);
  27.  
  28.  
  29. print "Code\t\tName\t\t\t\t\tDate\t\tStatus\n";
  30. # Cycle through our list
  31. for $i (@Ideas ) {
  32.     $file = $baseDir."/".$i."/$i.txt";
  33.  
  34.     open (LOGFILE, $file) or die "I couldn't open $file\n";
  35.  
  36.     $x = 0;
  37.     while ( $x == 0 ) {
  38.         $line = <LOGFILE> ;
  39.  
  40.         if ( $line =~ /^\n/ ) {
  41.             $x=1;
  42.  
  43.         } else {
  44.             @line = split(/:/, $line);
  45.             $y = (length $line[1]) - 2 ;
  46.  
  47.             $tbs = ((length $line[1])-((length $line[1])%8)) ;
  48.             # any attempt at division causes the program to bork on this line
  49.             # comment the line, and it all runs fine
  50.             # change to any other operand, and it runs fine
  51.             # out of ideas -- wtf!!!
  52.             $ts = int( $tbs / 8 ) ;
  53.  
  54.             switch ( $line[0] ) {
  55.                 case /^Status/ { print substr $line[1], 1, $y; print "\n"; }
  56.                 case /^Code/ { print substr $line[1], 1, $y; print "\t"; }
  57.                 case /^When/ { print substr $line[1], 1, $y; print "\t"; }
  58.                 case /^Name/ { print substr $line[1], 1, $y; print "\t"; }
  59.             }
  60.         }
  61.     }
  62.     close LOGFILE;
  63.  
  64.     # print "located $i\n";
  65. }
  66.  
if you need to create a test run, create a directory, with a file of the directory name.txt in it
eg : ~/Desktop/IdeaBin/TestDir/TestDir.txt

content template is:
;----------------
Code: Test
Name: Test Application
Who: Some Body
When: Jul 24, 2007
Status: Open

;----------------
Jul 24 '07 #1
1 3704
KevinADC
4,059 Recognized Expert Specialist
instead of :

Expand|Select|Wrap|Line Numbers
  1. $tbs = ((length $line[1])-((length $line[1])%8)) ;

try:

Expand|Select|Wrap|Line Numbers
  1. $tbs = length $line[1] - (length $line[1] %8 );
and report back.
Jul 26 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Xah Lee | last post by:
© # this is an example of for statement © # the % symbol calculates the remainder © # of division. © # the range(m,n) function © # gives a list from m to n-1. © © a = range(1,51) © for x in a:...
19
by: Imbaud Pierre | last post by:
integer division and modulo gives different results in c and python, when negative numbers are involved. take gdb as a widely available c interpreter print -2 /3 0 for c, -1 for python. more...
15
by: joel | last post by:
I have a table which I want to update by dividing one field into another. The update runs with no errors, but the results come out as only a positive integer number. The datatype for the result...
6
by: WipeOut | last post by:
I am having a problem in a perl script that I can't seem to find an answer for.. The $cost and $retail vars come from another part of the script and would be something like 000134.345 and...
17
by: seb.haase | last post by:
Hi, Is it true that that "Python 3000" is dead ? Honestly I think that e.g. changing 5/2 to be 2.5 (instead of 2) would just break to much code :-( On the otherhand I'm using Python as "Matlab...
22
by: jamestuck21 | last post by:
Hi, I'm trying to work out a binary division problem 1100 / 101010101010111 Here is what I have so far but I'm not sure if I'm doing it correctly and I'm suppose to continue the division...
13
by: jamesonang | last post by:
Supposed unsigned int(32 bits) is the largest number that computer can represent with a single variable. Now, i have a big integer ( less than 64 bit, but great than 32 bit) . i represent it by...
4
by: Jm lists | last post by:
Hello members, I want to know does the "eval" in python have the same features as in Perl (capture errors)? For example,in perl I can wrote: $re = eval { 1 / 0 }; Though 1/0 is a fatal...
5
by: zakad | last post by:
Hello, I have a working program in C++ that I am trying to rewrite in PERL. The program involves a division of two large integers with the result containing a predetermined number of...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.