You have to escape some special characters and not others:
Escape special pluses, capturing parentheses and literal $
use \1 for the captured strings.
A piggy bank of commands, fixes, succinct reviews, some mini articles and technical opinions from a (mostly) Perl developer.
When your clever crontab entry doesn't work:
/bin/sh: -c: line 0: unexpected EOF while looking for matching `"'
/bin/sh: -c: line 1: syntax error: unexpected end of file
You might need to escape some characters, like the percent sign: \%
Also consider that the backslash may not have the desired effect if it's inside double quotes.
# Format number with up to 8 leading zeroes
$result = sprintf("%08d", $number);
# Round number to 3 digits after decimal point
$rounded = sprintf("%.3f", $number);
Perl's sprintf
permits the following universally-known conversions:
%% a percent sign
%c a character with the given number
%s a string
%d a signed integer, in decimal
%u an unsigned integer, in decimal
%o an unsigned integer, in octal
%x an unsigned integer, in hexadecimal
%e a floating-point number, in scientific notation
%f a floating-point number, in fixed decimal notation
%g a floating-point number, in %e or %f notation
use Test::More tests => 23;
# or
use Test::More qw(no_plan);
ok($got eq $expected, $test_name);
like ($got, qr/expected/, $test_name);
is_deeply($got_complex_structure, $expected_complex_structure, $test_name);
eq_or_diff $got, $expected, "description"Test::Lazy
# Will evaluate the code and check it:
try('qw/a/' => eq => 'a');
# Don't evaluate, but still compare:
check(1 => is => 1);
use DBI;
@driver_names = DBI->available_drivers;
%drivers = DBI->installed_drivers;
@data_sources = DBI->data_sources($driver_name, \%attr);
$dbh = DBI->connect($data_source, $username, $auth, \%attr);
$rv = $dbh->do($statement);
$rv = $dbh->do($statement, \%attr);
$rv = $dbh->do($statement, \%attr, @bind_values);
$ary_ref = $dbh->selectall_arrayref($statement);
$hash_ref = $dbh->selectall_hashref($statement, $key_field);
$ary_ref = $dbh->selectcol_arrayref($statement);
$ary_ref = $dbh->selectcol_arrayref($statement, \%attr);
@row_ary = $dbh->selectrow_array($statement);
$ary_ref = $dbh->selectrow_arrayref($statement);
$hash_ref = $dbh->selectrow_hashref($statement);
$sth = $dbh->prepare($statement);
$sth = $dbh->prepare_cached($statement);
$rc = $sth->bind_param($p_num, $bind_value);
$rc = $sth->bind_param($p_num, $bind_value, $bind_type);
$rc = $sth->bind_param($p_num, $bind_value, \%attr);
$rv = $sth->execute;
$rv = $sth->execute(@bind_values);
$rv = $sth->execute_array(\%attr, ...);
$rc = $sth->bind_col($col_num, \$col_variable);
$rc = $sth->bind_columns(@list_of_refs_to_vars_to_bind);
@row_ary = $sth->fetchrow_array;
$ary_ref = $sth->fetchrow_arrayref;
$hash_ref = $sth->fetchrow_hashref;
$ary_ref = $sth->fetchall_arrayref;
$ary_ref = $sth->fetchall_arrayref( $slice, $max_rows );
$hash_ref = $sth->fetchall_hashref( $key_field );
$rv = $sth->rows;
$rc = $dbh->begin_work;
$rc = $dbh->commit;
$rc = $dbh->rollback;
$quoted_string = $dbh->quote($string);
$rc = $h->err;
$str = $h->errstr;
$rv = $h->state;
$rc = $dbh->disconnect;
Format Specifier | Type |
---|---|
%d (or %i) | int |
%c | char |
%f | float |
%lf | double |
%s | string |
%x | hexadecimal |
Don't do this. Just use strcat() and strncpy() instead.
#include <stdlib.h>
char* concat(char*, char*);
int main (int argc, char** argv)
{
char *x = "something";
char *y = " completely different.";
char *combined = concat(x, y);
printf("And now for %s\n", combined);
}
char* concat(char *a, char *b)
{
char *target = malloc( strlen(a) + strlen(b) + 1 );
strcpy(target,a);
strcat(target,b);
return target;
}
i=$(( i + 1 ))See http://www.softpanorama.org/Scripting/Shellorama/arithmetic_expressions.shtml
let i+=1
show table status
SET profiling = 1;
SETprofiling_history_size = 100; -- maximum is 100
SHOW PROFILES; -- shows a list of recent commands
SHOW PROFILE; -- shows a very detailed breakdown of time spent on each database task
For example, if a lot of time is spent 'Sending data', try improving your indexes.http://dev.mysql.com/doc/refman/5.0/en/show-profiles.html