how to open a text file for editing using perl

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • usustarr
    New Member
    • May 2010
    • 2

    how to open a text file for editing using perl

    i am working on creating a Gui environment on a Ubuntu OS.

    i have a .pl file.

    i need to open a /run/auto.txt file for editing in a new window, so user can edit the file manually. You know if i was using vi editor, i would have vi /run/auto.txt and it will open auto.txt in a new window so i can edit and wq! when i am done.

    Below is my code and i put some comments in the code so you can see where i want my file to be open.

    Any help would be greatly appreciated.




    Code:
    sub beforeDrainRecoveryNotes
    {
      $file = "$runDir/auto.txt";
      while((my $key, my $value) = each %stationSelected)
      {
        if($value)
        {
        
          if(my $pid = fork) { $pids{$pid}++; }
          else
          {
          #  &runSysComm("$binDir/win $key");
          #   This is where i want to open the auto.txt file in 
          #   new window so user can edit this file. 
          #   After editing is done, user will save and close the file
          #   preferbally using wq!	  
     
            CORE::exit();
          }
        }
      }
      printErr();
    }
  • RonB
    Recognized Expert Contributor
    • Jun 2009
    • 589

    #2
    Why should the user use "wq" to save and close the file?

    If you're creating a GUI, then you should have a menubar with a File dropdown like all other GUI's.

    For editing the file, you need to use Perl's open function.
    See: http://perldoc.perl.org/functions/open.html

    Comment

    • numberwhun
      Recognized Expert Moderator Specialist
      • May 2007
      • 3467

      #3
      @RonB He mentioned that that is what he does when editing with vi. That means that he probably has vi aliased to gvim (Graphical Vim), which still accepts the :wq to save and exit a file, but also has the "File" menu you mentioned.

      Us Unix command line geeks still like our keyboard interface, even in the face of a gui. Its a nice added feature. :)

      Comment

      • RonB
        Recognized Expert Contributor
        • Jun 2009
        • 589

        #4
        Jeff,

        Ya, I knew that, I just wanted the OP to clarify what (s)he wants. I just made the same mistake, which was not making it clear what I was asking.

        So, (usustarr) is this a Perl Tk GUI script, or are you wanting to use Perl to drive gvim? I've never tried, but it's probably possible to drive gvim, but that would be IMO the worst possible approach.

        Comment

        • usustarr
          New Member
          • May 2010
          • 2

          #5
          Originally posted by RonB
          Jeff,

          Ya, I knew that, I just wanted the OP to clarify what (s)he wants. I just made the same mistake, which was not making it clear what I was asking.

          So, (usustarr) is this a Perl Tk GUI script, or are you wanting to use Perl to drive gvim? I've never tried, but it's probably possible to drive gvim, but that would be IMO the worst possible approach.
          this piece of the code came from Gui environment.
          1) i want to open this text file in a new window so a user (human) can edit. That part of the code needs to be located in side of that else statement.

          2) when user done with editing i need a way to save and close this new window we opened. i prefer wq!, but i am open to any other ideas too.

          i am new to Perl,. so i am having hard time with this. i know how to open a file for editing if editing was done by a script. Can you please help me out here?

          Comment

          • RonB
            Recognized Expert Contributor
            • Jun 2009
            • 589

            #6
            We still seem to be dancing around the root of what you want, which means I don't have a clear picture of what you really want.

            1) i want to open this text file in a new window so a user (human) can edit. That part of the code needs to be located in side of that else statement.
            That tells me that you simply want Perl to launch gvim to edit your file.

            2) when user done with editing i need a way to save and close this new window we opened. i prefer wq!, but i am open to any other ideas too.
            That tells me that you want to use one of Perl's gui frameworks (possibly Perl/Tk) to create a gui that allows the user to modify the file and uses some of the (gvim) keyboard shortcuts to edit/save the file.

            Those 2 approaches have entirely different solutions and requires completely different code base. Which do you want to do?

            The ability to clearly state what you're doing and what you need will go a long way in us being able to suggest solutions.

            Comment

            Working...