1 / 3
Caption Text
2 / 3
Caption Two
3 / 3
Caption Three margin testing

Friday, July 24, 2009

Perl String Functions

String Functions

Perl provides a very useful set of string handling functions:

The first set of functions that we'll look at are those that deal with strings. These functions let you determine a string's length, search for a sub-string, and change the case of the characters in the string, among other things.

Here are Perl's string functions:

  • chomp(STRING) OR chomp(ARRAY) -- Uses the value of the $/ special variable to remove endings from STRING or each element of ARRAY. The line ending is only removed if it matches the current value of $/.
  • chop(STRING) OR chop(ARRAY)-- Removes the last character from a string or the last character from every element in an array. The last character chopped is returned.
  • chr(NUMBER) -- Returns the character represented by NUMBER in the ASCII table. For instance, chr(65) returns the letter A.
  • crypt(STRING1, STRING2) -- Encrypts STRING1. Unfortunately, Perl does not provide a decrypt function.
  • index(STRING, SUBSTRING, POSITION) -- Returns the position of the first occurrence of SUBSTRING in STRING at or after POSITION. If you don't specify POSITION, the search starts at the beginning of STRING.
  • join(STRING, ARRAY) -- Returns a string that consists of all of the elements of ARRAY joined together by STRING. For instance, join(">>", ("AA", "BB", "cc")) returns "AA>>BB>>cc".
  • lc(STRING) -- Returns a string with every letter of STRING in lowercase. For instance, lc("ABCD") returns "abcd".
  • lcfirst(STRING) -- Returns a string with the first letter of STRING in lowercase. For instance, lcfirst("ABCD") returns "aBCD".
  • length(STRING) -- Returns the length of STRING.
  • rindex(STRING, SUBSTRING, POSITION) -- Returns the position of the last occurrence of SUBSTRING in STRING at or after POSITION. If you don't specify POSITION, the search starts at the end of STRING.
  • split(PATTERN, STRING, LIMIT) -- Breaks up a string based on some delimiter. In an array context, it returns a list of the things that were found. In a scalar context, it returns the number of things found.
  • substr(STRING, OFFSET, LENGTH) -- Returns a portion of STRING as determined by the OFFSET and LENGTH parameters. If LENGTH is not specified, then everything from OFFSET to the end of STRING is returned. A negative OFFSET can be used to start from the right side of STRING.
  • uc(STRING) -- Returns a string with every letter of STRING in uppercase. For instance, uc("abcd") returns "ABCD".
  • Ucfirst(STRING) -- Returns a string with the first letter of STRING in uppercase. For instance, ucfirst("abcd") returns "Abcd".

Note As a general rule, if Perl sees a number where it expects a string, the number is quietly converted to a string without your needing to do anything.

Note Some of these functions use the special variable $_ as the default string to work with. More information about $_ can be found in Chapter on Files, and the Chapter Special Variables.

The next few sections demonstrate some of these functions. After seeing some of them work, you'll be able to use the rest of them.

Example: Changing a String's Value

Frequently, I find that I need to change part of a string's value, usually somewhere in the middle of the string. When this need arises, I turn to the substr() function. Normally, the substr() function returns a sub-string based on three parameters: the string to use, the position to start at, and the length of the string to return.

$firstVar = substr("0123BBB789", 4, 3);
print("firstVar = $firstVar\n");

This program prints:

firstVar = BBB

The substr() function starts at the fifth position and returns the next three characters. The returned string can be printed like in the above example, as an array element, for string concatention, or any of a hundred other options.

Things become more interesting when you put the substr() function on the left-hand side of the assignment statement. Then, you actually can assign a value to the string that substr() returns.

$firstVar = "0123BBB789"; substr($firstVar, 4, 3) = "AAA";
print("firstVar = $firstVar\n");

This program prints:

firstVar = 0123AAA789

Example: Searching a String

Another useful thing you can do with strings is search them to see if they have a given sub-string. For example if you have a full path name such as

