CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: Re: [teddoff] Parsing data from TXT file into XMP format with ExifTool: Edit Log



Zhris
Enthusiast

May 14, 2015, 7:41 PM


Views: 37091
Re: [teddoff] Parsing data from TXT file into XMP format with ExifTool

Hi,

If I have understood correctly, your first step is to parse the txt file. It is well structured, in that it follows the pattern key \n value \n linebreak, therefore can be parsed with ease. There are numerous ways to achieve this, here is an example of parsing into a hash:


Code
use strict; 
use warnings;
use Data::Dumper;

my %hash = map s/[\s:]*$//r, grep /\S+/, <DATA>;

print Dumper \%hash;

__DATA__

Title:
You've Been Peeling An Orange Wrong - Tablespoon

URL:
http://www.tablespoon.com/posts/youve-been-peeling-an-orange-wrong/14800c66-27f2-4715-9936-d299ec7bfa9f?utm_source=zergnet.com&utm_medium=referral&utm_campaign=zergnet_280460

Comment:
This technique works best with mandarin oranges, but just for good measure I tried it out on a Valencia orange as well. Simply lop off the ends, make a small incision in the side and carefully open to reveal easy-to-eat orange segments. (Or as I prefer to call it, an orange caterpillar.)


Output:


Code
$VAR1 = {                                                                                                                                                         
'Comment' => 'This technique works best with mandarin oranges, but just for good measure I tried it out on a Valencia orange as well. Simply lop off the ends, make a small incision in the side and carefully open to reveal easy-to-eat orange segments. (Or as I prefer to call it, an orange caterpillar.)',
'URL' => 'http://www.tablespoon.com/posts/youve-been-peeling-an-orange-wrong/14800c66-27f2-4715-9936-d299ec7bfa9f?utm_source=zergnet.com&utm_medium=referral&utm_campaign=zergnet_280460',
'Title' => 'You\'ve Been Peeling An Orange Wrong - Tablespoon'
};


CHris


(This post was edited by Zhris on May 14, 2015, 7:44 PM)


Edit Log:
Post edited by Zhris (Enthusiast) on May 14, 2015, 7:43 PM
Post edited by Zhris (Enthusiast) on May 14, 2015, 7:44 PM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives