Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19
PERL: edit File handle on the fly
Results 1 to 3 of 3

Thread: PERL: edit File handle on the fly

  1. #1
    Senior Member
    Join Date
    Apr 2002
    Posts
    417

    PERL: edit File handle on the fly

    Hi,

    I wanted to basically edit one line of a file that has a certain string in it. For example,

    cinnamon:23845
    spork:23042
    talon:948338
    bruce:742354

    I'd look for a line with string spork. then say add 'X' to the amount on the right.

    I'm looking for an elegant way of doing this on the fly.

    while(<FILENAME>)
    {
    if( /spork/)
    {
    # update only this line and write the file handle back to file.
    }

    }


  2. #2

    Re:PERL: edit File handle on the fly

    Oddly there is not one.

    You can edit files in place, but what if the current value is 9, you add X to it and suddenly it's double digits, which if you edit the file in place would not fit.

    So your options are, rewrite the whole file with the new number, use a fixed length for the numbers (00009), use a binary database format, use SQL.

  3. #3

    Re:PERL: edit File handle on the fly

    You could use the module Tie::File, it changes affect the file immediately.

Similar Threads

  1. W Explorer can't handle long file names
    By paulmarcw in forum Windows - General Topics
    Replies: 8
    Last Post: 02-18-2006, 05:47 AM
  2. HOW TO: Edit the Boot.ini File
    By CoolJsa14 in forum Windows - General Topics
    Replies: 0
    Last Post: 01-05-2005, 09:27 PM
  3. Edit the Boot.ini File in Windows XP
    By regix in forum Windows - General Topics
    Replies: 0
    Last Post: 01-04-2005, 07:21 AM
  4. perl, including a file /more/ than once
    By gorn in forum Linux - Software, Applications & Programming
    Replies: 4
    Last Post: 07-08-2002, 10:18 PM
  5. What file should I edit for DNS name info ...
    By Compunuts in forum Linux - Hardware, Networking & Security
    Replies: 2
    Last Post: 12-10-2001, 07:34 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •