Sponsored Content
Top Forums Shell Programming and Scripting Need help to write a Perl script Post 302177870 by user_prady on Sunday 23rd of March 2008 11:33:14 PM
Old 03-24-2008
Bug

Quote:
Originally Posted by era
The logic is a bit hard to follow. Could you post a sample input and sample output for that?

I would start by refactoring your script based on the following observations;

* the "if" has only an "else" clause. It would seem more natural to invert the test and have only a "then" clause.

* Perl can easily convert hex to binary, and generally between different number bases, so that part of the script is easy to simplify. But you are not using the value of $binary anywhere?

Code:
open(IN, $file)|| die("Could not open file: $!");
while(<IN>) {
 unless (/^["*]/) {
   @fld = split(/,/, $_);
   if( $fld[3] == 1 ){
          print $_;
          $binary1 = HexToBinary(substr($fld[0],0,2));
          print $_;
	  # do you mean
	  # $first = $binary1 . substr($fld[0],2);
          # shift @fld
          # print join ("," $first, @fld)
          # ?
    }
  }
}
sub HexToBinary{
    my $hex = $h;
    return sprintf "%b", hex($h);
}


Thank you all for your kind reply.

Era sorry for not sending my whole goal and code.

Here it goes...Its a FPGA test pattern .But I think I cant send all my constarints at once.

Input
Code:
"RxData","Time","NSysClkEn"
000000,0000,1,0,0,0,0,0,0
000000,0000,0,0,0,0,0,0,0
*Comment Control Frame at 10 us
000000,030C,0,0,0,0,1,0,1
241000,0000,0,1,3,0,0,0,0
000100,0000,0,0,2,0,0,0,0
*Comment Control Frame at 65 us
000000,13CE,0,0,0,0,1,0,1
000200,0000,0,1,2,0,0,0,0

*Main Start
*Comment Frame 2 at 1.04167 us
000000,2451,0,0,0,0,1,0,1
A8F9FF,0000,0,1,3,0,0,0,0
9F999F,0000,0,0,3,0,0,0,0
FFF9FF,0000,0,0,3,0,0,0,0
F9FF9F,0000,0,0,3,0,0,0,0
999DF3,0000,0,0,3,0,0,0,0
73BDF5,0000,0,0,3,0,0,0,0
D5FDF5,0000,0,0,3,0,0,0,0
5FD9B5,0000,0,0,3,0,0,0,0
1BB3BB,0000,0,0,3,0,0,0,0
7DF97D,0000,0,0,3,0,0,0,0
3BDDDB,0000,0,0,3,0,0,0,0
*Main End

Constraints:
Code:
1.dont process lines starting with lines " (double quotes)and  * (astris)
2.Prints the lines starting with * as it is. 
3.if the fourth field is "1" then take the fist two digits of the first field and then convert it to binary.
   checks the binary no with a look up table.
4.prints the second field in decimal when field 9th and 7th are "1".

For the time being I am explananing that much when I ll archive that goal in Perl I ll explain further friends.

Regards,
user_prady
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Should I write a PERL Script or Shell Script?

Hello, I have done some BASIC shell scripting/PERL scripting before so I am familiar with the languages. I am not really sure which one would lend itself better to the application I have to write. I am required to scan the message logs for possible break in attempts. If I use shell scripting... (2 Replies)
Discussion started by: mojoman
2 Replies

2. Shell Programming and Scripting

write a perl script or kornshell reading a two files and outputting to comma format

Hello Can someone help me to write a perl script or kornshell reading a two files and outputting to comma format. Here is the two files listofdisks.txt id, diskname, diskgroup, diskisze(GB), FC 1, CN34, GRP1, 30, FC_CN34 2, CN67, GRP5, 19, 4, VD1, GRP4, 23, FC_VD1 6, CF_D1, ... (0 Replies)
Discussion started by: deiow
0 Replies

3. Shell Programming and Scripting

Help need to write a script on column separation for syslog output in perl

HI Pros, I have a issue.I need to write a script to parse the logs got from syslog server and update the same in my database.I need the following output.I donot know perl and I heard it very easy to write in perl I have the sample log I need each column seperated by commas and all equals... (0 Replies)
Discussion started by: iron_michael86
0 Replies

4. Shell Programming and Scripting

perl script to find, write, repeat...

I am a novice writing perl scripts so I'd appreciate any help you guys can offer. I have a list of 100 words in a file (words.txt) and I need to find them in a second file (data.txt). Whenever one of these words is found I need to write that line to a third file (out.txt) and then continue... (1 Reply)
Discussion started by: tgamble
1 Replies

5. Shell Programming and Scripting

perl script to check read/write/execute permission for 'others'

I want to check access rights permissions not for 'user', not for 'group', but for 'others'. I want to do it by system command in which i want to use 'ls -l' and 'awk' command. I have written the following program : #!/usr/bin/local/perl #include <stdlib.h> system ("ls -l | awk... (1 Reply)
Discussion started by: shubhamsachdeva
1 Replies

6. Shell Programming and Scripting

How to write a update query in perl script?

can any one suggest me on how to write a update query in perl script for Oracle database and also tell me abt how we can write a code for sending mails with report as attachment to appropriate persons? (1 Reply)
Discussion started by: Ramesh V Kumar
1 Replies

7. Shell Programming and Scripting

Need a perl script to read and write the data

Hi, I have on Designdocument in that information is stored with in tabular format.I need Perlscript to read and write the datausing perl script? Regards, Ravi (0 Replies)
Discussion started by: toravi.pentaho
0 Replies

8. Shell Programming and Scripting

Need a UNIX/perl script to read and write the data

Hi, I have on Designdocument in that information is stored with in tabular format.I need Perl/unix script to read and write the data using perl script? Regards, Ravi (4 Replies)
Discussion started by: toravi.pentaho
4 Replies

9. Shell Programming and Scripting

Perl script to create/write into spreadsheet

Hi, I need help in debug following script. can somebody help....!!! #!/usr/bin/perl -w use strict; use Spreadsheet::WriteExcel; # Create a new workbook called simple.xls and add a worksheet. my $workbook = Spreadsheet::WriteExcel->new('simple.xls'); my $worksheet =... (1 Reply)
Discussion started by: chettyravi
1 Replies

10. Shell Programming and Scripting

How to write Perl Script to Get MQ Queue Depth?

Hi , I got the following script from internet to display queue depth using Perl Script. However, when I execute it , im getting following error. Can anyone shed light on what is going wrong? #!/usr/bin/perl ## 07/23/01 ## Depth Inquiry sample program. ## Arguments: ## Connects to... (11 Replies)
Discussion started by: srkmish
11 Replies
PPERL(1p)						User Contributed Perl Documentation						 PPERL(1p)

NAME
PPerl - Make perl scripts persistent in memory SYNOPSIS
$ pperl foo.pl DESCRIPTION
This program turns ordinary perl scripts into long running daemons, making subsequent executions extremely fast. It forks several processes for each script, allowing many processes to call the script at once. It works a lot like SpeedyCGI, but is written a little differently. I didn't use the SpeedyCGI codebase, because I couldn't get it to compile, and needed something ASAP. The easiest way to use this is to change your shebang line from: #!/usr/bin/perl -w To use pperl instead: #!/usr/bin/pperl -w WARNINGS
Like other persistent environments, this one has problems with things like BEGIN blocks, global variables, etc. So beware, and try checking the mod_perl guide at http://perl.apache.org/guide/ for lots of information that applies to many persistent perl environments. Parameters $ pperl <perl params> -- <pperl params> scriptname <script params> The perl params are sent to the perl binary the first time it is started up. See perlrun for details. The pperl params control how pperl works. Try -h for an overview. The script params are passed to the script on every invocation. The script also gets any current environment variables, the current working directory, and everything on STDIN. Killing In order to kill a currently running PPerl process, use: pperl -- -k <scriptname> You need to make sure the path to the script is the same as when it was invoked. Alternatively look for a .pid file for the script in your tmp directory, and kill (with SIGINT) the process with that PID. ENVIRONMENT
pperl uses the PPERL_TMP_PATH environment variable to determine the directory where to store the files used for inter-process communication. By default, the subdirectory .pperl of the user's home directory is used. BUGS
The process does not reload when the script or modules change. $^S is not represented identically with respect to perl, since your script will be run within an eval block AUTHOR
Matt Sergeant, matt@sergeant.org. Copyright 2001 MessageLabs Ltd. SEE ALSO
perl. perlrun. perl v5.14.2 2011-11-15 PPERL(1p)
All times are GMT -4. The time now is 02:27 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy