vineet2004 has asked for the wisdom of the Perl Monks concerning the following question:

hi monks i had used the Centos version of linux for creating and executing my perl file. i had made a code(tperl.pl) that matched patterns from a log file(hull.log) and entered the output into a file(fn.txt). i made tperl.pl executable using chmod on the shell i typed..... perl tperl.pl hull.log > fn.txt now i have amachine having redhat .the above statements worked on centos but not on Redhat9. please help

Replies are listed 'Best First'.
Re: Empty output file with Red Hat
by davido (Cardinal) on Dec 26, 2006 at 05:11 UTC

    Does the script fail silently, or do you get an error message? And if it fails silently, do you suppose you might be able to add some error checking to the script so that it will complain if something goes wrong? You're going to need to uncover and report to us some clues before anyone can meaningfully help you to ascertain what's wrong.

    Also, is there any way you can post relevant portions of the code, or at least a small example script that replicates the failure? Otherwise, we're only going to be able to guess, and you don't really want to settle for guesses when by providing a little more background you could get accurate answers.


    Dave

      #!usr/bin/perl while(<>) { if (/ (\w\w) (\w\w) (\w\w) (\w\w) (\w\w) (\w\w) (\w\w) (\w\w) (\w\w) +(\w\w) (\w\w) (\w\w) (\w\w) (\w\w) (\w\w) (\w\w) (\w\w) (\w\w) (\w\w) + (\w\w) (\w\w) (\w\w) (\w\w) (\w\w) (\w\w) (\w\w) (\w\w) (\w\w) (\w\w +) (\w\w) (\w\w) (\w\w) (\w\w)/) { if ($2=="11") { print "\tBSC -> BTS\tBCCH INFOmation ", $1,$2,$3,$4,$5,$6,$7,$8,$9,$1 +0,$11,$12,$13,$14,$15,$16,$17,$18, $19,$20,$21,$22,$23,$24,$25,$26,$2 +7,$28,$29,$30,"\n"; print "\tMessage discriminator :",$1,"\n"; print "\tMessage type :",$2,"\n"; print "channel number :"; print "\tchannel number :",$3,$4,"\n"; print "\tElement Identifier :",$14,"\n"; print "system info Type :",$7,$8,"\n"; print "\tElement Identifier :" ,$7,"\n"; print "\tsystem info Type :", $8,"\n"; print "Full BCCH Info :",$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$1 +8,$19,$20,$21,$22,$23,$24,$25,$26,$27,$28,$29,$30,"\n"; } elsif ($2=="34") { print "\tBSC -> BTS\tSACCH INFO MODIFY ", $1,$2,$3,$4,$5,$6,$7,$8,$9 +,$10,$11,$12,$13,$14,$15,$16,$17,$18, $19,$20,$21,$22,$ +23,$24,$25,$26,$27,$28,$29,$30,"\n"; print "\tMessage discriminator :",$1,"\n"; print "\t Message type :",$2,"\n"; print "channel number :"; print "\tchannel number :",$3,$4,"\n"; print "system info Type :",$7,$8,"\n"; print "\tElement Identifier :",$7,"\n"; print "\tsystem information :",$8,"\n"; print "L3 INFORMATION :",$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18 +,$19,$20,$21,$22,$23,$24,$25,$26,$27,$28,$29,$30,"\n"; } elsif ($2=="13") { print "\tBSC -> BTS\tCHAN_RQD ", $1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$ +12,$13,$14,$15,$16,$17,$18,$19,$20,$21,"\n"; print "\tMessage discriminator :",$1,"\n"; print "\t Message type :",$2,"\n"; print "channel number :"; print "\tchannel number :",$3,$4,"\n"; print "\t Identifier :",$3,"\n"; print "\tRequest Reference :",$5,$6,$7,$8,"\n"; print "\tElement Identifier :",$5,"\n"; print "\tRandom access information :",$6,"\n"; print "\tFrame number modulo :",$7 ,$19,"\n"; print "Access delay :",$9,$10,"\n"; print "\tElement indentifier :",$9,"\n"; print "\tAccess delay :",$10,"\n"; } elsif ($2 =="33") { print "\t BTS -BSC\tRF_CHAN_REL_ACK : ",$1,$2,$3,$4,"\n"; print "BTSM Header : "; print "\tmesssage Discriminator :", $1,"\n"; print "\tMessage Type :\t", $2,"\n"; print "channel number :"; print "\tchannel number :",$3,$4,"\n"; print "\tElement indentifier :",$3,"\n"; } elsif ($2=="22") { print "\tBSC -> BTS\tCHAN_ACTIV_ACK : " , $1 , $2, $3 , $4 , $5 , $ +6 , $7, "\n"; print "BTSM Header : "; print "\t;messsage Discriminator :" , $1,"\n"; print "\tMessage Type : \t", $2,"\n"; print "channel number :"; print "\tchannel number : ", $3 , $4,"\n"; print "\tElement indentifier :",$3,"\n"; print "\tFrame number :" ,$5, $6 , $7,"\n"; print "\tElement indentifier :" , $5, "\n"; } elsif ($2=="21") { print "\tBSC -> BTS\tCHAN_ACTIV :",$1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11 +,$12,$13,$14,"\n"; print "BTSM Header : "; print "\tmesssage Discriminator :",$1,"\n"; print "\tMessage Type :\t",$2,"\n"; print "channel number :"; print "\tchannel number :",$3,$4,"\n"; print "\tElement indentifier :",$3,"\n"; print "\tActivation type :",$5,$6,"\n"; print "\tElement indentifier :",$5,"\n"; print "\tChannel mode :",$7,$8,$9,$10,$11,$12,"\n"; print "\tElement indentifier :",$17,"\n"; print "\tLength :",$18,"\n"; print "\tTiming Advance :" ,$13,$14,"\n"; print "\tElement indentifier :",$13,"\n"; } } }

      20061226 Janitored by Corion: Added code tags, as per Writeup Formatting Tips

        To avoid puzzling problems with missing data files, test your input with something along these lines:

        #!/usr/bin/perl if (!defined $ARGV[0]) { # make sure some input is given die "No input file provided: $!"; } elsif (!-f $ARGV[0]) { # input is not a file die "Input $ARGV[0] not available as a file"; }
        Then you'll know when you've got no data file to work on.

        Also suggested is the use of "use warnings" and "use strict" at the beginning of nearly every Perl program.

        non-Perl: Andy Ford

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Empty output file with Red Hat
by hesco (Deacon) on Dec 27, 2006 at 08:31 UTC
    andyford had sage advice. What you mostly need, it seems to me is a workplan for debugging code. Start by using your text editors search and replace tool to insert a '#' sign at the start of every line. Then add at the very top, just after you declare perl as your script's interpreter of choice:

    print STDERR "Well, I made it to line: ", __LINE__, ".\n";
    Then save your changes and run your script. See if that worked. Did it give you your expected output?

    If not, debug that. If so, uncomment a small block of code and copy your debug statement just below it. Run your test again.

    Feel free to comment out debug statements earlier in the script, if they have told you what they need to. But don't delete them, As your script matures, they may get reworked as log statements and be used again.

    As you copy your debug line down past tested and working code, you can make the debug output more informative, say by writing it this way:

    print STDERR "At line: ", __LINE__, ", the message type is $2, so we'l +l append to the log.\n"; etc. . . .
    Have you examined the logfile you are processing? Does it contain any lines matched by your regex? If you run this file without redirecting its output, do you see any feedback in the console?

    You would likely learn quite a bit about your script were you to write conditions to handle exceptions. Robust code includes lots of conditional paths that the programmer expects will never be taken by legitimate data in a production environment. But coding that exception handling will help you see where you perhaps made bad assumptions about what your code is actually doing. A properly handled exception might recover so the script need not terminate. It could add useful debugging information to a log file. At the very least it could die in a loud and descriptive way.

    -- Hugh

    if( $lal && $lol ) { $life++; }