Sponsored Content
Full Discussion: perl script help
Top Forums Shell Programming and Scripting perl script help Post 302173680 by HPAVC on Friday 7th of March 2008 12:28:55 PM
Old 03-07-2008
Quote:
Originally Posted by jambesh
Hi all,

open(FH,"indexlog.txt") || die "could not able to open the file : $!";
while(defined(my $line = <FH>))
{
my ($tbl_spc,$max_size,$free_size,$max_block,$pctfree) = $line=~/^(\w+) \s+ (\d+) \s+ (\d+) \s+ (\d+)$/;
print $tbl_spc,$max_size,"\n";
}

close(FH);
you have a lot of extra spaces in your regex

Code:
$line=~/^(\w+)_\s+_(\d+)_\s+_(\d+)_\s+_(\d+)$/;

why not ..
Code:
my ($tbl_spc,$max_size,$free_size,$max_block,$pctfree) = split(/\s+/, $line);

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl: Run perl script in the current process

I have a question regarding running perl in the current process. I shall demonstrate with an example. Look at this. sh-2.05b$ pwd /tmp sh-2.05b$ cat test.sh #! /bin/sh cd /etc sh-2.05b$ ./test.sh sh-2.05b$ pwd /tmp sh-2.05b$ . ./test.sh sh-2.05b$ pwd /etc sh-2.05b$ So... (10 Replies)
Discussion started by: vino
10 Replies

2. 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

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

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

6. Shell Programming and Scripting

calling a perl script with arguments from a parent perl script

I am trying to run a perl script which needs input arguments from a parent perl script, but doesn't seem to work. Appreciate your help in this regard. From parent.pl $input1=123; $input2=abc; I tried calling it with system("/usr/bin/perl child.pl $input1 $input2"); and `perl... (1 Reply)
Discussion started by: grajp002
1 Replies

7. Shell Programming and Scripting

executing perl script from another perl script : NOT WORKING

Hi Folks, I have 2 perl scripts and I need to execute 2nd perl script from the 1st perl script in WINDOWS. In the 1st perl script that I had, I am calling the 2nd script main.pl =========== print "This is my main script\n"; `perl C:\\Users\\sripathg\\Desktop\\scripts\\hi.pl`; ... (3 Replies)
Discussion started by: giridhar276
3 Replies

8. Shell Programming and Scripting

Perl : embedding java script with cgi perl script

