The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
perl -write values in a file to @array in perl meghana Shell Programming and Scripting 27 06-07-2009 06:05 PM
Help me to write the script gyana_cboy Shell Programming and Scripting 5 10-05-2007 03:19 AM
how to write perl substitute command in shell scripts param_it UNIX for Dummies Questions & Answers 3 07-03-2007 05:09 AM
need help to write perl code getdpg Shell Programming and Scripting 0 09-20-2006 10:24 AM
Help! Need to write my first script fundidor Shell Programming and Scripting 5 01-08-2004 10:20 PM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 03-21-2008
user_prady user_prady is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 163
Need help to write a Perl script

Hello friends,

I am having a awk script which does my goal , but I want to learn perl , after learning the basics in perl now I am trying to convert my nawk script to perl .

Please help me to do some task in perl that I ve already did in nawk.

Like I am facing some problem in perl with $_, I think it is similar to $0 in nawk.

part of my perl code as follows
Code:
open(IN, $file)|| die("Could not open file");
while(<IN>) {
 if($_ !~ /^"/){
    if($_ =~ /^\*/){
    }
    else{
       @fld = split(/,/, $_);
       if( $fld[3] == 1 ){
              print $_;
              $binary1 = HexToBinary(substr($fld[0],0,2));
              print $_;
        }
     }
  }
}
sub HexToBinary{
        my(%h)=( '0'=>'0000'
                ,'1'=>'0001'
                ,'2'=>'0010'
                ,'3'=>'0011'
                ,'4'=>'0100'
                ,'5'=>'0101'
                ,'6'=>'0110'
                ,'7'=>'0111'
                ,'8'=>'1000'
                ,'9'=>'1001'
                ,'A'=>'1010'
                ,'B'=>'1011'
                ,'C'=>'1100'
                ,'D'=>'1101'
                ,'E'=>'1110'
                ,'F'=>'1111'
        );
        $_=uc $_[0];
        s/([0-9A-F])/$h{$1}/g;
        return $_;
};
Although both the print statement seems to be same but gives me a different result. If i am not wrong incase of nawk we can print the current line anywhere with just typing
Code:
print $0

Regards,
user_prady

Last edited by user_prady; 03-21-2008 at 04:14 AM..
 

Bookmarks

Tags
perl, perl shift, shift, shift perl

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:41 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0