Splice Line Occurrences In A Text File

I need to splice all line occurrences in a text file with these variables:
/^REM DATE .*?$/
/^REM GENRE .*?$/
but I don't know how to use the splice function when not exact values.
thebourneidAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

zlobchoCommented:
Try this:
#!/usr/bin/perl

 use strict;
 open (DATA,"yourfile.txt") or die "can not open the inputfile\n";
 my $lines;
 while(<DATA>){
  if (($_!~/^REM DATE .*?$/)||($_!~/^REM GENRE .*?$/)){
   $lines.=$_;
  }
  if (($_=~/^REM DATE .*?$/)||($_=~/^REM GENRE .*?$/)) {
    print $lines;
    print "\n\n\n\n";
    undef $lines;
  }
}
close (DATA);

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
zlobchoCommented:
Or:
#!/usr/bin/perl
 use strict;
 open (DATA,"yourfile.txt") or die "can not open the inputfile\n";
 my $lines; my @array;
 while(<DATA>){
  if (($_!~/^REM DATE .*?$/)||($_!~/^REM GENRE .*?$/)){
   $lines.=$_;
  }
  if (($_=~/^REM DATE .*?$/)||($_=~/^REM GENRE .*?$/)) {
    push (@array,$lines);
    undef $lines;
  }
}
close (DATA);
foreach (@array){
print "$_\n\n";
}

Open in new window

0
TintinCommented:
Could you please describe what you are trying to do in non-perl terms, as the splice function is for removing elements from an array and your "variables" are actually regular expressions, so it is not obvious what you are trying to achieve.
0
thebourneidAuthor Commented:
I'm trying to remove every line oocurrences with the variables from a text file without leaving blank spaces.
I'm using the "tie:file" function as a part of a bigger script and this substitution s/^\n//; dosen't work to delete empty lines.
is it possible to integrate zlobcho's suggestion in this script


my @ln;      
       tie @ln, 'Tie::File', $filename or die "could not tie $fn: $!"; 
       foreach (@ln) {
	/some substitution process/..../;   
       } 
       untie @ln; 

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.