CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner:
understanding program


New User

Nov 8, 2014, 9:08 AM

Post #1 of 2 (2066 views)
understanding program Can't Post

 can anybody explain what the program will do inside the while and foreach loop especially split and count part in below program?

$count = 0;
open ($INFILE, '<', $inputfilename) || die "Cannot open file for input $inputfilename: $!" ;
open ($OUTFILE, '>', $outputfilename) || die "Cannot open file for output $outputfilename: $!";
while (my $curline = <$INFILE>)
my @lines = split /\<\/Item\>/, $curline;
foreach my $line (@lines)
if (index($line, "<Item ") != -1)
$count = $count + 1;
$line =~ s/\<Item /\<Item itemKey\=\"$count\" /;
print $OUTFILE $line."</Item>";
print $OUTFILE $line;
print $OUTFILE "\n";
close ($FILE);


Nov 8, 2014, 5:44 PM

Post #2 of 2 (2059 views)
Re: [vamsi.valiveti] understanding program [In reply to] Can't Post

This program assumes that the input consists of a special subset of HTML. It splits each line into item tags. In each tag, it adds (after the attribute 'Item') the attribute 'ItemKey=count" (where count is the number of replacements made so far.

In general this is a very poor way to edit HTML. It probably works ok as long as the input truly conforms to the expected format.
Good Luck,


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives