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
Regarding redirection using cat. marconi UNIX for Dummies Questions & Answers 2 08-21-2008 05:02 AM
redirection DNAx86 Shell Programming and Scripting 9 04-18-2008 02:24 PM
sed redirection myle UNIX for Dummies Questions & Answers 3 03-12-2008 07:04 PM
Help with redirection Shallon1 High Level Programming 2 12-12-2001 07:35 AM
redirection to tty** with cat zorro UNIX for Dummies Questions & Answers 1 11-02-2001 11:23 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 2 Weeks Ago
King Nothing King Nothing is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 67
Perl Redirection

Hi,
I have a Perl script that finds some files based on some criteria and then it processes the file contents using some logic.
Extract:
Code:
print "Started ... ";
my $command = "<unix command>";
@arr=`$command`;
$size=@arr;
print "Size: ".$size
If I turn on the Perl debugging option then I get a warning like:

Use of uninitialized variable in line number so and so
after the initial lines are printed.

My question is that whenever I redirect the output of this script to some text file the debug warnings are written to the text file before the print statement in red is printed.
The flow of the script also does not conform to this weird behavior. Any idea folks?
Thanks.
  #2 (permalink)  
Old 2 Weeks Ago
SFNYC SFNYC is offline
Registered User
  
 

Join Date: Jun 2008
Location: New York City
Posts: 95
You should always have

Code:
use strict;
use warnings;
in your code.

Once there, listen to their error & warning messages and clean them up.

"Use of uninitialized variable in line number so and so" is telling you that you are trying to print a variable with no value. Use an 'if' condition to test this before you print it or initialize the variable with some value by default.

To remove this message from your output, redirect stderr when you submit your script.

Code:
./myprog 2> /dev/null
should do the trick, but it won't get rid of the warning.
  #3 (permalink)  
Old 2 Weeks Ago
thegeek thegeek is offline
Registered User
  
 

Join Date: Apr 2009
Location: /usr/bin/vim
Posts: 438
stderr is unbuffered.

stdout is fullbuffered/line buffer... Thats why you get the errors/warning before output.

Declare the undeclared variables first, and continue programming.
  #4 (permalink)  
Old 1 Week Ago
King Nothing King Nothing is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 67
Thanks a lot for your suggestions .
Reply

Bookmarks

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 05:38 PM.


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