"C:\\WINDOWS\TEMP\WSREWE.DAT",

you might need to extract the file name at the end of the path. You might do this by searching for the last backslash and then using substr() to return the sub-string.

Note The path name string has double backslashes to indicate to Perl that we really want a backslash in the string and not some other escape sequence, search.pl

$pathName = "C:\\WINDOWS\\TEMP\\WSREWE.DAT";
$position = rindex($pathName, "\\") + 1;
$fileName = substr($pathName, $position);
print("$fileName\n");

This program prints:

WSREWE.DAT

If the third parameter-the length-is not supplied to substr(), it simply returns the sub-string that starts at the position specified by the second parameter and continues until the end of the string specified by the first parameter.

Thursday, July 23, 2009

Adobe Releases Beta Text Layout Framework

Adobe Releases Beta Text Layout Framework
by Jennifer Farley

logo_flashplayerThis week, Adobe announced the beta release of the Text Layout Framework, an extensible library, built on the new text engine in Adobe Flash Player 10. This will allow developers and designers to use more sophisticated typography layouts in Web applications. The framework is intended for use with Adobe Flash CS4 Professional or Adobe Flex, and is included in the next version of Flex, code named Gumbo.

Layout

The Text Layout Framework delivers multi-lingual, print-quality typography for the web, including support for:

  • Bidirectional text, vertical text and over 30 writing systems including Arabic, Hebrew, Chinese, Japanese, Korean, Thai, Lao, the major writing systems of India, and others
  • Selection, editing and flowing text across multiple columns and linked containers, and around inline images
  • Vertical text, Tate-Chu-Yoko (horizontal within vertical text) and justifier for East Asian typography
  • Rich typographical controls, including kerning, ligatures, typographic case, digit case, digit width and discretionary hyphens
  • Cut, copy, paste, undo and standard keyboard and mouse gestures for editing
  • Rich developer APIs to manipulate text content, layout, markup and create custom text components

While this might be especially of interest to developers (because it looks like there is a bit of hard work behind the scenes to use it), for designers it means that online typography design is coming closer to what can be achieved in print. On the Adobe website you can test out eight examples of how you can manipulate and control text. Examples include working with columns, text effects, linked containers, ligatures and graphics. On first impression, the ability to work with text like this feels a little bit like InDesign "lite," which is very exciting if you love type and are frustrated with current limitations on the web. You can play with the examples here.

LayoutEffects

You can also try out the Text Editor Layout Demo
.
To see Text Layout Framework in action, some sites that are using the technology are the New York Times Reader demo, the Boston Globe Reader and Makebook.

Aspell and Kevin's English Word List

GNU Aspell is a Free and Open Source spell checker designed to eventually replace Ispell. It can either be used as a library or as an independent spell checker. Its main feature is that it does a superior job of suggesting possible replacements for a misspelled word than just about any other spell checker out there for the English language. Unlike Ispell, Aspell can also easily check documents in UTF-8 without having to use a special dictionary. Aspell will also do its best to respect the current locale setting. Other advantages over Ispell include support for using multiple dictionaries at once and intelligently handling personal dictionaries when more than one Aspell process is open at once.

Try it out for your self using the Aspell Spell Helper or see some Test Results Comparing Aspell with other spell checkers.

Kevin's Word List Page contains links to various Word Lists and related information. They are intended to be suitable for use in spell checkers. However, I am sure they will have numerous other uses as well.

Links to other General Word Lists

Links to Online Dictionaries

Links to Slang Word Lists and Dictionaries

Links to Specialty Word Lists and Dictionaries

Other Links

Wednesday, July 22, 2009

New Coalition To Promote OSS To Feds

Slashdot Linux Story | New Coalition To Promote OSS To Feds

