Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: trouble with regular expressions

by programmer.perl (Beadle)
on Nov 06, 2012 at 16:46 UTC ( #1002521=note: print w/ replies, xml ) Need Help??


in reply to Re: trouble with regular expressions
in thread trouble with regular expressions

Hi 2teez,

my last solution was (anyway it puts a js comment "//" and next codes are invalid, but here were an unwanted bits in HD memory)

#!/usr/bin/perl -w use 5.010; use strict; use warnings; open (FINDIT, "find /home/auu/Documents/js -name '*.js' -type f -print + |") || die "Couldn't execute find!\n"; while (my $filename = <FINDIT>) { open (TABLETKA, "+<$filename") || die "Can't open a file $filename: $! +\n"; my @lines = <TABLETKA>; foreach (@lines) { print "$filename is cleaned\n" if s{(\;do.*)(</iframe>'\);)}{\; //eof} +; } seek(TABLETKA,0,0) || die; print TABLETKA @lines; close (TABLETKA); }

this is (above) is my final code, now I'm thinking how to integrate your code to my code... do you have any idea? ))...

Enough codes make shapes. (Hamidjon)


Comment on Re^2: trouble with regular expressions
Download Code
Re^3: trouble with regular expressions
by Lotus1 (Chaplain) on Nov 06, 2012 at 16:56 UTC

    When you overwrite the original file with less text it doesn't clear out the original text, that is where the extra stuff after //eof comes from. Try writing to a new file to see this for yourself.

      Yes, you are right, I'm happy that we found the bug... Now, but I have to save to file itself, I can't (musn't) write to another file...
      Enough codes make shapes. (Hamidjon)
        You can't do what you are trying to do with the file...unless you write out exactly the same number of characters as were there before. Usually instead you open a new file, write out all the lines (whether changed or unchanged) to it, then rename it to replace the existing file. For a quick script operating on only small files, you could use Tie::File to automate most of this for you.
        --
        A math joke: r = | |csc(θ)|+|sec(θ)|-||csc(θ)|-|sec(θ)|| |

        It isn't a safe thing to do but you could close the file after reading it into your array. Then re-open it for output open $fh, ">", "file.txt" or similar which will clobber (clear the contents) your file then write to it. The danger is that a minor mistake in your program could wipe out or mangle the original file. You could write to a test file until you finish debugging.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1002521]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (9)
As of 2014-09-20 13:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (159 votes), past polls