Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

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)

Replies are listed 'Best First'.
Re^3: trouble with regular expressions
by Lotus1 (Curate) 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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1002521]
[james28909]: cant seem to make it look in linux module path for
[james28909]: no matter how i prepare the paths. oh well. looks like ill just have to start wsl perl from scratch
[Corion]: james28909: You can get a list of all modules on your Windows Perl via the autobundle command in the cpan shell. But that likely lists many more modules than you actually want. I recommend a clear separation and installing modules on ...
[Corion]: ... both Perls separately. I use cpanfiles or Makefile.PL for that - listing all modules for an application there allows me to install them via cpanm . or cpan . automatically without any further interaction

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2018-05-23 17:21 GMT
Find Nodes?
    Voting Booth?