beginner perl question

    Date: 08/27/06 (Computer Geeks)    Keywords: no keywords

    this is my first time using perl and i'm completely stuck.
    i'm trying to write a script that changes a part of a file.

    i've got the program to open, find the correct line and make the changes, but i dont know how to overwrite the old line with the new.

    open (SAMPLE, '>>sample') || die ("Could not open the file. \n");
    print SAMPLE "$text";

    sticks the new line on the end of the file.

    neither
    open (SAMPLE, 'sample') and open (SAMPLE, '>sample')
    works either.

    #!/usr/bin/perl -w
    
    #open the file
    open (SAMPLE, "sample") || die ("Could not open the file.  \n");
    
    $text = < SAMPLE >;
    
    print "text is $text";
    
    $number = substr($text, 16, 1);
    $number++;
    substr($text, 16, 1) = $number;
    
    print "text is now $text \n";
    
    close (SAMPLE);
    
    open (SAMPLE, '>>sample') || die ("couldnt open sample the 2 time. \n");
    
    print SAMPLE "$text";
    
    close (SAMPLE);


    i've been at this for way too long and i'm sure its a very basic thing. anyone give me a nudge?

    Source: http://community.livejournal.com/computergeeks/970685.html

« New person with question || Kingston SD 2 Gb Ultimate 120x »


antivirus | apache | asp | blogging | browser | bugtracking | cms | crm | css | database | ebay | ecommerce | google | hosting | html | java | jsp | linux | microsoft | mysql | offshore | offshoring | oscommerce | php | postgresql | programming | rss | security | seo | shopping | software | spam | spyware | sql | technology | templates | tracker | virus | web | xml | yahoo | home