The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-08-2002
Optimus_P Optimus_P is offline Forum Advisor  
flim flam flamma jamma
  
 

Join Date: May 2001
Location: Chicago IL, USA
Posts: 1,006
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";
  #2 (permalink)  
Old 01-09-2002
auswipe's Avatar
auswipe auswipe is offline Forum Advisor  
Registered User
  
 

Join Date: Nov 2001
Location: Wide Awake Wylie, Texas
Posts: 535
Is this what you are wanting to do?

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++;
}

print HTML "/table
/html";
Notice that all I did was add the $movieCount variable declaration above the `for (@movies` line and added a post-fix increment to the $movieCount variable after the `for map` line so that after each loop and display, $movieCount will increment.

If not, please let me know.
  #3 (permalink)  
Old 01-09-2002
Optimus_P Optimus_P is offline Forum Advisor  
flim flam flamma jamma
  
 

Join Date: May 2001
Location: Chicago IL, USA
Posts: 1,006
i think that will work.

in the end on the webpage there should be a number next to the movie so i dont have to manualy count how manyy i have.
  #4 (permalink)  
Old 01-09-2002
auswipe's Avatar
auswipe auswipe is offline Forum Advisor  
Registered User
  
 

Join Date: Nov 2001
Location: Wide Awake Wylie, Texas
Posts: 535
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";
  #5 (permalink)  
Old 07-18-2008
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,078
input:
Code:
leo:30
stt:25
tony:31
code:
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);
output:
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>
  #6 (permalink)  
Old 07-18-2008
KevinADC KevinADC is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2008
Posts: 731
are you for real? Another ancient thread dug up.

01-08-2002
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:35 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0