Perl Code Snippet Index

Need help writing a perl script to parse multiple files

I'm new to perl and I'm writing a script to parse multiple Gaussian03 output files and extract certain pieces of data from them. Ideally the script needs to print out the name of each file, look for (the last) SCF Energy, the Zero-point Energy and check if the job has converged (i.e. in the... (Read More)

Remove leading and trailing white space from a string

This is a routine task best done with two regexp's when using perl. (Read More)
-1

Последняя возможност ь для вас.

Восстановление и естественная гармонизация отношений без вреда, результат в день обращения (авторский метод И.Н.Германа). Результат гарантирован в самых сложных случаях, где не смогли помочь другие специалисты. Привязка любимого человека, сексуальная и эмоциональная (авторский метод И.Н.Германа).... (Read More)
-1

Random Password Generator

Code snippet to generate random passwords. Avoids using confusing characters such as lower case L (l) and the number one (1), the letter 'O' and the number zero. Upper-case alpha characters could be added to the character set if mixed-case passwords are desired. (Read More)

Generate unique strings of random numbers

This code snippet will produce strings of numbers (1 thru 49) with no repeated numbers in the same string and no duplicated string of numbers in the list of strings. To change the range of numbers the script generates change 49 in the code to your requirements. Please feel free to ask... (Read More)

Regular Expression for Date(dd/mm/yyyy format)

Regex to match the dd/mm/yyyy date format. (Read More)

Remove Duplicate Lines from a File

A bare-bones code snippet to remove duplicate lines from a file. There are a number of ways to accomplish this task but this is a fast and dependable method using perls inplace editor and a simple hash to get the job done. This probably should not be used for really big files, but files with a... (Read More)

Dynamic Image Scaling (HTML Strict Compliant)

Situation: Ever wanted to get the size of an image? Possibly to determine new height and width dimensions that DO NOT distort the proportion. Well I have, and I overcame the math like so. Solution: First you must decide on an image width. The subroutine returns the proportional height... (Read More)

A quick date/Time fix (MySql)

Ever had to fix auto-generated dates retrieved from MySql databases? I made a really quick fix that displays the date in "human readable" format. Just replace "CST" with GMT, or EST etc... Whatever time zone your mysql server is located. it takes one argument, the date from the database. ... (Read More)

Adding commas to numbers

Convert 1000000 into 1,000,000 using a perl regexp. (Read More)

Search and Replace Script

This is a bare-bones search and replace script that uses perls in-place editor and the File::Find module to get the job done quickly. It will search in all sub directories of the start directory and find and replace the text you specify in the type of file you specify. Keep in mind, this is a... (Read More)

An extremely safe eval

Ever wanted to evaluate a user-provided expression, maybe from a form input or otherwise, and return the result? eval($expr) is dangerous because eval(open $out, "> file.what"); will open the file, infact, eval(everything) will pretty much do everything. checking though everything is tedious, and... (Read More)

Calculate day of the week for a given date MM-DD-YYYY

Given the date in mm-dd-yyyy (or M-D-YYYY) format (or any combination of that format) you can find out what day of the week that was on or is on or will be on, within the limitations of the system the script resides on. This snippet uses only core functions and modules so nothing needs to be... (Read More)

Simple website hit counter

This is my first working perl script that does anything useful; that being to count the hits made on a web page and display the count graphically. To make the counter work on your web page (should you wish to), you will need to create images for the number tiles like the one found on my site. You... (Read More)

Shuffling an array randomly

Use the List::Util module. I believe List::Util is a core module starting with perl 5.8. For older versions of perl you may need to install the module. See the module documentation for more details: List::Util (Read More)

Expanding variables in single-quoted strings.

I've seen this question (or similar) asked many times on forums: I have a variable in a file (text) and want to expand it. For example, I have this line in a text file: Mary had a little $lamb and I want to be able to expand $lamb but text files are treated as single-quoted strings and... (Read More)

Process all possible permutations of a list

"How can I find all the permutations of a list (or a word)"? I have seen this question asked a number of times on forums. There is a module that makes this task very easy: List::Permutor. It is not a core module so you may need to install it. See module for more details: List::Permutor (Read More)

Check if an email address is well-formed

You will need to install the Email::Valid module if it's not already installed. See the module documentation for further details. Email::Valid (Read More)

Using File::Basename to get file extensions

The File::Basename module is used to parse file paths into directory, filename and suffix (or file extension). My simple example shows how to get just the file extensions. (Read More)

Forum Tools


About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC