Allison,

On Saturday 11 August 2001 12:26, Allison Davis wrote:
> I am new to the list and just starting to learn perl.  Can anyone tell me
> how to process a form into a text delimited file or even what a text
> delimited file is.  I hope this isn't a stupid question.

There are no stupid questions, only questions that are so broad they cannot 
be easily answered.  Oh, and stupid answers, there are definitely those too.

First, what is a "text delimited file."  I think what you mean is 
"delimited text file."  This is just a text file, like one you might create 
with notepad in Windows.  The delimited part refers to something between 
pieces of text that separates them.  Lines are often separated by a 
carriage return.

You can also delimit "fields" within a line of a text file.  Here's an 
example of that:

Perl^Larry Wall^www.perl.com
Python^Guido Van Rossum^www.python.org
Ruby^Yukihiro Matsumoto^www.rubycentral.com

Each line can be thought of as a record and each of the sections of each 
record separated by the caret ("^") sign can be considered a field.  This 
translates roughly into columns and rows in database parlance.

Let's say this bit of text is in a file called cool_langs.txt.  Here's how 
you might do something with it in a perl program.

#!/usr/bin/perl

use warnings;
use strict;

open( LANG, "cool_langs.txt" ) or die( "File open error: $!\n" );

while( <LANG> ){
        chomp;
        my ( $lang_name, $author, $url ) = split /\^/; 
        
        print "Language: $lang_name\n";
        print "Author: $author\n";
        print "More Info: $url\n\n";
}

close( LANG);

Well, that's it.  Look at Learning Perl, 3rd edition for this type of stuff 
and more.

Regards,

Troy




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to