Use perl, python, php, shell, sed, awk, c to realize the flipping of strings

Original title: Q: There is a.txt file, the contents of which are as follows 1234569 abcABCabc requires awk to print out the following results 987654321 cbaCBAcba A: shell: [root@vps tmp]# rev a.txt 9654321 cbaCBAcbaperl: [root@vps tmp]# perl -nle ‘print scalar reverse $_;’ a.txt 9654321 cbaCBAcbaawk : [root@vps tmp]# awk ‘{num=split($0,arr,””);for(i=num;i>0;i–){printf arr[i];if(i==1) {printf “\n”}}}’ a.txt 9654321 cbaCBAcbaphp: [root@vps tmp]# php -r ‘$fp=fopen(“a.txt”,”r”); while(! feof($fp)){ echo strrev(fgets($fp,999));} echo “\n”;;’ 9654321 cbaCBAcbased: [root@vps tmp]# sed ‘/\n/!G ;s/\(.\)\(.*\n\)/&\2\1/;//D;s/.//’ a.txt 9654321 cbaCBAcba python: (one of the methods) >>> arr=’hello’>>>arr[::-1]‘olleh’ (Method 2) >>> str=’hello’>>> tmp=”>>> for s in reversed(str):… tmp+=s…>> > print tmpolleh reverse.h#ifndef _reverse_hint getLine(char s[],int limit);void reverse(char s[]);#endif int getLine(char s[],int limit){ int c,i ; for(i =0; ireverse.c#include “stdio.h”#include “/Users/chenqing/tmp/reverse.h”#define MAXLINE 1000/* reverse a string use c langusge*/int main(void){ int len; char line[MAXLINE]; if((len = getLine(line,MAXLINE)) > 0){ reverse(line); printf( “%s”,line); } return 0;} gcc reverse.c -o reverseQing:tmp chenqing$ echo “ChinaCache” |./reverseehcaCanihC The above is an example of using these implementations to realize string reversal under the terminal command line, haha, In fact, it is still cool to implement perl.

A comparison of decorator patterns in PHP, Python, and Javascript