Hi All, I am aware that html tags can be embedded in cgi script as below.. In the same way is it possible to embed the below javascript in perl cgi script ?? print("<form action="action.htm" method="post" onSubmit="return submitForm(this.Submitbutton)">"); print("<input type = "text"... (1 Reply)
Discussion started by: scriptscript
1 Replies

9. Shell Programming and Scripting

Excuting perl script from within a perl script with variables.

Not sure what I am doing wrong here, but I can print the list with no issue. Just a blank screen with the 'do'. #!/usr/bin/perl open FILE, "upslist.txt"; while ($line=<FILE>){ if ($line=~/^(.*?),(.*?)$/){ #print "ups:$1 string:$2\n"; do 'check_snmp_mgeups-0.1.pl -H $1 -C $2'; } ... (1 Reply)
Discussion started by: mrlayance
1 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
Imager::IO(3pm) 					User Contributed Perl Documentation					   Imager::IO(3pm)

NAME
Imager::IO - Imager's io_layer object. SYNOPSIS
# Imager supplies Imager::IO objects to various callbacks my $IO = ...; my $count = $IO->write($data); my $count = $IO->read($buffer, $max_count); my $position = $IO->seek($offset, $whence); my $status = $IO->close; DESCRIPTION
Imager uses an abstraction when dealing with image files to allow the same code to work with disk files, in memory data and callbacks. If you're writing an Imager file handler your code will be passed an Imager::IO object to write to or read from. Note that Imager::IO can only work with collections of bytes - if you need to read UTF-8 data you will need to read the bytes and decode them. If you want to write UTF-8 data you will need to encode your characters to bytes and write the bytes. CONSTRUCTORS
new_fd($fd) Create a new I/O layer based on a file descriptor. my $io = Imager::IO->new(fileno($fh)); new_buffer($data) Create a new I/O layer based on a memory buffer. The supplied variable must not be changed on the the life of the I/O object. Buffer I/O layers are read only. new_cb($writecb, $readcb, $seekcb, $closecb) Create a new I/O layer based on callbacks. See "I/O Callbacks" in Imager::Files for details on the behavior of the callbacks. new_bufchain() Create a new "bufchain" based I/O layer. This accumulates the file data as a chain of buffers starting from an empty stream. Use the "slurp()" method to retrieve the accumulated content into a perl string. BUFFERED I
/O METHODS These methods use buffered I/O to improve performance unless you call set_buffered() to disable buffering. Prior to Imager 0.86 the write and read methods performed raw I/O. write($data) Call to write to the file. Returns the number of bytes written. The data provided may contain only characters x00 to xFF - characters outside this range will cause this method to croak(). If you supply a UTF-8 flagged string it will be converted to a byte string, which may have a performance impact. Returns -1 on error, though in most cases if the result of the write isn't the number of bytes supplied you'll want to treat it as an error anyway. read($buffer, $size) my $buffer; my $count = $io->read($buffer, $max_bytes); Reads up to $max_bytes bytes from the current position in the file and stores them in $buffer. Returns the number of bytes read on success or an empty list on failure. Note that a read of zero bytes is not a failure, this indicates end of file. read2($size) my $buffer = $io->read2($max_bytes); An alternative interface to read, that might be simpler to use in some cases. Returns the data read or an empty list. At end of file the data read will be an empty string. seek($offset, $whence) my $new_position = $io->seek($offset, $whence); Seek to a new position in the file. Possible values for $whence are: o "SEEK_SET" - $offset is the new position in the file. o "SEEK_CUR" - $offset is the offset from the current position in the file. o "SEEK_END" - $offset is the offset relative to the end of the file. Note that seeking past the end of the file may or may not result in an error. Any buffered output will be flushed, if flushing fails, seek() will return -1. Returns the new position in the file, or -1 on error. getc() Return the next byte from the stream. Returns the ordinal of the byte or -1 on error or end of file. while ((my $c = $io->getc) != -1) { print chr($c); } gets() gets($max_size) gets($max_size, $end_of_line) Returns the next line of input from the stream, as terminated by "end_of_line". The default "max_size" is 8192. The default "end_of_line" is "ord " "". Returns nothing if the stream is in error or at end of file. Returns the line as a string, including the line terminator (if one was found) on success. while (defined(my $line = $io->gets)) { # do something with $line } peekc() Return the buffered next character from the stream, loading the buffer if necessary. For an unbuffered stream a buffer will be setup and loaded with a single character. Returns the ordinal of the byte or -1 on error or end of file. my $c = $io->peekc; peekn($size) Returns up to the next "size" bytes from the file as a string. Only up to the stream buffer size bytes (currently 8192) can be peeked. This method ignores the buffering state of the stream. Returns nothing on EOF. my $s = $io->peekn(4); if ($s =~ /^(II|MM)*/) { print "TIFF image"; } putc($code) Write a single character to the stream. Returns "code" on success, or -1 on failure. close() my $result = $io->close; Call when you're done with the file. If the IO object is connected to a file this won't close the file handle, but buffers may be flushed (if any). Returns 0 on success, -1 on failure. eof() $io->eof Test if the stream is at end of file. No further read requests will be passed to your read callback until you seek(). error() Test if the stream has encountered a read or write error. my $data = $io->read2(100); $io->error and die "Failed"; When the stream has the error flag set no further read or write requests will be passed to your callbacks until you seek. flush() $io->flush or die "Flush error"; Flush any buffered output. This will not call lower write layers when the stream has it's error flag set. Returns a true value on success. is_buffered() Test if buffering is enabled for this stream. Returns a true value if the stream is buffered. set_buffered($enabled) If $enabled is a non-zero integer, enable buffering, other disable it. Disabling buffering will flush any buffered output, but any buffered input will be retained and consumed by input methods. Returns true if any buffered output was flushed successfully, false if there was an error flushing output. RAW I
/O METHODS These call the underlying I/O abstraction directly. raw_write() Call to write to the file. Returns the number of bytes written. The data provided may contain only characters x00 to xFF - characters outside this range will cause this method to croak(). If you supply a UTF-8 flagged string it will be converted to a byte string, which may have a performance impact. Returns -1 on error, though in most cases if the result of the write isn't the number of bytes supplied you'll want to treat it as an error anyway. raw_read() my $buffer; my $count = $io->raw_read($buffer, $max_bytes); Reads up to $max_bytes bytes from the current position in the file and stores them in $buffer. Returns the number of bytes read on success or an empty list on failure. Note that a read of zero bytes is not a failure, this indicates end of file. raw_read2() my $buffer = $io->raw_read2($max_bytes); An alternative interface to raw_read, that might be simpler to use in some cases. Returns the data read or an empty list. raw_seek() my $new_position = $io->raw_seek($offset, $whence); Seek to a new position in the file. Possible values for $whence are: o "SEEK_SET" - $offset is the new position in the file. o "SEEK_CUR" - $offset is the offset from the current position in the file. o "SEEK_END" - $offset is the offset relative to the end of the file. Note that seeking past the end of the file may or may not result in an error. Returns the new position in the file, or -1 on error. raw_close() my $result = $io->raw_close; Call when you're done with the file. If the IO object is connected to a file this won't close the file handle. Returns 0 on success, -1 on failure. UTILITY METHODS
slurp() Retrieve the data accumulated from an I/O layer object created with the new_bufchain() method. my $data = $io->slurp; dump() Dump the internal buffering state of the I/O object to "stderr". $io->dump(); AUTHOR
Tony Cook <tonyc@cpan.org> SEE ALSO
Imager, Imager::Files perl v5.14.2 2011-11-25 Imager::IO(3pm)
All times are GMT -4. The time now is 12:37 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy