[ale] System in Perl
Jay Loden
ale at jayloden.com
Fri Jul 27 02:40:04 EDT 2007
Terry Bailey wrote:
> Hi,
>
> Is there any way to place the results of the following into a Perl
> variable without opening and closing a file? In addition, this
> would be used in Javascript function.
>
> system("stat test | grep -i access | grep -v Uid | cut -b8-27");
In addition to what Chris already suggested about using Perl's stat instead of calling shell commands unnecessarily...
Perl has a built-in mechanism for exactly this purpose, which is the backticks operator. For instance, using the below in a file called stat.pl
#!/usr/bin/perl
my $stat_result = `stat test | grep -i access | grep -v Uid | cut -b8-27`;
print "$stat_result\n";
Now running it on an example test file:
[jloden at dell ~]$ touch test
[jloden at dell ~]$ perl stat.pl
2007-07-27 02:39:13
That being said, I still recommend using a built in function for stat() instead, it's a lot cleaner, more portable, and less fragile.
-Jay
More information about the Ale
mailing list