关注perl
Dec 25
个人感觉perl获取文件名最方便的方法Basename 模块的使用方法
how-to-get-perl-file-name-quick
问题:如何将一个文件的所在路径,文件名称,文件后缀区分开?比如 abc.pl 如何单独获取abc 和 pl 呢
方案:使用perl - File:Basename 模块
说明:在perl脚本中,使用use File::Basename模块后,可以调用三种常用的函数:fileparse, basename, dirname.
1. fileparse: 输入参数全路径名称和后缀列表;返回三个值:文件名,路径,后缀,并存放在列表中。
2. basename: 输入参数全路径名称和后缀列表; 返回文件名
3. dirname: 输入参数全路径名称; 返回文件路径
示例:
#! /usr/bin/perl

use strict;
use warnings;
use File::Basename;

my $fullname='/home/perl/perl_basename.pl';
my @suffixlist=qw(.pl .txt .sv .v);
my ($name, $path, $suffix)=fileparse($fullname, @suffixlist);

print "name=$name\n";
print "path=$path\n";
print "suffix=$suffix\n";

$name=fileparse($fullname, @suffixlist);
print "name=$name\n";

my $Basename=basename($fullname, @suffixlist);
print "Basename=$Basename\n";

my $dirname = dirname($fullname);
print "dirname=$dirname\n";
执行上述脚本,得到下面的结果:

name=perl_basename
path=/home/perl/
suffix=.pl
name=perl_basename
Basename=perl_basename
dirname=/home/qilzhao
from:https://www.cnblogs.com/qixinsoc365/p/4346710.html
Tags:
Dec 25
Perl: 同时在屏幕和文件打印输出的3种实现方式
第一种方式:Perl 代码实现:
#!/usr/bin/perl
 
use strict;
use warnings;
use diagnostics;
 
open(LOG, '>', 'LOG_FILE') or die "Can't redirect stdout: $!";
open(CMD, 'ls |');
open(STDERR, '>&', STDOUT) or die "Can't redirect stderr: $!";
open(STDERR, '>', 'LOG_FILE') or die "Can't redirect stderr: $!";
print "LOG_FILE\n";
while (<CMD>) {
    &lprint ($_)
}
 
sub lprint {
      my ($line) = @_;
      print LOG $line;  
      print $line;
}
 
close(CMD) or die "close CMD failed: $!";
 
exit(1);

第二种方式:利用Perl的Tee模块:
#!/usr/bin/perl
use IO::Tee; 
$tee = IO::Tee->new(">> log.txt", \*STDOUT); 
print $tee "Log on ".scalar(localtime)."\n";

或者
#!/usr/bin/perl
open (STDOUT, "| tee -ai log.txt");
print "Log on ".scalar(localtime)."\n";
close (STDOUT);

这个方式最方便 tee -ai log.txt 且默认不用额外安装其他插件
how-perl-log-on-screen-and-file
---end
Tags:
Jan 2

windows下安装dmake

How to install dmake
    1、Download and install ActivePerl
    2、Open Command Prompt
    3、Type ppm install dmake
   tips:如何运行ppm install dmake 异常,可以参考文章http://itlife365.com/blog/post/os-windowxp-dos-http_proxy.php 设置http_proxy代理进行联网下载

Tags: ,
Jan 2

perl通过环境变量解决路径中包含中文名的问题,通过环境变量修改ppm的默认路径即可

C:\>set ACTIVEPERL_PPM_HOME=C:\perl\temp
C:\>ppm install your-package-name  记得替换为对应的值

(参考http://community.activestate.com/forum-topic/ppm-does-not-work-after-install

Tags:
Jan 2

window xp dos下通过设置http_proxy 使用代理上网或者下载文件

由于公司内部本机不能上网,都是通过代理上网的,在配置perl 的ppm文件升级的时候经常报错误,
比如升级perl install dmake 下载dmake的ppm包的时候报
Downloading ActiveState Package Repository packlist...failed 500 Can't connect to ppm4.activestate.com:80 (Bad hostname)
ppm install failed: Can't find any package that provides dmake

这时可以通过设置环境变量http_proxy 来解决。
dos下查看是否有设置变量set http_proxy

The http_proxy Environment Variable 几种http_proxy的设置区别
如果我代理的IP是10.2.4.5 端口是808

Set the http_proxy variable with the hostname or IP address of the proxy server:

  http_proxy=http://proxy.example.org
  http_proxy=10.2.4.5:808
If the proxy server requires a user name and password, include them in the following form:

  http_proxy=http://username:password@proxy.example.org

If the proxy server uses a port other than 80, include the port number:

  http_proxy=http://username:password@proxy.example.org:8080

各平台操作系统设置http_proxy的方法 Setting http_proxy
Windows XP设置代理
    1、Open the Control Panel and click the System icon.登陆到控制面板并点击系统
    2、The System Properties dialog is displayed.系统属性对话框
    3、On the Advanced tab, click on Environment Variables.点击高级 tab 页面的环境变量
    4、The Environment Variables dialog is displayed.
    5、Click New in the System variables panel. 新建环境变量
    6、The New Sytem Variable dialog is displayed.
    7、Add http_proxy with the appropriate proxy information (see examples above).设置环境变量

Windows 200x设置代理
    1、Right click on My Computer.
    2、Click on Properties and select the Advanced tab.
    3、Click "Environment Variables".
    4、The "System Variables" dialog appears.
    5、Click New and add http_proxy, with the appropriate proxy information (see examples above).

Windows NT设置代理
    Right click on My Computer.
    Click on Properties, select the Environment tab.
    Add http_proxy with the appropriate proxy information (see examples above).

Windows 95/98/ME设置代理
    Open the C:\autoexec.bat file for editing (e.g. in Notepad).
    Add a "SET" line like the following (see examples above):
          SET http_proxy=http://username:password@hostname:port
    Restart your computer for the change to take effect.

Mac OS X设置代理
The http_proxy should be set in two places on OS X:
    Shell: Add a line like the following in .bash_profile (/Users/<name>/.bash_profile):
          http_proxy=http://username:password@hostname:port;  export http_proxy
    This setting applies to PPM when it is launched from or used at the command line.
    Desktop: Add an entry like the following in your environment.plist file (/Users/<name>/.MacOSX/environment.plist):
          <key>http_proxy</key>
          <string>http://username:password@hostname:port</string>
    This setting applies to PPM when it is launched by clicking the PPM icon.

Linux, Solaris or HP-UX设置代理
Set the http_proxy environment variable using the command specific to your shell (e.g. set or export). To make this change persistent, add the command to the appropriate profile file for the shell. For example, in bash, add a line like the following to your .bash_profile or .bashrc file:
    http_proxy=http://username:password@hostname:port;  export http_proxy

分页: 1/3 第一页 1 2 3 下页 最后页 [ 显示模式: 摘要 | 列表 ]