"Print" not working in script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting "Print" not working in script
# 1  
Old 07-13-2009
"Print" not working in script

Hello everybody,

I've gotten a script together that is designed to open a .bin file and read it 32 bits at a time and then add it to the checksum. However, the only issue that I have is that it will not print anything at the end. Can anyone help me? Also, is the & symbol used for restraining the read to 32 bits? Thanks for your help in advanced.

Code:
sub cksum{
 my $word_count;
 my $bias=0;
 my $checksum=0;
 my $srcfile="../file.bin"; 
 my $buffer;
 
 open INF, $srcfile
    or die "\nCan't open $srcfile for reading: $!\n";
 print "Cannot open file.\n";
 binmode INF;
   
  $checksum = $bias;
  #while ($word_count>=0)
  while (
  read (INF, $buffer, 32) # read in (up to) 64k chunks, write
  #and print OUTF $buffer # exit if read or write fails
  ) 
  {$checksum = $checksum + $buffer}; #adding goes here
  $checksum = $checksum & 0xFFFFFFFF;
  print "This is the checksum: $checksum";
  }

# 2  
Old 07-13-2009
This just declares a subroutine. Are you actually calling the subroutine? When I call it, it runs fine except it prints a spurious "cannot open file" message, and does not append a line-feed to the end of your output Smilie

I'm also confused by your checksum-generating method. It looks like you're just adding a pointer, which doesn't make sense, since the value of the pointer has nothing to do with the contents. You need to deal with the contents manually since perl does not understand your intent, sorry Smilie
# 3  
Old 07-13-2009
After running this a few times, I've run into problems with non numeric values. The return is lower than expected and I dont see how I can add non numerics? Any suggestions?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. Shell Programming and Scripting

Why awk print is strange when I set FS = " " instead of FS = "\t"?

Look at the following data file(cou.data) which has four fields separated by tab. Four fields are country name, land area, population, continent where it belongs. As for country name or continent name which has two words, two words are separated by space. (Data are not accurately... (1 Reply)
Discussion started by: chihuyu
1 Replies

3. UNIX for Beginners Questions & Answers

Automate "touch" bash script not working.

#!/bin/bash -i SAVEIFS=$IFS IFS=$"\n\b" picc=$* if ; then echo $TDATE if ; then touch dummy touch -t "tdate" dummy touch -r "dummy" "$picc" else echo -e "No mod date value to apply. If there is one in your shell,\ninvoke \eStarted asking advice on this (on Linuxquestions.org).... (9 Replies)
Discussion started by: iamwrong
9 Replies

4. Shell Programming and Scripting

"if" Loop not working when executing script using cron

I am facing this weird issue where the script is working fine from the command line but when I am executing it from cron though it is working fine but the "if" loop is processing else part though I know that the if part of the logic is true and ideally the loop should execute the if portion. ... (3 Replies)
Discussion started by: sk2code
3 Replies

5. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

6. Shell Programming and Scripting

print system("uname -n") is not working .Pls help

awk '{if ($1 == "State:" && $2 == "Okay") {print system("uname -n")}}' ---------- Post updated at 01:20 AM ---------- Previous update was at 01:19 AM ---------- it is printing uname -n instead of printing the output of the command (8 Replies)
Discussion started by: rishiraaz
8 Replies

7. Solaris

How to check "faulty" or "stalled" print queues - SAP systems?

Hi all, First off, sorry for a long post but I think I have no other option if I need to explain properly what I need help for. I need some advise on how best to check for "faulty" or "stalled/jammed' print queues. At the moment, I have three (3) application servers which also acts as print... (0 Replies)
Discussion started by: newbie_01
0 Replies

8. Shell Programming and Scripting

cat $como_file | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g'

hi All, cat file_name | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g' Can this be done by using sed or awk alone (4 Replies)
Discussion started by: harshakusam
4 Replies

9. Shell Programming and Scripting

Script not working..."sort" not working properly....

Hello all, I have a file - 12.txt cat 12.txt =============================================== Number of executions = 2 Total execution time (sec.ms) = 0.009883 Number of executions = 8 Total execution time (sec.ms) = 0.001270 Number of... (23 Replies)
Discussion started by: Rahulpict
23 Replies

10. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies
Login or Register to Ask a Question