in reply to how to store values from system command
In your sample, $val will contain the return code from ls. Most system commands return 0 or undef on success, so your system("ls -lrt "); call is succeeding (I'm quite sure ls can fail; I just can't remember seeing it do so.).
As ikegami and andyford mentioned, using system is almost certainly not the best solution. For one thing, it uses a sub-shell, where using glob or opendir doesn't.
You could try something like this (see stat):
#!perl use strict; use warnings; my @list = glob("*"); foreach(@list){ (my $dev, my $ino, my $mode, my $nlink, my $uid, my $gid, my $rdev, my $size, my $atime, my $mtime, my $ctime, my $blksize, my $blocks) = stat; # do processing here }
yeah, verily, an update
ikegami pointed out that system only uses a subshell if the command contains shell metacharacters. In any case, unless you need the data exactly as produced by ls, using the Perl functions is certainly more portable (Windows doesn't have ls), and possibly faster.emc
At that time [1909] the chief engineer was almost always the chief test pilot as well. That had the fortunate result of eliminating poor engineering early in aviation.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: how to store values from system command
by ikegami (Patriarch) on Nov 21, 2006 at 20:07 UTC |