Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^2: opening file for editing

by ramprasad27 (Sexton)
on Oct 09, 2011 at 08:08 UTC ( #930434=note: print w/ replies, xml ) Need Help??


in reply to Re: opening file for editing
in thread opening file for editing

well, why is the file going blank if i use > even though the file exists and has contents


Comment on Re^2: opening file for editing
Replies are listed 'Best First'.
Re^3: opening file for editing
by Anonymous Monk on Oct 09, 2011 at 08:36 UTC

    well, why is the file going blank if i use > even though the file exists and has contents

    Because that is what > means, see open

      you can understand in this way:
      The file name here is where you save your work. 
      ( you use close() to save your file )
      So it doesn't matter the file has data inside or not. 
      ONLY the data in the handle will write to your file.
      ie. This ">" is an overwrite, if you are opening an existed file
      
      So, since you are open a file for WRITE, so it couldn't READ, while you read
      nothing, so you write nothing. End up, you harvest an empty file
      
        ok i got it, i just wanted to know any way i can open already existing file change it on the fly
Re^3: opening file for editing
by pvaldes (Chaplain) on Oct 09, 2011 at 08:48 UTC

    ">" and ">>" are pipelines.

    For Perl and bash (one of the linux shells) ">" is the standard way to say: "redirect this stuff to the named file and overwrite (delete) its previous contents with this".

    And ">>" is the standard way to say: "add this material after the last line of the file (updating this contents) but preserve any previous contents that you found in this file". ">>" works also in perl and in bash

    If the file is missing both do basically the same. Create a "box" (the file) and dump all the "bricks" into this box.

    So, let's see what are you doing:

    open (HAN , ">" ,'D:\RAM\perl\test') or die "$!"; # DELETE the contents of this file and open it while (<HAN>){ s/e/\*\*/ig; # nothing here to mach, the file is empty, no survivor "e" chars print HAN ; # thus, nothing is changed and nothing left to print to the file }

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2015-08-01 01:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (285 votes), past polls