Sponsored Content
Full Discussion: $| example in perl
Top Forums Shell Programming and Scripting $| example in perl Post 302829665 by elixir_sinari on Friday 5th of July 2013 01:19:37 PM
Old 07-05-2013
You should have read perlvar documentation (using perldoc perlvar in most cases) before asking this question.

This is a special variable which controls the output buffering of the currently selected output filehandle (which is STDOUT initially). Setting it to any true value (mostly 1 assigned to it) does buffer flush after any print, printf, or write on that handle. It normally means that you get to see output on that handle immediately, without (block) buffering coming into play.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[Perl] Accessing array elements within a sed command in Perl script

I am trying to use a script to replace the header of each file, whose filename are stored within the array $test, using the sed command within a Perl script as follows: $count = 0; while ( $count < $#test ) { `sed -e 's/BIOGRF 321/BIOGRF 332/g' ${test} > 0`; `cat 0 >... (2 Replies)
Discussion started by: userix
2 Replies

2. Shell Programming and Scripting

Passing date formats in Perl: i.e. Jul/10/2007 -> 20070710 (yyyymmdd) - Perl

Hi , This script working for fine if pass script-name.sh Jul/10/2007 ,I want to pass 20070710(yyyymmdd) .Please any help it should be appereciated. use Time::Local; my $d = $ARGV; my $t = $ARGV; my $m = ""; @d = split /\//, $d; @t = split /:/, $t; if ( $d eq "Jan" ) { $m = 0 }... (7 Replies)
Discussion started by: akil
7 Replies

3. Shell Programming and Scripting

perl/unix: script in command line works but not in perl

so in unix this command works works and shows me a list of directories find . -name \*.xls -exec dirname {} \; | sort -u | > list.txt but when i try running a perl script to run this command my $query = 'find . -name \*.xls -exec dirname {} \; | sort -u | > list.txt';... (2 Replies)
Discussion started by: kpddong
2 Replies

4. Shell Programming and Scripting

Perl :How to print the o/p of a Perl script on console and redirecting same in log file @ same time.

How can i print the output of a perl script on a unix console and redirect the same in a log file under same directory simultaneously ? Like in Shell script, we use tee, is there anything in Perl or any other option ? (2 Replies)
Discussion started by: butterfly20
2 Replies

5. Shell Programming and Scripting

Hidden Characters in Regular Expression Matching Perl - Perl Newbie

I am completely new to perl programming. My father is helping me learn said programming language. However, I am stuck on one of the assignments he has given me, and I can't find very much help with it via google, either because I have a tiny attention span, or because I can be very very dense. ... (4 Replies)
Discussion started by: kittyluva2
4 Replies

6. Shell Programming and Scripting

HELP on Perl array / sorting - trying to convert Korn Shell Script to Perl

Hi all, Not sure if this should be in the programming forum, but I believe it will get more response under the Shell Programming and Scripting FORUM. Am trying to write a customized df script in Perl and need some help with regards to using arrays and file handlers. At the moment am... (3 Replies)
Discussion started by: newbie_01
3 Replies

7. UNIX for Advanced & Expert Users

perl and HP-UX : instmodsh in combination with software depot : update inventory for installed Perl

we create a HP-UX software depot with a new perl-modul. after installation of the software depot, the perl module i can't find with instmodsh in the inventory for installed Perl modules. - i have learned of using instmodsh command : i find out what modules are already installed on my system. ... (0 Replies)
Discussion started by: bora99
0 Replies

8. Shell Programming and Scripting

Perl :: reading values from Data Dumper reference in Perl

Hi all, I have written a perl code and stored the data into Data structure using Data::Dumper module. But not sure how to retreive the data from the Data::Dumper. Eg. Based on the key value( Here CRYPTO-6-IKMP_MODE_FAILURE I should be able to access the internal hash elements(keys) ... (1 Reply)
Discussion started by: scriptscript
1 Replies

9. Programming

Perl: restrict perl from automaticaly creating a hash branches on check

My issue is that the perl script (as I have done it so far) created empty branches when I try to check some branches on existence. I am using multydimentional hashes: found it as the best way for information that I need to handle. Saing multidimentional I means hash of hashes ... So, I have ... (2 Replies)
Discussion started by: alex_5161
2 Replies

10. Programming

PERL: In a perl-scripttTrying to execute another perl-script that SETS SOME VARIABLES !

I have reviewed many examples on-line about running another process (either PERL or shell command or a program), but do not find any usefull for my needs way. (Reviewed and not useful the system(), 'back ticks', exec() and open()) I would like to run another PERL-script from first one, not... (1 Reply)
Discussion started by: alex_5161
1 Replies
IO::Handle(3pm)                                          Perl Programmers Reference Guide                                          IO::Handle(3pm)

NAME
IO::Handle - supply object methods for I/O handles SYNOPSIS
use IO::Handle; $io = new IO::Handle; if ($io->fdopen(fileno(STDIN),"r")) { print $io->getline; $io->close; } $io = new IO::Handle; if ($io->fdopen(fileno(STDOUT),"w")) { $io->print("Some text "); } # setvbuf is not available by default on Perls 5.8.0 and later. use IO::Handle '_IOLBF'; $io->setvbuf($buffer_var, _IOLBF, 1024); undef $io; # automatically closes the file if it's open autoflush STDOUT 1; DESCRIPTION
"IO::Handle" is the base class for all other IO handle classes. It is not intended that objects of "IO::Handle" would be created directly, but instead "IO::Handle" is inherited from by several other classes in the IO hierarchy. If you are reading this documentation, looking for a replacement for the "FileHandle" package, then I suggest you read the documentation for "IO::File" too. CONSTRUCTOR
new () Creates a new "IO::Handle" object. new_from_fd ( FD, MODE ) Creates an "IO::Handle" like "new" does. It requires two parameters, which are passed to the method "fdopen"; if the fdopen fails, the object is destroyed. Otherwise, it is returned to the caller. METHODS
See perlfunc for complete descriptions of each of the following supported "IO::Handle" methods, which are just front ends for the corresponding built-in functions: $io->close $io->eof $io->fcntl( FUNCTION, SCALAR ) $io->fileno $io->format_write( [FORMAT_NAME] ) $io->getc $io->ioctl( FUNCTION, SCALAR ) $io->read ( BUF, LEN, [OFFSET] ) $io->print ( ARGS ) $io->printf ( FMT, [ARGS] ) $io->say ( ARGS ) $io->stat $io->sysread ( BUF, LEN, [OFFSET] ) $io->syswrite ( BUF, [LEN, [OFFSET]] ) $io->truncate ( LEN ) See perlvar for complete descriptions of each of the following supported "IO::Handle" methods. All of them return the previous value of the attribute and takes an optional single argument that when given will set the value. If no argument is given the previous value is unchanged (except for $io->autoflush will actually turn ON autoflush by default). $io->autoflush ( [BOOL] ) $| $io->format_page_number( [NUM] ) $% $io->format_lines_per_page( [NUM] ) $= $io->format_lines_left( [NUM] ) $- $io->format_name( [STR] ) $~ $io->format_top_name( [STR] ) $^ $io->input_line_number( [NUM]) $. The following methods are not supported on a per-filehandle basis. IO::Handle->format_line_break_characters( [STR] ) $: IO::Handle->format_formfeed( [STR]) $^L IO::Handle->output_field_separator( [STR] ) $, IO::Handle->output_record_separator( [STR] ) $ IO::Handle->input_record_separator( [STR] ) $/ Furthermore, for doing normal I/O you might need these: $io->fdopen ( FD, MODE ) "fdopen" is like an ordinary "open" except that its first parameter is not a filename but rather a file handle name, an IO::Handle object, or a file descriptor number. (For the documentation of the "open" method, see IO::File.) $io->opened Returns true if the object is currently a valid file descriptor, false otherwise. $io->getline This works like <$io> described in "I/O Operators" in perlop except that it's more readable and can be safely called in a list context but still returns just one line. If used as the conditional +within a "while" or C-style "for" loop, however, you will need to +emulate the functionality of <$io> with "defined($_ = $io->getline)". $io->getlines This works like <$io> when called in a list context to read all the remaining lines in a file, except that it's more readable. It will also croak() if accidentally called in a scalar context. $io->ungetc ( ORD ) Pushes a character with the given ordinal value back onto the given handle's input stream. Only one character of pushback per handle is guaranteed. $io->write ( BUF, LEN [, OFFSET ] ) This "write" is like "write" found in C, that is it is the opposite of read. The wrapper for the perl "write" function is called "format_write". $io->error Returns a true value if the given handle has experienced any errors since it was opened or since the last call to "clearerr", or if the handle is invalid. It only returns false for a valid handle with no outstanding errors. $io->clearerr Clear the given handle's error indicator. Returns -1 if the handle is invalid, 0 otherwise. $io->sync "sync" synchronizes a file's in-memory state with that on the physical medium. "sync" does not operate at the perlio api level, but operates on the file descriptor (similar to sysread, sysseek and systell). This means that any data held at the perlio api level will not be synchronized. To synchronize data that is buffered at the perlio api level you must use the flush method. "sync" is not implemented on all platforms. Returns "0 but true" on success, "undef" on error, "undef" for an invalid handle. See fsync(3c). $io->flush "flush" causes perl to flush any buffered data at the perlio api level. Any unread data in the buffer will be discarded, and any unwritten data will be written to the underlying file descriptor. Returns "0 but true" on success, "undef" on error. $io->printflush ( ARGS ) Turns on autoflush, print ARGS and then restores the autoflush status of the "IO::Handle" object. Returns the return value from print. $io->blocking ( [ BOOL ] ) If called with an argument "blocking" will turn on non-blocking IO if "BOOL" is false, and turn it off if "BOOL" is true. "blocking" will return the value of the previous setting, or the current setting if "BOOL" is not given. If an error occurs "blocking" will return undef and $! will be set. If the C functions setbuf() and/or setvbuf() are available, then "IO::Handle::setbuf" and "IO::Handle::setvbuf" set the buffering policy for an IO::Handle. The calling sequences for the Perl functions are the same as their C counterparts--including the constants "_IOFBF", "_IOLBF", and "_IONBF" for setvbuf()--except that the buffer parameter specifies a scalar variable to use as a buffer. You should only change the buffer before any I/O, or immediately after calling flush. WARNING: The IO::Handle::setvbuf() is not available by default on Perls 5.8.0 and later because setvbuf() is rather specific to using the stdio library, while Perl prefers the new perlio subsystem instead. WARNING: A variable used as a buffer by "setbuf" or "setvbuf" must not be modified in any way until the IO::Handle is closed or "setbuf" or "setvbuf" is called again, or memory corruption may result! Remember that the order of global destruction is undefined, so even if your buffer variable remains in scope until program termination, it may be undefined before the file IO::Handle is closed. Note that you need to import the constants "_IOFBF", "_IOLBF", and "_IONBF" explicitly. Like C, setbuf returns nothing. setvbuf returns "0 but true", on success, "undef" on failure. Lastly, there is a special method for working under -T and setuid/gid scripts: $io->untaint Marks the object as taint-clean, and as such data read from it will also be considered taint-clean. Note that this is a very trusting action to take, and appropriate consideration for the data source and potential vulnerability should be kept in mind. Returns 0 on success, -1 if setting the taint-clean flag failed. (eg invalid handle) NOTE
An "IO::Handle" object is a reference to a symbol/GLOB reference (see the "Symbol" package). Some modules that inherit from "IO::Handle" may want to keep object related variables in the hash table part of the GLOB. In an attempt to prevent modules trampling on each other I propose the that any such module should prefix its variables with its own name separated by _'s. For example the IO::Socket module keeps a "timeout" variable in 'io_socket_timeout'. SEE ALSO
perlfunc, "I/O Operators" in perlop, IO::File BUGS
Due to backwards compatibility, all filehandles resemble objects of class "IO::Handle", or actually classes derived from that class. They actually aren't. Which means you can't derive your own class from "IO::Handle" and inherit those methods. HISTORY
Derived from FileHandle.pm by Graham Barr <gbarr@pobox.com> perl v5.12.1 2010-04-26 IO::Handle(3pm)
All times are GMT -4. The time now is 10:37 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy