ЭЛЕКТРОННАЯ БИБЛИОТЕКА КОАПП |
Сборники Художественной, Технической, Справочной, Английской, Нормативной, Исторической, и др. литературы. |
12.2 GlobbingThe shell (or whatever your command-line interpreter is) takes a solitary asterisk ( The expansion of arguments like @a = </etc/host*>; @a = glob("/etc/host*"); In a list context, as demonstrated here, the glob returns a list of all names that match the pattern (as if the shell had expanded the glob arguments) or an empty list if none match. In a scalar context, the next name that matches is returned, or while (defined($nextname = </etc/host*>)) { print "one of the files is $nextname\n"; } Here the returned filenames begin with /etc/host, so if you want just the last part of the name, you'll have to whittle it down yourself, like so: while ($nextname = </etc/host*>) { $nextname =~ s#.*/##; # remove part before last slash print "one of the files is $nextname\n"; } Multiple patterns are permitted inside the file glob argument; the lists are constructed separately and then concatenated as if they were one big list: @fred_barney_files = <fred* barney*>; In other words, the glob returns the same values that an equivalent echo command with the same parameters would return.[3]
Although file globbing and regular-expression matching function similarly, the meaning of the various special characters is quite different. Don't confuse the two, or you'll be wondering why The argument to if (-d "/usr/etc") { $where = "/usr/etc"; } else { $where = "/etc"; } @files = <$where/*>; Here we set There's one exception to this rule: the pattern
|