Perl programmer for hire: download my resume (PDF).
John Bokma Perl
freelance Perl programmer

Comments: Perl Programmer available

4 comments

Are you looking for an experienced and professional Perl programmer who

Read the rest of Perl Programmer available.

Comments

I need help with Perl. I want to read files within a directory, and print the files content in an ascending order to another file. Any idea how I can do this?

Posted by enu at 03:05 GMT on 6 March 2007

@enu - I recommend you to install the module File::Slurp. You can use read_dir to read all files to an array. Next you probably want to use grep to get the files you want, and sort to sort.

For more information on grep or sort, type on the command line

perldoc -f grep

or

perldoc -f sort

respectively.

You can read an entire file with read_file and either print each file to STDOUT and use a redirect when you call your script (i.e. yourscript.pl > output.txt) or use append_file.

See the File::Slurp documentation on CPAN.

Posted by John Bokma at 03:28 GMT on 6 March 2007

Hi, I am writing a perl script using a bunch of xml files. The script is supposed to look at a specific tag in the xml file and read in its text. Its supposed to store the text. As of now, I save the entire the file in a variable and go through each line until i reach the tag which i need. Therefore, if the file is 80000 lines long, the program is certainly not efficient. Can you suggest a quicker way! thanks!

Posted by Martha at 20:50 GMT on 16 May 2008

Hi Marta,

The recommended way to parse XML is to use a dedicated XML parser because there are many ways a simple hand coded parser can fail, often in unexpected ways.

While maybe not the best module, XML::Parser might do the job for you. See for an example: XML elements report

This one does parse a bunch of XML files, and it's not that hard to modify the characters sub to remember the text if and only if the opening element has been encountered and use the end_element sub to store the text if and only if the closing element has been encountered.

Remember that the characters sub (handler) can be called several times for a piece of text enclosed in an element.

If you need more help, let me know. I can also write the Perl program for you - because it's a small one - in exchange for book(s), see: Perl programming.

Posted by John Bokma at 20:48 GMT on 20 May 2008

Post a comment

Note that your comment doesn't show up immediately. I review each comment before I add it to this site.

Check the Follow this page option if you want to receive an email each time a comment is posted to this page, including yours. A link to turn this option off will be included with each email.

Internet adresses will be converted automatically. You can use the following notation to specify anchor text for a link: [url=http://example.com/]example text[/url].