"Red Hat, Mozilla, Novell, Oracle, and Sun are among the 50-plus member Open Source for America coalition that will be officially announced today by Tim O'Reilly at OSCON. The OSA will be a strong advocate for free and open source software, and plans to boost US Federal government support and adoption of FOSS. From their website: 'The mission of OSA is to educate decision makers in the US Federal government about the advantages of using free and open source software; to encourage the Federal agencies to give equal priority to procuring free and open source software in all of their procurement decisions; and generally provide an effective voice to the US Federal government on behalf of the open source software community, private industry, academia, and other non-profits.'"

Tuesday, July 21, 2009

Google Expert Tips: How to Find Anything Fast

Google Expert Tips: How to Find Anything Fast
July 21, 2009 10:30 AM ET

PC World - The nice people at Google have invented multiple ways to make their core product --Internet search--even better. The tips and tricks below will help you improve the precision of the search results Google provides--and use far fewer keystrokes to get them.

Get to know search operators: Google made its name by delivering powerful search results in response to queries of any level of sophistication, but learning to use Google's search operators can really hone your Google-fu. The Google Help Cheat Sheet rounds up some of the finest, such as define: (for quick dictionary lookups), site: (to return results from a specific Web site), and OR (as in 'pc OR world').

Convert nearly any measurement: Aside from working as a simple calculator, Google is also a great tool for converting units of measure. Need to know how many ounces are in a cup? Enter ounces in a cup in Google. Or try something exotic, like how many furlongs are in a league. Google can handle it.

Narrow down your results: Usually you can find what you're looking for on the first page of Google results, but if you need something very specific--say, a page that was published in the last 24 hours--click the new Show Options link above your search results. Among other features available is the interactive Wonder Wheel, a spidering graphical representation of queries related to yours.

Navigate results from your keyboard: Google's Experimental Search page is full of fun experiments from the search giant. One of the best is the Keyboard shortcuts experiment, which adds Gmail-like keyboard shortcuts to Google search results; for example, pressing 'j' or 'k' moves you up or down, respectively, between results.

Find a killer desktop wallpaper: Google Image Search is a familiar go-to resource for users seeking new wallpaper, but finding wallpaper that fits your desktop is much easier than you may realize. Go to the Google Advanced Image Search page, and click Use my desktop size link to automatically search for images that exactly fit your desktop dimensions.

Square your results: If you're a hardcore data nerd, give Google Squared a try. This new search tool returns results as structured data in a spreadsheet to help you get a bird's-eye view of the data contained in the results. Search for 'DSLR cameras', for example, to compare and contrast prices and resolutions for digital SLRs.

Developer's Choice: Quick Local Searches

"I'm really happy with how easy it is to use local search on Google. Just search for the kind of store you want--restaurants, for example. We guess your location, and show restaurants near you. It's one of my favorite of our lesser known search tips: www.google.com/landing/searchtips."

--Jim Muller, Google software engineer

国产MYSQL数据库开源备份利器—帝国备份王

占奇博客
作者:admin 发表时间:07月 - 21 - 2009 5 views

写博客的同学都知道,MYSQL数据库备份这项工作既十分麻烦但又非常重要。麻烦的是要在phpmyadmin上点击一大堆按钮。重要的是保证在你的主机提供商跑路的那一天,你手里还一分数据库备份。但是用phpmyadmin备份数据通常有下面几个缺点:
1、如果你的MYSQL数据库太大了,phpmyadmin将很难导出你的数据库;
2、备份的数据重新导入新的数据库后通常会出现编码乱码问题;
3、不同MYSQL版本数据不能互导问题,万一你的新空间和你的老空间MYSQL版本不同的话,你可能会很麻烦了。

然而这个三个大问题,都让国产的开源软件——帝国备份王给完美解决了,废话少说,下面教大家怎么在你的空间上安装《帝国备份王》:

第1步:上传程序包
点击这里下载帝国备份王安装包,解压。在你的空间的根目录建立一个backup文件夹。将安装包的 upload 目录中的"全部文件和目录"全部上传到backup文件夹。

