Date: 2 Oct 2001 02:23:04 GMT From: damian@qimr.edu.au (Damian James) Subject: Re: Using TAB - Newbie Question Message-Id: On 1 Oct 2001 17:43:31 -0700, Daniel Riveong said: >... >I am creating a flat database with data from a submitted form. My >Question is how does one use TAB is a delimiter? A tab is represented by \t. > >Here is a sample of the code: > > foreach $to_print (@sortlist) { > if ($fields{'outputfile'} ne "") > { print OUT_FILE "$fields{$to_print}\|"; } > if ($fields{'submit_to'} ne "") > { $msgtext .= "$to_print = $fields{$to_print}\n"; } > } Do you really want all records on the same line, with a trailing delimiter? Remember that anything other than '', 0 and undefined will evaluate as true. Also, you can test for the existence of hash keys with exists(). See `perldoc -f exists` and `perldoc -f defined`. You are specifically testing for the empty string in both conditionals. You *probably* don't need to do that. Since $fields{'submit_to'} and $fields{'outputfile'} are not going to change, and you probably don't want to be testing them for every element in @sortlist, the above could be rewritten to eliminate the foreach loop: [warning: untested] print OUT_FILE join("\t", @fields{@sortlist}) if $fields{'outputfile'}; $msgtext = join('', map("$_ = $fields{$_}\n", @sortlist)) if $fields{'submit_to'}; You might want to have a look at the perldata man page to find out about hash slices. See also, `perldoc -f map` and `perldoc -f join`. HTH Cheers, Damian -- @:=grep!(m!$/|#!..$|),split//,;@;=0..$#:;while($:=@;){$;=rand $:--,@;[$;,$:]=@;[$:,$;]while$:;push@|,shift@;if$;[0]==@|;select$,, $,,$,,1/80;print qq x\bxx((@;+@|)*$|++),@:[@|,@;],!@;&&$/} __END__ Just another Perl Hacker,### http://home.pacific.net.au/~djames.hub