0

Hello,

I've searched far and wide for an answer to a question that I have, but did not find anything that could help me achieve what I would like to do.

I have a delimited text file (CSV) with fields that resemble these below that repeats/resemble 18 times (I only included 3 rows for an example).

It's a regularly updated database where Row-1, 2 or 3 etc, stand to change from "open" to "closed".

<img src='/images/closed.gif'>;Row-1;<img src='/images/open.gif' align='absmiddle'>;<img src='/images/closed.gif' align='absmiddle'>
<img src='/images/closed.gif'>;Row-2;<img src='/images/closed.gif' align='absmiddle'>;<img src='/images/closed.gif' align='absmiddle'>
<img src='/images/closed.gif'>;Row-3;<img src='/images/open.gif' align='absmiddle'>;<img src='/images/closed.gif' align='absmiddle'>

With the (working) code I have below, I would like the script to "print" the output, but only if the string "open.gif" exists on any given line, and NOT printing if it is not.

It would be appreciated, thank you.

#!/usr/bin/perl


use CGI::Carp qw(fatalsToBrowser);
use strict;

my $csvfile = "/my_file.txt";

print "Content-Type: text/html\n\n";

open (CSV, "< $csvfile");
while( <CSV> )
{
my @cols = split(/;/, $_);


if (2..18) {print "Row-1: $cols[0]<br>Row-2: $cols[1]<br>Row-3: $cols[2]"

}

}
close CSV
2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by fredfletcher
0

try this (untested) - hope it helps!

#!/usr/bin/perl


use CGI::Carp qw(fatalsToBrowser);
use strict;

my $csvfile = "/my_file.txt";

print "Content-Type: text/html\n\n";

open (CSV, "<$csvfile") or die "Can't open $csvfile\n";
while( <CSV> )
{
chomp;
my $line = $_;
if ($line =~ 'open.gif'){
my @cols = split(/;/, $line);
print "Row-1: $cols[0]<br>Row-2: $cols[1]<br>Row-3: $cols[2]\n";
}
}

close CSV
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.