Decorator Pattern, also known as Decorator Pattern, is a design pattern that dynamically adds new behavior to a class in the field of object-oriented programming. In terms of functionality, the decorator pattern is more flexible than subclassing, so that you can add some functionality to an object instead of the entire class. The decoration mode is very suitable for flexibly extending the function of the object, the following is the UML diagram of the decoration mode: For example, there is a technical forum where users communicate by leaving messages. Since the forum is full of acquaintances at the beginning, there is almost no need to review the content of the messages. The page for receiving messages can be as follows: class SaveMsg(){ private $msg; public function __construct($msg){ $this->msg=$msg; } public function __store(){ // store in database } } Later, as the forum became more and more famous, some people posted links on it, so it was necessary to filter the news containing links. The forum developed further and found that in addition to developing spam links, there were many useless spam. Later, there may be various abnormal posts such as attacks, so the management of forum posts can be managed…

What language is good for learning programming? Is it PHP, Python, or Ruby?

A simple one-sentence summary: 1. If you want to help him find a job as soon as possible and make money, recommend PHP. 2. If you want him to be an efficient engineer, Python is recommended. 3. If you want him to fall in love with his work, recommend Ruby. Language selection: Programming language is very important, don’t think that they are all Turing equivalent, they are all the same in use. In fact, good language can bring you things beyond imagination. Here are some thoughts: 1. The programmer’s time is far more valuable than the machine’s time: choose the language with the highest development efficiency, and don’t care too much about running performance. If you can’t develop something, it’s useless to run fast. 2. Elegant abstraction is better than simple stacking: This means that your code is the most concise and full of design, object-oriented, easy closure, everything is an expression, etc., and the best Abstraction means that the language itself can be layered, which can not only write the language, but the ability of DSL is an indicator. 3. Talented community beats difficult recruiting: the language must have an active and talented community, as long as the people…

Shell, Perl, Python, PHP access MySQL database code example

In the afternoon, I wrote a simple bash script to test the program, input a test case file, output the test cases and results that failed the test, and then save the results to the database. How to directly access the database in bash script? Since you can directly use the mysql command to operate the database in the shell, you should also be able to operate the database by calling mysql in the shell script. For example, use the following bash shell script to query the database: Bash The code is as follows: #!/bin/bash mysql -uvpsee -ppassword test <<EOFMYSQL select * from test_mark; EOFMYSQL If you need complex database operations, it is not recommended to use shell scripts. It is very convenient to operate the database with Perl/Python/PHP, and operate the database through the Perl DBI/Python MySQLdb/PHP MySQL Module interface respectively. Here are some simple examples of connecting and querying databases in these three different languages ​​(some unnecessary codes are deleted for simplicity and space reduction): Perl The code is as follows: #!/usr/bin/perl use DBI; $db = DBI->connect(‘dbi:mysql:test’, ‘vpsee’, ‘password’); $query = “select * from test_mark”; $cursor = $db->prepare($query); $cursor->execute; while (@row = $cursor->fetchrow_array) { print “@row\n”; } Python…

For the web, what will be the best future development prospect among Java, PHP, Python, and .NET?

Response content: The golden mean chooses Java, c#, and it should not starve to death. If you want to do other things, then use python and ruby, which are generally used by start-up companies. It’s not that Java and C# are bad, what’s wrong with the language, only whether it’s suitable or not, Java and C# developers are in great demand in China, even if they don’t write web, they can write other things. The so-called development, I think there are two points:1. The depth of language and related technologies. 2. Market share. For php, a little bit lies in the development efficiency. With it, you can quickly implement a website, but when your website background needs powerful services (such as large-scale e-commerce systems, search, etc.), php cannot satisfy you Yes, so you can see that companies using php will basically recruit engineers in other languages ​​(such as Baidu). It is impossible to implement the entire complex system simply using php. For Java, although it is not as efficient as php in web development, it has many enterprise-level frameworks and platforms. Some companies often do not want to hire specialized web development engineers and use java to develop systems, regardless…

A small chestnut compares the performance of golang, php, Node.js, Python, and Rust

Seeing the comparison of netizen toozyxia (https://my.oschina.net/xiayongsheng/blog/4775399), I had a sudden idea to increase the comparison of Node.js golang: package main import ( “fmt” “os” “reflect” “runtime/pprof” “runtime/trace” “strconv” “time” “unsafe” ) type CalcCollection struct { } func (c *CalcCollection) V0() { arr := map[string]int64{} for i := int64(0); i <1000000; i++ { value := time.Now().Unix() key : = strconv.FormatInt(i, 10) + "_" + strconv.FormatInt(value, 10) arr[key] = value } } func (c *CalcCollection) V1() { nums := int64(1000000) arr := make(map[string]int64, nums) // key, outside the loop, key can be reused := make([]byte, 0) for i := int64(0); i <nums; i++ { key = key [:0] value := time.Now().Unix() // Use appendInt instead to remove the overhead of converting []byte to string inside strconv key = strconv.AppendInt(key, i, 10) key = append(key, '_') key = strconv.AppendInt(key, value, 10) keyStr := string(key) arr[keyStr] = value } } func (c *CalcCollection) V2() { nums := int64(1000000) arr : = make(map[string]int64, nums) // calculate the key length, and apply to save all keys []byte keyLen := int64(len(strconv.FormatInt(nums, 10)) + 1 + 10) totalLen := keyLen * nums key := make([]byte, totalLen) for i := int64(0); i <nums; i++ { value := time.Now().Unix()…

What are the characteristics or advantages of PHP, Java, Python, C, and C++ programming languages?

What are the characteristics or advantages of PHP, Java, Python, C, and C++ programming languages? phpjavapythonCC++ phpAs we all know, PHP language, as a scripting language for server-side development, is very famous in website development. Since the creation of Rasmus Lerdorf in 1995, according to the W3Techs survey, PHP has accounted for 82% of the known server-side programming languages. Among them are well-known technology companies such as WordPress and Facebook. The release of PHP7 in 2015 has greatly improved performance and made PHP more powerful. Like all technology, though, it has mixed reviews, with some people liking it and some not. Today, Dane PHP experts (http://PHP.tedu.cn) will analyze the advantages and disadvantages of the PHP language with you. Advantage 1: Popular and easy to use PHP is by far the most popular programming language, there is no doubt about it. It drives more than 200 million websites around the world, and more than 81.7% of public websites in the world use PHP on the server side. Not only that, according to statistics, 78.1% of people who are engaged in PHP think that PHP is the easiest to learn and use. This is because the data structures commonly used in PHP…

How Java, PHP, Python, JS and other developers draw statistical graphs

How Java, PHP, Python, JS and other developers draw statistical graphs

Abstract: At present, many programmers basically use the back-end to generate data and pass it to the front-end, and then the front-end renders the data to the drawing library for display, so as to get the last we see. However, sometimes we find that there is a lot of data that needs to be transmitted. At this time, if the data is transmitted to the front end for analysis and display, it will be very slow. Therefore, it is necessary to generate various statistical graphs at the back end. The following Let’s talk about how various programmers make pictures? PHP programmers who have made statistical charts with PHP should know that JqGraph is the golden partner of PHP. With JqGraph, we can complete many charts, such as scatter charts, histograms, line charts, stock trend charts, and pie charts. Wait, and the library already supports PHP7, so we can use it with confidence. At present, many programmers basically use the back-end to generate data and pass it to the front-end, and then the front-end renders the data to the drawing library for display, so as to get the various pictures we see last, but sometimes, we find that There is a…

How to choose Java, Python, C++, PHP, Javascript 5 major programming languages

How to choose Java, Python, C++, PHP, JavaScript 5 programming languages

This article mainly introduces how to choose Java, Python, C++, PHP, Javascript 5 major programming languages. It has certain reference value. Interested friends can refer to it. I hope that after reading this article, There is a lot to gain, let the editor take everyone to understand together. Before I help you solve this problem, let’s take a look at what these five languages ​​are used for? This may help you make a decision faster! 1.Java What Java can do: Android and IOS application development , video game development, desktop GUI, software development, etc.; Java has the characteristics of cross-platform, object-oriented, and generic programming, and is very popular with enterprises. It is widely used in enterprise-level Web application development and mobile application development. Java has developed to the present, and it is mainly divided into three major blocks according to applications: J2SE, J2ME, and J2EE. The application ranges of the three blocks are different, but they complement each other. Widely used in PCs, data centers, game consoles, scientific supercomputers, mobile phones and the Internet, and has a global developer community. Java has developed along with the rapid development of the Internet and has gradually become an important network programming language.…

bubble sort animation

Top Ten Classic Sorting Algorithms – Bubble Sort (implemented in Java, JavaScript, PHP, Python, Go language)

Top Ten Classic Sorting Algorithms——Bubble Sort This article mainly introduces “bubble sorting” among the top ten classic sorting algorithms, and attaches the Java, Javascript, PHP, Python, and Go language implementations of the bubble sorting algorithm. 1. Introduction to the top ten classic sorting algorithms Sorting algorithms can be divided into internal sorting and external sorting. Internal sorting means that data records are sorted in memory, while external sorting is because the sorted data is too large to accommodate all the sorting records at a time. During the sorting process, it needs to be accessed External storage. Common internal sorting algorithms include: insertion sort, Hill sort, selection sort, bubble sort, merge sort, quick sort, heap sort, radix sort, etc. 2. Comparison of ten classic sorting algorithms Note: about time complexity 1. Square order (O(n2)) sorting All kinds of simple sorting: direct insertion, direct selection and bubble sorting. 2. Linear logarithmic order (O(nlog2n)) sorting Quick sort, heap sort and merge sort. 3. O(n1+§)) sorting, where § is a constant between 0 and 1. Hill sort. 4. Linear order (O(n)) sorting Radix sorting, in addition to bucket and box sorting. Note: about stability Stability: The order of 2 equal key values ​​after sorting…

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索