Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Anyone for UIEE?

by Cody Fendant (Pilgrim)
on Aug 30, 2010 at 23:32 UTC ( #858093=perlquestion: print w/ replies, xml ) Need Help??
Cody Fendant has asked for the wisdom of the Perl Monks concerning the following question:

I recently had to write code to parse files in UIEE format. Have any monks come across it before?

There isn't anything on CPAN which I could find, although there were some plaintive, unanswered cries for help out there on sites like Experts Exchange. It's a rather old-fashioned format, but still used in the book trade. Some booksellers use it to upload their inventories to Amazon, I believe.

Parsing an actual file is incredibly simple, I did it roughly like this:

$/ = "\r\n\r\n"; open( UIEEFILE, '<', '/path/to/file.txt' ); while (<UIEEFILE>) { my %book = (); foreach my $line ( split( "\r\n", $_ ) ) { my ( $key, $value ) = split( /\|/, $line, 2 ); if ( defined( $book{$key} ) ) { $book{$key} .= " $value"; } else { $book{$key} = $value; } # do something with %book } }

Though that doesn't deal with the issue of binary data, or of course error handling and so on.

Does anyone think a CPAN module would be a good idea? To me it's in a grey area where anyone halfway competent with perl would be able to knock up a script like mine in five minutes, and anyone who wasn't able to do that would have bigger problems than not having a module.

One other problem I encountered was that the UIEE files I was dealing with didn't actually follow the spec anyway, and I couldn't rely on things like field order which should indicate validity. If there's lots of invalid code out there, people will have to write their own parsers a lot of the time anyway.

Comment on Anyone for UIEE?
Download Code
Re: Anyone for UIEE?
by ikegami (Pope) on Aug 31, 2010 at 00:06 UTC

    One other problem I encountered was that the UIEE files I was dealing with didn't actually follow the spec anyway

    That would be one reason to make a CPAN module. It would hold the collective experiences of the people who worked on it, including workarounds for common deviations from the spec.

      Interesting point. Any module would definitely need to have strict and non-strict modes.
        Or maybe a validator (strict) and a parser (not strict)
Re: Anyone for UIEE?
by dasgar (Deacon) on Aug 31, 2010 at 00:19 UTC

    Sounds like a good idea to me. As for files not following the spec, the same can be said of HTML files and there are HTML parser modules available.

    OT -- Ok, am I the only one to find it ironic that a format that is used for books was authored by someone named Thomas A. Sawyer, whose name is very similar to one of the most well known characters from Mark Twain's books (Tom Sawyer)? Sorry, couldn't resist commenting on the irony of that.

      He didn't actually do the work. He told those passing by how much fun it was & got them to do the work instead. ;)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://858093]
Approved by ikegami
Front-paged by aquarium
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (7)
As of 2014-07-29 00:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (211 votes), past polls