第2步:设置服务器777属性
设置目录属性您在正式使用以前,需要设置相关的目录属性,以便数据文件可以被《帝国备份王》正确的读写。使用 FTP 软件登录您的服务器,将服务器backup文件夹里的以下文件或目录属性设置为 777,见下:
目录文件名称
说明
bdata 备份目录
bdata/safemod 安全模式下数据备份目录
class/config.php 配置文件
setsave 保存设置目录
setsave/def 默认备份设置文件
zip 压缩包存放目录
tmp 临时文件目录

第3步:登陆后台
在浏览器中访问 http://您的域名/backup/index.php,就可以安装成功并可以立即访问后台了。
(后台默认的管理员帐号与密码分别为:admin , 123456)
登陆后自己修改帐号密码与数据库设置即可完成安装。

错误纠正:安装的过程中,如果你的空间没有开启"short-tag"支持的话,会出错,请开启这个服务。

后台使用说明
登录后台后即可轻松使用轻松备份和恢复数据
1.备份数据:备份数据 -> 选择备份的数据库 -> 选择备份的表与设定备份参数 -> 备份完毕
2.恢复数据:恢复数据 -> 选择恢复源目录,数据库 -> 恢复完毕
3.下载备份文件:下载备份目录下相应的备份目录即可。默认的备份目录为"bdata"。(对于文件少的也可直接到"管理备份目录"打包下载)

相关信息和演示
帝国备份王官方网站:http://www.phome.net/
本人安装成功的帝国备份王:http://zhanqi.s202.xrea.com/backup/index.php

Monday, July 20, 2009

Offisync - Using Google Docs from MS Office 2007



The idea behind OffiSync

The idea to build OffiSync came to me when I was told that many Google Docs and Google Apps users also use Microsoft Office.

I decided to learn more about why would people use both products at the same time? Why not switch from the expensive Microsoft Office to the free / Cheap Google Docs / Google Apps alternative?

So I started asking around, I talked to a Gartner analyst, a general manager in a fortune 500 company, a good friend that is a CEO of a start up company and about a dozen other users who all gave me more or less the same answer:

"We like using Office for content creation and editing, but then, when we need to collaborate with others we upload the document to Google Docs so we can work with others and see changes and edits in real time. We also like keeping the files online so we can access them when we are not in front of our own computer"

So I decided to try it myself and do the same. It is then that I realized 2 very important facts:
- Google Docs is an amazing service
- Working with Office and Google docs in the scenario mentioned above seemed to almost be impossible and was very cumbersome. It took so much time to take a file I created in PowerPoint or Word and make it available online so I could collaborate with my co-workers....

So being an adventurous person, I decided to solve the problem for myself and for all those who use both Microsoft Office and Google docs and started OffiSync.

The idea we had when we started was very simple: enable users to keep using the leading desktop productivity suite, MS Office, and super charge it with the online and collaborative power of Google. We envisioned the integration between Office and Google Docs to feel very natural and almost as if they came from the same vendor.

So that's what we did....

Once you install OffiSync, you will get a tight integration between Office and Google Docs that will help you do the following:

* Save your Office files on Google docs just as if you were saving them locally. From that moment, you can access them from any computer using the browser only OR use Office to access those files when you use your own computer, just as if they were stored locally
* Use Google Search, integrated into the OffiSync toolbar, to find your documents in seconds (I love this feature!! )
* Share and collaborate with others by combining Office and Google Docs collaboration features. OffiSync will let you save a document online and add collaborators right from within the Office toolbar.


But then I started thinking, why stop here, why not build more "google features into MS Office" and that became the longer term plan for this product. We are now working to put more Google features such as Google maps integration, Google images and Google App Engine to make some magic with Office.

Let us know what you think! contact@offisync.com

You can also follow us on www.twitter.com/offisync
Posted by Oudi Antebi at 12:11 PM 16 comments

Featured Post

Windows和Ubuntu双系统完全独立的安装方法

http://www.ubuntuhome.com/windows-and-ubuntu-install.html  | Ubuntu Home Posted by Snow on 2012/06/25 安装Windows和Ubuntu双系统时,很多人喜欢先安装windows,然...