![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| perl -write values in a file to @array in perl | meghana | Shell Programming and Scripting | 27 | 06-07-2009 05:05 PM |
| Array length in PERL | anent | Shell Programming and Scripting | 5 | 07-17-2008 04:39 PM |
| how to get last value in an array in perl | meghana | Shell Programming and Scripting | 7 | 02-04-2008 05:12 PM |
| multidimensional array in perl | prkfriryce | Shell Programming and Scripting | 9 | 12-01-2007 04:33 PM |
| hash,array and perl | new2ss | Shell Programming and Scripting | 3 | 05-23-2007 11:30 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
perl + array and incrementing number
morning guys and gals,
I am haveing a problem, a friend helped me out with this script but i dont know how to add incrementing number for each movie in movie.list. this is what i have so far. any assistance would be great. I have removed the GT and LT symbols so you can see what is going on in the array. Code:
#! /usr/bin/perl -w
use strict;
my $src_list = 'movie.list';
open SRC, $src_list or die "Couldn't read $src_list: $!\n";
my @movies = sort <SRC>;
my $dst_list = 'dvd-list.html';
open(HTML, "> $dst_list") or die "Can't write to $dst_list: $!\n";
print HTML "
my basic html goes here";
for (@movies) {
# The order here needs to be fixed.
my ($title, $run_time, $mpaa_rating, $genre, $prod_company) = split ':', $_;
print HTML "tr";
# Make sure we get no undef vars.
print HTML "td $_ /td"
for map {$_ || ''} $title, $run_time, $mpaa_rating, $genre, $prod_company;
print HTML "/tr\n";
}
print HTML "/table
/html";
|
|
|||||
|
Ooooohhh.
Then try this: Code:
#! /usr/bin/perl -w
use strict;
my $src_list = 'movie.list';
open SRC, $src_list or die "Couldn't read $src_list: $!\n";
my @movies = sort ;
my $dst_list = 'dvd-list.html';
open(HTML, "> $dst_list") or die "Can't write to $dst_list: $!\n";
print HTML "
my basic html goes here";
# Add variable to display "Current Record Number"
my $movieCount = 1;
for (@movies) {
# The order here needs to be fixed.
my ($title, $run_time, $mpaa_rating, $genre, $prod_company) = split ':', $_;
print HTML "tr";
# Make sure we get no undef vars.
print HTML "td $_ /td"
for map {$_ || ''} $movieCount $title, $run_time, $mpaa_rating, $genre, $prod_company;
print HTML "/tr\n";
# Increment $movieCount by one with each display
$movieCount++;
}
$movieCount--;
print HTML "(br)(b) There are $movieCount movies in the library.(/b)\n";
print HTML "/table
/html";
|
|
||||
|
input:
Code:
leo:30 stt:25 tony:31 Code:
open SFH,"<staff.txt" or die "Can not open file";
open HFH,">staff.html" or die "Can not open file";
print HFH "<HTML>\n";
while(<SFH>){
print HFH "<member",$.,">\n";
my ($name,$age)= split ":",$_;
$age=~ tr/\n//d;
print HFH "<name> ",$name," </name>\n";
print HFH "<age> ",$age, "</age>\n";
print HFH "</member",$.,">\n";
}
print HFH "</HTML>\n";
close(HFH);
close(SFH);
Code:
<HTML> <member1> <name> leo </name> <age> 30</age> </member1> <member2> <name> stt </name> <age> 25</age> </member2> <member3> <name> tony </name> <age> 31</age> </member3> </HTML> |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|