|
In a message dated 4/11/2006 10:43:01 A.M. Eastern Standard Time,
[EMAIL PROTECTED] writes:
> Source database file <a.txt> follows:
> > Delphi#Sales pitch training & Basic service training (VCD Format with > English & Hindi Voiceover)#0#1 > GPS#To develop animation and integration as per the storyboard and > instructions given by RTS#0#0#672 > > > Output should be <a.out> as: > > <record> > <project>Delphi</project> > <desc>Sales pitch training & Basic service training (VCD Format with English > & Hindi Voiceover)</desc> > <no1>0</no1> > <no2>1</no2> > </record> > > <record> > <project>GPS</project> > <desc>To develop animation and integration as per the storyboard and > instructions given by RTS</desc> > <no1>0</no1> > <no2>0</no2> > <no3>672</no3> > </record> > > > Could you please use file handling option. > > Regards > Saravanan. hi saravanan --
i don't know what the ``file handling option'' is, but the code below may
be
useful to you.
(btw -- i just got done sending out a long screed about how i never use the
DATA
filehandle for test data, and here i'm using it. oh,
well... i guess it's justified by
the fact that it's just a toy, example script.)
hth -- bill walters
BEWARE WRAPPING in long lines in __DATA__ section below.
---------------- code begins -----------------------
#
t_usaravanan1.pl
11apr06waw
use strict; use warnings; ENTRY: while (defined (my $entry = <DATA>)) { next ENTRY unless $entry =~ /\S/; # ignore unless non-blank line chomp $entry; print formatted_output(split '#', $entry); } $! and die "error reading DATA: $!";
sub formatted_output { my ($project, $desc, @others) = @_;
my $indent = ' '; # makes output
pretty
my $tag = 'no1';
$_ = "$indent<$tag>$_</$tag> \n", ++$tag for @others; local $" = ''; # interpolate @others array without
extra spaces
return "<record>
\n"
. "$indent<project>$project</project> \n" . "$indent<desc>$desc</desc> \n" . "@others" . "</record> \n"; }
# BEWARE WRAPPING in long lines below
__DATA__ Delphi#Sales pitch training & Basic service training (VCD Format with English & Hindi Voiceover)#0#1 GPS#To develop animation and integration as per the storyboard and instructions given by RTS#0#0#672 Foo#To develop Foo so that it may ultimately become
Bar |
_______________________________________________ ActivePerl mailing list [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
