Want to do One line Perl Command
EchoAngel
created: 2004-07-02 16:31:47
i have a file with the following
apple.c
pears.c
watermelons.c
i want to delete these files using some code in perl -ne however if my file contains stuff like
apple.c
Errors
Errors
pears.c
Errors
Errors
Errors
watermelon.c
i want the perl command line to delete only the watermelon.c file since it has no Errors statements following the file name in the list I hope I made this clear
Re: Want to do One line Perl Command
created: 2004-07-02 16:43:33

If I read you right ...

perl -nle '$_ eq "Errors" ? pop(@f) : push(@f, $_); END {unlink @f}'

print "Just another Perl ${\(trickster and hacker)},"
The Sidhekin proves Sidhe did it!

Re^2: Want to do One line Perl Command
created: 2004-07-02 17:22:28
Oh sorry, I forgot to indicated that there could be multiple Errors statements
Re^3: Want to do One line Perl Command
created: 2004-07-02 17:29:58

Oh sorry, I forgot to indicated that there could be multiple Errors statements

Oh well. Slight modification:

perl -nle '$_ eq "Errors" ? delete($f{$prev}) : $f{$prev=$_}++; END {unlink keys %f}'

print "Just another Perl ${\(trickster and hacker)},"
The Sidhekin proves Sidhe did it!

Re: Want to do One line Perl Command
created: 2004-07-03 08:23:00
If we make an assumption that any line that doesn't have a .c file is an error statement...

perl -lne '/\.c$/?$h{$l=$_}++:delete$h{$l}}{unlink keys%h' file.txt

Re: Want to do One line Perl Command
created: 2004-07-03 15:36:33
Here's a different approach:
   perl -0ne 'unlink /.+\n(?:Errors$)+|(.+)/mg'
Re^2: Want to do One line Perl Command
created: 2004-07-05 07:08:30
Hmm... I just don't see why it's so important to you to have a perl -ne style one-liner. What's wrong with a script which can do the job easier and more readable than a one-liner?
"2b"||!"2b";$$_="the question"

perlmonks.org content © perlmonks.org and delirium, EchoAngel, muba, Neutron Jack, Sidhekin

prlmnks.org © 2006 edmund von der burg (eccles & toad)

v 0.03