FAQ
Hi everybody...
Supose that i have a file that i have to use many times.
But, in that file is a line that changes everytime that i have
to use the file.
I know the number of that line.
May I only overwrite that line everytime I need the file or
I am obligated, like i'm doing now, to write the entire file
of each time i have to use it.

This is the file that i have to write

==============================================================

1 global env tcl_platform
2 source "$env(ASCENDTK)/ascend.tcl"
3 READ FILE "~/ascdata/heat_recover/heat_recover.a4c";
4 COMPILE hr OF heat_recover;
5 RUN {hr.reset};
6 RUN {hr.values};
7 ASSIGN {hr.T2} 150 {Kelvin};
8 SOLVE {hr} WITH QRSlv;
9 WRITE VALUES {hr.FOB}
"heat_recover/results/FOB_heat_recover150.dat";
10 exit;

==============================================================

And, at everytime I use it, the only change is the value 150 at line 7.

Can someone give me a tip?

Thank you very much!!

--
Helder Gomes da Silva

e-mail: hgsilva@fe.up.pt
URL: http://www.fe.up.pt/~hgsilva

Search Discussions

  • George P. at May 14, 2003 at 11:41 am

    On Wed, 14 May 2003, Helder Gomes da Silva wrote:

    Hi everybody...
    Supose that i have a file that i have to use many times.
    But, in that file is a line that changes everytime that i have
    to use the file.
    I know the number of that line.
    May I only overwrite that line everytime I need the file or
    I am obligated, like i'm doing now, to write the entire file
    of each time i have to use it.

    This is the file that i have to write

    ==============================================================

    1 global env tcl_platform
    2 source "$env(ASCENDTK)/ascend.tcl"
    3 READ FILE "~/ascdata/heat_recover/heat_recover.a4c";
    4 COMPILE hr OF heat_recover;
    5 RUN {hr.reset};
    6 RUN {hr.values};
    7 ASSIGN {hr.T2} 150 {Kelvin};
    8 SOLVE {hr} WITH QRSlv;
    9 WRITE VALUES {hr.FOB}
    "heat_recover/results/FOB_heat_recover150.dat";
    10 exit;

    ==============================================================

    And, at everytime I use it, the only change is the value 150 at line 7.

    Can someone give me a tip?
    I'm not sure what you want to do.. but, if you have to use the file
    contents many times in one program, you could push the entire file
    into an array. This way, you can also change any line you want.

    my (@lns);
    open(F1, "< $file") or die("ERROR: Cannot open $file: $!\n");
    @lns = <>;
    close F1;

    $lns[6] =~ s/} \d+ {/} 100 {/;
    ## Above I'm changing all digits between "} " and " {"
    ## to 100 on the 7th line.

    -George P.

    Thank you very much!!

    --
    Helder Gomes da Silva

    e-mail: hgsilva@fe.up.pt
    URL: http://www.fe.up.pt/~hgsilva



    --
    To unsubscribe, e-mail: beginners-unsubscribe@perl.org
    For additional commands, e-mail: beginners-help@perl.org
  • Sudarshan Raghavan at May 14, 2003 at 11:51 am

    George P. wrote:
    On Wed, 14 May 2003, Helder Gomes da Silva wrote:


    Hi everybody...
    Supose that i have a file that i have to use many times.
    But, in that file is a line that changes everytime that i have
    to use the file.
    I know the number of that line.
    May I only overwrite that line everytime I need the file or
    I am obligated, like i'm doing now, to write the entire file
    of each time i have to use it.

    This is the file that i have to write

    ==============================================================

    1 global env tcl_platform
    2 source "$env(ASCENDTK)/ascend.tcl"
    3 READ FILE "~/ascdata/heat_recover/heat_recover.a4c";
    4 COMPILE hr OF heat_recover;
    5 RUN {hr.reset};
    6 RUN {hr.values};
    7 ASSIGN {hr.T2} 150 {Kelvin};
    8 SOLVE {hr} WITH QRSlv;
    9 WRITE VALUES {hr.FOB}
    "heat_recover/results/FOB_heat_recover150.dat";
    10 exit;

    ==============================================================

    And, at everytime I use it, the only change is the value 150 at line 7.

    Can someone give me a tip?
    Tie::File will be of interest to the OP. It is a part of 5.8 standard
    distribution.
    If you don't have a 5.8 installation, you can download and install the
    module from
    http://search.cpan.org/author/MJD/Tie-File-0.95/
    I'm not sure what you want to do.. but, if you have to use the file
    contents many times in one program, you could push the entire file
    into an array. This way, you can also change any line you want.

    my (@lns);
    open(F1, "< $file") or die("ERROR: Cannot open $file: $!\n");
    @lns = <>;
    close F1;

    $lns[6] =~ s/} \d+ {/} 100 {/;
    ## Above I'm changing all digits between "} " and " {"
    ## to 100 on the 7th line.

    -George P.



    Thank you very much!!

    --
    Helder Gomes da Silva

    e-mail: hgsilva@fe.up.pt
    URL: http://www.fe.up.pt/~hgsilva



    --
    To unsubscribe, e-mail: beginners-unsubscribe@perl.org
    For additional commands, e-mail: beginners-help@perl.org



  • Rob Dixon at May 14, 2003 at 1:55 pm

    Helder Gomes Da Silva wrote:
    Hi everybody...
    Supose that i have a file that i have to use many times.
    But, in that file is a line that changes everytime that i have
    to use the file.
    I know the number of that line.
    May I only overwrite that line everytime I need the file or
    I am obligated, like i'm doing now, to write the entire file
    of each time i have to use it.

    This is the file that i have to write

    ==============================================================

    1 global env tcl_platform
    2 source "$env(ASCENDTK)/ascend.tcl"
    3 READ FILE "~/ascdata/heat_recover/heat_recover.a4c";
    4 COMPILE hr OF heat_recover;
    5 RUN {hr.reset};
    6 RUN {hr.values};
    7 ASSIGN {hr.T2} 150 {Kelvin};
    8 SOLVE {hr} WITH QRSlv;
    9 WRITE VALUES {hr.FOB} "heat_recover/results/FOB_heat_recover150.dat";
    10 exit;

    ==============================================================

    And, at everytime I use it, the only change is the value 150 at line 7.

    Can someone give me a tip?
    Hi.

    Can I assume that 'using' this file just involves rewriting
    it with a different temperature? If this is the case then
    it can be done in a single command line like this:

    perl -pi -e "s/\b\d+\b/newnumber/ if /^ASSIGN\n/"

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupbeginners @
categoriesperl
postedMay 14, '03 at 11:08a
activeMay 14, '03 at 1:55p
posts4
users4
websiteperl.org

People

Translate

site design / logo © 2022 Grokbase