perl 中glob函数的使用

Example

Try out following example: Here glob will retun all the files which begin with "perl_g"

#!/usr/bin/perl

(@file_list) = glob "perl_g*";

print "Returned list of file @file_listn";
[@more@] Syntax

glob EXPR

glob

Definition and Usage

Returns a list of files matching EXPR as they would be expanded by the standard Bourne shell. If the EXPR does not specify a path, uses the current directory. If EXPR is omitted, the value of $_ is used.

From Perl 5.6 on, expansion is done internally, rather than using an external script. Expansion follows the csh (and any derivatives, including tcsh and bash) style of expansion, which translates as the following:

  • Files beginning with a single period are ignored unless EXPR explicitly matches.
  • The * character matches zero or more characters of any type.
  • The ? character matches one character of any type.
  • The [..] construct matches the characters listed, including ranges, as per regular expressions.
  • The ~ characters matches the home directory; ~name matches the home directory for the user name.
  • The {..} construct matches against any of the comma-separated words enclosed in the braces.

www.tutorialspoint.com/perl/perl_glob.htm

Return Value

  • In scalar context undef on error otherwise First file in the list of expanded names

  • In list context Empty list on error otherwise List of expanded file names.

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/16723161/viewspace-1016238/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/16723161/viewspace-1016238/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值