Re: writing array to file?
- From: Jim Gibson <jgibson@xxxxxxxxxxxxxxxxx>
- Date: Tue, 21 Aug 2007 10:02:33 -0700
In article <1187714457.955337.306830@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
elroyerni <davechunny@xxxxxxxxx> wrote:
Hi -
I have a array that i initialize for using this in my perl script:
my @array_data = qx(cat /home/dchun/logs/$date/stat.log|grep "System
took"|cut -c 56-62);
I know this is really simple but I can't seem to figure it out. How do
i write this array to a text file in my home directory? I just want to
save it for later. If the file already exists, i just want to write
over it.
I tried using a system command.. but that didn't work. Any suggestions
on a simple way to do this?
system `cat /home/ssi9gwy/logs/$date/rco.log|grep "OTS took"|cut -c
56-62 > /u/dchun/rco_stats/$date.rco_stat.log`;
Perl has input and output facilities for reading and writing files,
regular expressions for searching for patterns in strings, and
functions for manipulating strings. You should consider using them
(untested):
#!/usr/local/bin/perl
#
use warnings;
use strict;
my $date = '???';
my $infile = "/home/ssi9gwy/logs/$date/rco.log";
my $outfile = "/u/dchun/rco_stats/$date.rco_stat.log";
open(my $in, '<', $infile) or die("Can't open $infile: $!");
open(my $out, '>', $outfile) or die("Can't open $outfile: $!");
while(<$in>) {
next unless /OTS took/;
print $out substr($_,56,7), "\n";
}
close($in) or die("Error closing $infile: $!");
close($out) or die("Error closing $outfile: $!");
__END__
See
perldoc -f open
perldoc -f substr
perldoc perlre
perldoc perlop (search for 'I/O Operators')
--
Jim Gibson
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
.
- Follow-Ups:
- Re: writing array to file?
- From: elroyerni
- Re: writing array to file?
- References:
- writing array to file?
- From: elroyerni
- writing array to file?
- Prev by Date: Re: Join lines
- Next by Date: Re: Symrefs
- Previous by thread: Re: writing array to file?
- Next by thread: Re: writing array to file?
- Index(es):
Relevant Pages
|