IT Community - Software Programming, Web Development and Technical Support

How do I read data from a pipeline in perl?

This is a discussion on How do I read data from a pipeline in perl? within the Perl forums, part of the Software Development category; Hi, How do I read data from a pipeline in perl? Thanks sivaraman....


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > Perl

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 07-20-2007, 09:48 AM
sivaramakrishnan sivaramakrishnan is offline
D-Web Programmer
 
Join Date: Feb 2007
Posts: 74
sivaramakrishnan is on a distinguished road
Post How do I read data from a pipeline in perl?

Hi,

How do I read data from a pipeline in perl?

Thanks
sivaraman.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-11-2007, 01:45 AM
Venkat Venkat is offline
D-Web Master
 
Join Date: Mar 2007
Posts: 350
Venkat is on a distinguished road
Thumbs up Re: How do I read data from a pipeline in perl?

hey,

Data files are opened in Perl using the open() function. When you open a data file, all you have to do is specify (a) a file handle and (b) the name of the file you want to read from.

As an example, suppose you need to read some data from a file named "checkbook.txt". Here's a simple open statement that opens the checkbook file for read access:

open (CHECKBOOK, "checkbook.txt");

In this example, the name "CHECKBOOK" is the file handle that you'll use later when reading from the checkbook.txt data file. Any time you want to read data from the checkbook file, just use the file handle named "CHECKBOOK".

Example - opening a data file and reading from it

Now that we've opened the checkbook file, we'd like to be able to read what's in it. Here's how to read one line of data from the checkbook file:

$record = <CHECKBOOK>;

Pretty simple, eh? After this statement is executed, the variable $record contains the contents of the first line of the checkbook file. The "<>" symbol is called the line reading operator, and in this example we've put the checkbook file handle in the line reading operator, indicating that we'd like to read a line from the checkbook file.

Of course, instead of reading just one line of data, you may want to operate on many lines of data in the checkbook file. Suppose, for example, you wanted to print every record of information from the checkbook file. Here's the code to (a) open the checkbook file, (b) print each record from the file, and (c) close the file when you're finished working with it:

open (CHECKBOOK, "checkbook.txt");

while ($record = <CHECKBOOK>) {
print $record;
}

close(CHECKBOOK);

Notice the use of the close() statement in this example. You always want to close a file when you're finished reading from it, and since the while loop reads through the entire file, there's not much else to do when you're finished except close it.
__________________
Venkat
knowledge is Power
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to read text area data line by line ? KiruthikaSambandam ASP and ASP.NET Programming 3 01-23-2008 09:25 PM
How do I read command-line arguments with Perl? leoraja8 Perl 3 11-26-2007 06:43 AM
How do I read command-line arguments with Perl? sivaramakrishnan Perl 1 07-23-2007 04:50 AM
how to open and read data files with Perl sivaramakrishnan Perl 1 07-23-2007 02:02 AM
How to read data from excel files in webload? devarajan.v Software Testing 0 07-16-2007 04:07 AM


All times are GMT -7. The time now is 02:22 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0