21 Reusable Code Snippet Topics

Remove Filter
Member Avatar for
Member Avatar for 2teez

I wanted a graphical representation of the listing of my files and folders from the command line interface, just like what the CLI **tree** would give on linux system, I really don't like how the same command is displayed on windows. So, I called on ma 'Cherie' Perl do it …

0
290
Member Avatar for KevinADC
Member Avatar for 2teez

I really got bored and tired of trying to find or remember some codes usage in so many files saved on my system, when it was needed. So, I called 'Monsieur' perl for help, hacking together some codes which works great for me and solve my problem of boredom. You …

Member Avatar for rsprice
0
241
Member Avatar for OneDreamCloser

hello all, i am getting the following error when i am trying to run my 1st Perl script: [CODE][id=0 @ 0] : IP address "3.3.3.3" corresponds to device "core". Thread 1 terminated abnormally: Not a CODE reference at ./dev_ithread.pl line 23. [id=0 @ 1] : IP address "5.5.5.5" corresponds to …

Member Avatar for erezschatz
1
435
Member Avatar for KevinADC

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 …

Member Avatar for sensamurai
1
1K
Member Avatar for KevinADC

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 …

Member Avatar for roswell1329
0
232
Member Avatar for mitzoff

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 …

Member Avatar for mitzoff
0
204
Member Avatar for KevinADC

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.

Member Avatar for Prakash_8111
-1
421
Member Avatar for KevinADC

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 …

Member Avatar for KevinADC
0
622
Member Avatar for Kelicula

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. [B]Usage:[/B] …

Member Avatar for Kelicula
0
213
Member Avatar for Kelicula

[B]Situation:[/B] 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. [B]Solution:[/B] First you must decide on an image width. The subroutine returns the proportional height equivalent. …

Member Avatar for Kelicula
0
164
Member Avatar for MattEvans

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 manually parsing everything seems like a waste …

Member Avatar for KevinADC
0
386
Member Avatar for kalyanraj
Member Avatar for KevinADC

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 …

1
1K
Member Avatar for Mushy-pea

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 …

Member Avatar for Mushy-pea
0
184
Member Avatar for KevinADC
Member Avatar for KevinADC

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: [URL="http://perldoc.perl.org/List/Util.html"]List::Util[/URL]

0
161
Member Avatar for KevinADC

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 …

0
271
Member Avatar for KevinADC

"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 …

0
170
Member Avatar for KevinADC

You will need to install the Email::Valid module if it's not already installed. See the module documentation for further details. [URL="http://search.cpan.org/~rjbs/Email-Valid-0.176/lib/Email/Valid.pm"]Email::Valid[/URL]

0
291
Member Avatar for KevinADC

The [URL="http://perldoc.perl.org/File/Basename.html"]File::Basename[/URL] 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.

0
872

The End.