Re: Need help with a question.
- From: Trev <trevor.dodds@xxxxxxxxx>
- Date: Sat, 28 Jun 2008 13:18:08 -0700 (PDT)
On Jun 28, 1:40 pm, Ben Morrow <b...@xxxxxxxxxxxx> wrote:
Thanks Ben for the detailed reply, I've been able to get the output
correct, but I'm stuck on how to read $cpqlogline into an array
without writing it to a file.
my files look like this:
the perl file:
use warnings;
use strict;
my $server_file = "list.txt";
my $mactmp = "mactmp.txt";
my $maclog = "logfile.txt";
sub LoadFile
{
open(my $SRV, '<', $server_file)
or die("Could not open file: $!");
while (my $server = <$SRV>) {
chomp($server);
open (my $DAT, '<', 'output.txt')
|| die("Could not open 'output.txt': $!");
open (OTF, ">blah.txt");
print OTF $DAT;
while (my $cpqlogline = <$DAT>) {
{
chomp($cpqlogline);
if ($cpqlogline =~ /MAC/)
{
$cpqlogline =~ s/ <FIELD NAME="Subject" VALUE="//i;
$cpqlogline =~ s/ <FIELD NAME="MAC" VALUE="//i;
$cpqlogline =~ s/"\/>//i;
open (TMP, ">>$mactmp");
print TMP "$server". "," . "$cpqlogline\n";
close TMP;
}
}
}
}
close OTF;
}
sub CreateLOG
{
open (TMP, "<$mactmp");
open (LOG, ">>$maclog");
my @lines=<TMP>;
print LOG "$lines[1]";
close TMP;
close LOG;
print @lines;
unlink "blah.txt";
#unlink $mactmp;
}
LoadFile;
CreateLOG;
The list.txt file:
server1
server2
server3
The output.txt file:
<FIELD NAME="Subject" VALUE="Embedded NIC MAC Assignment"/>
<FIELD NAME="Port" VALUE="1"/>
<FIELD NAME="MAC" VALUE="00-00-00-00-00-01"/>
<FIELD NAME="Port" VALUE="2"/>
<FIELD NAME="MAC" VALUE="00-00-00-00-00-02"/>
<FIELD NAME="Port" VALUE="iLO"/>
<FIELD NAME="MAC" VALUE="00-00-00-00-00-03"/>
When the script runs it only creats the logfile with one line:
server1,00-00-00-00-00-01
When it should show:
server1,00-00-00-00-00-01
server2,00-00-00-00-00-01
server3,00-00-00-00-00-01
I see the problem is that the CreateLog only reads value[1] since the
above sub writes everything into mactmp.txt then only CreateLog is
run.
Any ideas?
.
- Follow-Ups:
- Re: Need help with a question.
- From: Ben Morrow
- Re: Need help with a question.
- From: Anonymous coward
- Re: Need help with a question.
- From: Jürgen Exner
- Re: Need help with a question.
- References:
- Need help with a question.
- From: Trev
- Re: Need help with a question.
- From: Ben Morrow
- Need help with a question.
- Prev by Date: FAQ 8.25 How can I capture STDERR from an external command?
- Next by Date: Re: Need help with a question.
- Previous by thread: Re: Need help with a question.
- Next by thread: Re: Need help with a question.
- Index(es):