Data conversion example in Perl

May 4, 2008 at 12:15 am | Posted in perl | 1 Comment

This is a one-off to convert Dinesh Prabhu’s Romanized Urdu-English dictionary into comma separated value format (.CSV) to be opened in Microsoft Excel and then pasted into the Microsoft Excel workbook included with Günther’s Vocabulary Cards for Palm.

open (INPUT, “< $ARGV[0]") || die "Can't open file $ARGV[0].\n"; while () { if ($_ =~ /([^\:]+)\:\s*([PATHSG])\s+(n.f.|n.m.|pron.|adj.|v.|adv.|intj.|prep.|suff.|pref.)\s+(.*)/) { ($urdu, $origin, $part, $english) = ($1, $2, $3, $4); print "\"$urdu \[$part\] \[$origin\]\",\"\",\"\",\"\",\"$english\"\n"; } } close(INPUT) [/sourcecode]

Create a free website or blog at
Entries and comments feeds.