$ perl -pi -e 's/(S|s)licing/{$1 eq 'S' ? 'Excel' : 'excel'}/ge' *.pas
Showing posts with label perl. Show all posts
Showing posts with label perl. Show all posts
Tuesday, 4 February 2014
Perl: perserve case while replacing
According to this stackoverflow topic it's not quite easy to make a replacement preserving case with simple pattern unless we have perl6's 'ii' modifier, but for practical purposes it mentions great solution like the following one:
Friday, 7 June 2013
Perl script to extract and present hex colors found in arbitrary text
The following script searches STDIN for 3 or 6 symbol hex values and prints a html structure that represents those values as colors on page.
To view example output hit "read more".
#!/usr/bin/perl -w
use Set::Scalar;
$uniqueColors = Set::Scalar->new;
while( defined( $_ = <STDIN> ) ){
while ( $_ =~/(#[a-fA-F0-9]{1,6})/g ){
$uniqueColors->insert( $1 )
}
}
print <<HEADER;
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<HTML>
<HEAD>
<TITLE>Found HEX colors</TITLE>
</HEAD>
<BODY>
HEADER
while ( defined( my $color = $uniqueColors->each ) ){
print "<p style=\"background: " . $color . "\">" . $color . "</p>\n"
}
print "</BODY>
</HTML>"
Used this one to parse color-theme-tangotango.el emacs color theme file.To view example output hit "read more".
Thursday, 31 January 2013
Useful onliner to make testing in Oracle SQL*Developer a little bit easier
This little script helps to test subroutines using SQL*Developer Run or Debug command. Just copy code from "Run PL/SQL" window and run the following onliner in a terminal. It uncomments legacy dbms_ouput code and extends capacity of varchar2 variables from 200 to 32767 chars. Now paste clipboard contents back into SQL Worksheet and run.
cat /dev/clipboard | perl -p -e 's/\/\* Legacy output://g; s/\*\///g; s/VARCHAR2\(200\)/VARCHAR2\( 32767 char \)/g;s/^\s+:.*$//g' > /dev/clipboard
Friday, 28 May 2010
Replace text in multiple files
A simple perl command to replace all occurencies of 'RESULT_FAILURE' with 'RESULT_FAIL' in all *.sql files in current directory:
perl -pi -e 's/RESULT_FAILURE/RESULT_FAIL/g' *.sql
perl -pi -e 's/RESULT_FAILURE/RESULT_FAIL/g' *.sql
Subscribe to:
Posts (Atom)