Others have given you some good stuff about deleting from the array, but
what about if you try a different approach and filter the files as you add
them to the array?

#!/usr/local/bin/perl

$file = 'flashimage.txt';   # file name
@lines = ();                # init empty array
open(INFO, $file) or die $! # file open w/error check
while(<INFO>)
{
  push @lines, $_  # <-- no semicolon!  
    if /\.(txt|scc)$/;  # shorthand "if" test
}
close INFO;

print (join "\n", @lines);  # print files, one per line

Like that any better?  :)

Mark Nutter
Manager, Internet Applications Development
Marconi
[EMAIL PROTECTED]
It's not necessarily an advantage to have better brakes than the guy behind
you.


> -----Original Message-----
> From: Kaustav Bhattacharya [mailto:[EMAIL PROTECTED]]
> Sent: Friday, April 27, 2001 8:26 AM
> To: [EMAIL PROTECTED]
> Subject: replacing an element in an array
> 
> 
> Am rather a beginner at perl and was wondering how to do the 
> following. I've
> read in a text file containing a list of file paths.  the 
> list is read in to
> an array. I want to scan through the whole array and remove 
> all lines with
> end as .txt and .scc. i.e remove that element in the array.  
> My file list
> looks like this:
> 
> D:\Liberate\Connect\app\pages\servicemanager\splash.gif
> D:\Liberate\Connect\app\pages\servicemanager\splash.html
> D:\Liberate\Connect\app\pages\servicemanager\vssver.scc
> D:\Liberate\Connect\app\pages\servicemanager\sounds\enter.wav
> D:\Liberate\Connect\app\pages\servicemanager\sounds\key.wav
> D:\Liberate\Connect\app\pages\servicemanager\sounds\vssver.scc
> 
> 
> and my code thus far is:
> 
> #\usr\local\bin\perl
> 
> $file = 'flashimage.txt';     # Name the file
>  open(INFO, $file);          # Open the file
>  @lines = <INFO>;      # Read it into an array
>  close(INFO);               # Close the file
> 
> foreach $eachline (@lines) {
>  $eachline =~ s/scc//g
> }
> 
> print @lines;
> 
> 

Reply via email to