小编Ant*_*ton的帖子

MySQL:创建数据库吗?

在MySQL中我想克隆某些数据库.有没有这样的事情

CREATE DATABASE LIKE <template database here>
Run Code Online (Sandbox Code Playgroud)

命令?
我知道,有

CREATE TABLE LIKE 
Run Code Online (Sandbox Code Playgroud)

mysql

8
推荐指数
1
解决办法
2万
查看次数

C从配置文件中读取值

我需要帮助从配置文件中读取端口.该行看起来像:PORT = 8888

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>


int main(int ac, char **av)
{

        char buf[256];
        FILE *file = NULL;
        char hostlist[256] = "";
        int port = 8080; /* default not from config */
        int i = 0;
Run Code Online (Sandbox Code Playgroud)
  // open file
  // some feof code   
Run Code Online (Sandbox Code Playgroud)

[..]

        strcpy(hostlist,buf);
        if (strstr(buf,"PORT")) {      /* buf[0-3] = */
                printf("%c\n",buf[5]); /* PORT=8888 */
                printf("%c\n",buf[6]);
                printf("%c\n",buf[7]);
                printf("%c\n",buf[8]);
Run Code Online (Sandbox Code Playgroud)

这按预期工作^^但是,当尝试复制到缓冲区时,我没有得到任何端口或我得到默认端口.

                for(i=4;i<9;i++) {
                while (buf[i] != '\n') {
                port += buf[i++];
                printf("buf:%c\n",buf[i]);
                }
                }
                printf("port=%d\n",port);
        } …
Run Code Online (Sandbox Code Playgroud)

c parsing config

0
推荐指数
1
解决办法
3580
查看次数

在Perl中,如何将文件内容读入数组?

可能重复:
打开文本文件并使用Perl将其读入数组的最简单方法

我是Perl的新手,并希望每个文件在一个单独的数组中推送该文件的内容,我设法通过以下方式执行此操作,它使用if语句.但是,对于我的阵列,我想要1美元.那可能吗?

#!/usr/bin/perl

use strict;
my @karray;
my @sarray;
my @testarr = (@sarray,@karray);
my $stemplate = "foo.txt";
my $ktemplate = "bar.txt";
sub pushf2a  {
  open(IN, "<$_[0]") || die;
  while (<IN>) {
    if ($_[0] eq $stemplate) {
      push (@sarray,$_);
    } else {
      push (@karray,$_);
    } 
  }
  close(IN) || die  $!;
}
&pushf2a($stemplate,@sarray);
&pushf2a($ktemplate,@karray);
print sort @sarray;
print sort @karray;
Run Code Online (Sandbox Code Playgroud)

我想要这样的东西:

#!/bin/sh
myfoo=(@s,@k)
barf() {
  pushtoarray $1
}
barf @s
barf @k
Run Code Online (Sandbox Code Playgroud)

perl

0
推荐指数
2
解决办法
5199
查看次数

标签 统计

c ×1

config ×1

mysql ×1

parsing ×1

perl ×1