Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

netsds::util::string(3pm) [debian man page]

NetSDS::Util::String(3pm)				User Contributed Perl Documentation				 NetSDS::Util::String(3pm)

NAME
NetSDS::Util::String - string prcessing routines SYNOPSIS
use NetSDS::Util::String qw(); # Read from standard input my $string = <STDIN>; # Encode string to internal structure $string = string_encode($tring); DESCRIPTION
"NetSDS::Util::String" module contains functions may be used to quickly solve string processing tasks like parsing, recoding, formatting. As in other NetSDS modules standard encoding is UTF-8. EXPORTED FUNCTIONS
str_encode($str[, $encoding]) - encode string to internal UTF-8 By default this function treat first argument as byte string in UTF-8 and return it's internal Unicode representation. In case of external character set isn't UTF-8 it should be added as second argument of function. # Convert UTF-8 byte string to internal Unicode representation $uni_string = str_encode($byte_string); # Convert KOI8-U byte string to internal $uni_string = str_encode($koi8_string, 'KOI8-U'); After "str_encode()" it's possible to process this string correctly including regular expressions. All characters will be understood as UTF-8 symbols instead of byte sequences. str_decode($str[, $encoding]) - decode internal UTF-8 to byte string By default this function treat first argument as string in internal UTF-8 and return it in byte string (external) representation. In case of external character set isn't UTF-8 it should be added as second argument of function. # Get UTF-8 byte string from internal Unicode representation $byte_string = str_decode($uni_string); # Convert to KOI8-U byte string from internal Unicode $koi8_string = str_encode($uni_string, 'KOI8-U'); It's recommended to use "str_encode()" when preparing data for communication with external systems (especially networking). str_recode($str, $FROM_ENC[, $TO_ENC]) - recode string Translate string between different encodings. If target encoding is not set UTF-8 used as default one. str_trim($str) - remove leading/trailing space characters $orig_str = " string with spaces "; $new_str = str_trim($orig_str); # Output: "string with spaces" print $new_str; str_trim_left($str) - removes leading whitespaces This function is similar to "str_trim()" except of it removes only leading space characters and leave trailing ones. str_trim_right($str) - removes trailing whitespaces This function is similar to "str_trim()" except of it removes only trailing space characters and leave leading ones. str_clean($str) - clean string from extra spaces Function is similar to "str_trim()" but also changes all spacing chains inside string to single spaces. str_camelize($strin) If pass undef - return undef. If pass '' - return ''. Examples: # returns 'getValue' str_camelize( 'get_value' ) # returns 'addUserAction' str_camelize( 'ADD_User_actION' ) str_decamelize(...) If pass undef - return undef. If pass '' - return ''. Examples: # returns 'get_value' str_decamelize( 'getValue' ) EXAMPLES
None yet BUGS
Unknown yet TODO
Implement examples and tests. SEE ALSO
Encode, perlunicode AUTHORS
Valentyn Solomko <pere@pere.org.ua> Michael Bochkaryov <misha@rattler.kiev.ua> perl v5.12.4 2011-08-27 NetSDS::Util::String(3pm)

Check Out this Related Man Page

NetSDS::Util::File(3pm) 				User Contributed Perl Documentation				   NetSDS::Util::File(3pm)

NAME
NetSDS::Util::File - file related utilities SYNOPSIS
use NetSDS::Util::File qw(file_read); my $passwd = file_read('/etc/passwd'); file_move('/etc/passwd', '/tmp/find_this'); DESCRIPTION
"NetSDS::Util::File" module contains some routines for files and directories processing tasks like creating, reading, writing, copying and moving files and catalogs. This module of cource uses such well known things like File::Spec, File::Path, File::Copy and others. EXPORTED FUNCTIONS
is_handle($var) - check if argument is a file handle Paramters: some variable Returns: 1 if it's file handle or undef otherwise if (is_handle($var)) { reset_handle($fh); } reset_handle($fh) - reset file handle Paramters: file handle Returns: nothing This function tries to set filehandle to begin of file and set binmode on it. my $fh = file_open('/etc/passwd'); ... do something with file ... reset_handle($fh); # We can read it from the beginning file_open($file) - open file Paramters: file name or file handle Returns: file handle This function provides unified API for opening files. my $f = file_open('/etc/passwd'); file_read($file) - read file to scalar Paramters: file name or file handle Returns: scalar content of file This function provides ability to read file content to scalar variable. my $data = file_read('/etc/passwd'); print "Passwords file: $data "; file_write($file, $data) - write scalar data to file Paramters: file name or open file handle Returns: length of written data or undef in case of error my $data = 'This should be file'; file_write('/tmp/file.dat', $data); file_copy($in_file, $out_file) - copy file Paramters: input file name, output file name Returns: This function copy file to new location. file_move($in_file, $out_file) - move file Paramters: input file name, output file name Returns: 1 or undef This function moves old file to new location. file_temp($dir) - create temporary file Creates new temp file and return its handle dir_create($dir) - create directory with parents Paramters: directory name Returns: directory name or undef # Will create all parent catalogs if necessary dir_create('/var/log/NetSDS/xxx'); dir_delete($dir) - remove directory recursive Paramters: directory name Returns: dir name or undef if error print "We need no libs!"; dir_delete('/usr/lib'); dir_read($dir, $ext) - read files list from catalog Paramters: directory name, extension of files to read Returns: list of files in catalog my @logs = @{ dir_read('/var/log/httpd', 'log') }; print "Logs are: " . join (', ', @logs); dir_read_recursive($dir, $ext, [$res]) - read all files list recursive Paramters: $start catalog, $extension Returns: list of files with extension from parameters my $tpls = dir_read_recursive('/etc/NetSDS', 'tmpl'); foreach my $tpl (@$tpls) { pritn "Template: $tpl "; } exec_external($prog, [$param1, ... $paramN]) - execute external program Paramters: pragram name, arguments list (see perldoc -f system) Returns: 1 if ok, undef otherwise This function calls system() with given parameters and returns 1 if everything happened correctly (program executed and returned correct result). if (exec_external('/bin/rm', '-rf', '/')) { print "Hey! We removed the world!"; } EXAMPLES
None yet BUGS
Unknown yet SEE ALSO
IO::Handle, IO::Scalar, IO::File, File::Spec, File::Copy, File::Path, system() TODO
1. Implement more detailed error handling AUTHOR
Valentyn Solomko <pere@pere.org.ua> Michael Bochkaryov <misha@rattler.kiev.ua> perl v5.12.4 2011-08-27 NetSDS::Util::File(3pm)
Man Page