User Profile

Collapse

Profile Sidebar

Collapse
ramesh54
ramesh54
Last Activity: Oct 1 '08, 06:53 PM
Joined: Jul 7 '08
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • ramesh54
    replied to Replacing a string
    in Perl
    Thanks for the hint. I just modified a little bit and it is working well

    Code:
    $file =~ s/(<sub>)\s+(\w+)/$1Actual/;
    I have one more query,In the above problem,I print the first line and modify the second line.If in a file, if I have to modify the file at 4 places, Is it possible to do it under one while loop or do I need to open the file 4 times and use the while loop each time?
    See more | Go to post

    Leave a comment:


  • ramesh54
    replied to Replacing a string
    in Perl
    Hi Kevin,

    The exact data in my file is

    <main>x02_a08_s 091<main>
    <sub>Iteratio n problem<sub>

    In my file, only the numbers change in my first line and the name of the problem in this case is Iteration, but the title changes every time. I need to change the heading to 'Actual problem' from 'Iteration problem'. My intention is to...
    See more | Go to post

    Leave a comment:


  • ramesh54
    started a topic Replacing a string
    in Perl

    Replacing a string

    Hello All,

    I have two lines as follows in my file.
    <start>start of program<end>
    <start>string to be replaced<end>

    These lines are in the middle. There are blank spaces before the promt <. The sentence 'string to be replaced' need to be replaced by the sentence 'changed'.
    The sentences 'string to be replaced is not always the same.

    So...
    See more | Go to post

  • ramesh54
    replied to Reading the filename
    in Perl
    Hi Kevin,

    At last was able to make the code work well.

    I had split the file name in this form

    d124_${t1}_SF_t ${s1}_r${s2}_s$ {s3}_m${s4}_${s 5}grad.txt instead of defining as $f1 directly. Also in the rename function, the code with variables works only with double quotes(") not doesn't work with single quotes. Same is the case with open function. It is really surprising!

    Thanks for all...
    See more | Go to post

    Leave a comment:


  • ramesh54
    replied to Reading the filename
    in Perl
    I tried giving the full path, there is no change in the text file... Also I tired even the rename function, it is not renaming my file when code in variables.
    See more | Go to post

    Leave a comment:


  • ramesh54
    replied to Reading the filename
    in Perl
    Hi Kevin

    It is not recognizing the directory . .

    <../../x08_b03_e056/FD_m276_17zoll/r172_GD_EF_v08_ a03_e056_m276_1 7zoll.txt> :No
    such file or directory at t2.pl line 53, <> line 1.

    The folder name and file in the folder is the same as mentioned in the error but maybe the promt sysmbol is not recognized.
    See more | Go to post
    Last edited by ramesh54; Sep 14 '08, 07:57 AM. Reason: additional comments

    Leave a comment:


  • ramesh54
    replied to Reading the filename
    in Perl
    Hi Admin,

    I am sorry for the comment. I had misunderstood your comment as it was not clear.Now it is clear.

    Ramesh
    See more | Go to post

    Leave a comment:


  • ramesh54
    replied to Reading the filename
    in Perl
    Thanks for the help....The code works now.
    I went further with my code and got stuck up with this problem. I open my file and edit the file with replace function save it again.

    Code:
    open (IN,'+<','../../x02_a08_s091/GD_z124_17grad/d124_GD_SF_t02_r08_s091_z124_17grad.txt'); 
    open OUT,"+< ../../x02_a08_s091/GD_z124_17grad/d124_GD_SF_t02_r08_s091_z124_17grad.txt"; 
    while (<IN>) {
    s/rat/bat/g;
    ...
    See more | Go to post

    Leave a comment:


  • ramesh54
    replied to Reading the filename
    in Perl
    If you see my previous posts, I have been trying my own code. I am now trying to write my code which works for all files in variable form. Right from yesterday I have been waiting for your reply and it is surprising that I have not go the right solution till now. I am very sorry to hear that you have badly interpreted by saying that I have copied the code.
    See more | Go to post

    Leave a comment:


  • ramesh54
    replied to Reading the filename
    in Perl
    The test with mkdir function works well
    Code:
    mkdir("../../x${s1}_a${s2}_s${s3}") || print $!;
    mkdir("../../x${s1}_a${s2}_s${s3}/GD_z${s4}_${s5}grad") || print $!;
    I am able to get the actual name in my new folder as /x02_a08_s091/GD_z124_17grad. I guess there is some problem in my loop as it doesnot give the desired folder name.

    Code:
    my @dirs = qw[../../x${s1}_a${s2}_s${s3}/GD_z${s4}_${s5}grad];
    ...
    See more | Go to post

    Leave a comment:


  • ramesh54
    replied to Reading the filename
    in Perl
    Sorry I had typed the code wrong

    Code:
    my @dirs = qw[../../${t5}/${t3}];
    for my $dir (@dirs) {
    mkpath($dir) or die $!;
    }
    But even then I am unable to get the folders with the right name.

    To make a simple test I tried rewriting the code as follows

    Code:
    mkdir ../../$t5/$t3;
    - It says folder not found.
    See more | Go to post

    Leave a comment:


  • ramesh54
    replied to Reading the filename
    in Perl
    In my earlier query I had typed my definition of my variable wrong, it is t3 as GD_z124_17grad. and t5 defined as x02_a08_s091. In the code it is defined properly.Still my problem is not solved as I get the folder defined in the form ${t5}/${t3} and not actual name.
    See more | Go to post

    Leave a comment:


  • ramesh54
    replied to Reading the filename
    in Perl
    I have t3 defined as x02_a08_s091 and t5 defined as GD_z124_17grad. So when I need to create the folder, I get the folder with the name ${t5}/${t3} and not actual name.

    Code:
    #!/usr/bin/perl 
    use strict;
    use File::Path;
    use File::Copy;
    print "Enter the basis file: ";
    my $file = <>;
    chomp($file);
    my $f1 = $file;
    print "$f1 \n";
    my $t1=substr($f1,8,2);
    ...
    See more | Go to post

    Leave a comment:


  • ramesh54
    replied to Reading the filename
    in Perl
    Hello Jeff now it is clear with your instructions. I would like to know your suggestion for my earlier query. I hope this query satisfies the code tags..

    Now that I have split my filename in variable form like t1, t2 ,t3.
    When i need to create new folders, I need to specify the directory path in terms of variables.
    Code:
    1. my @dirs = qw[../../x01_a05_s089/RD_z121_18grad];
    How do I define the above path in terms of...
    See more | Go to post

    Leave a comment:


  • ramesh54
    replied to Reading the filename
    in Perl
    Hello Jeff,

    Sorry about the code tags. I went through your article and I have listed only the code which I have tried. What is the error in my code tags.

    Ramesh
    See more | Go to post

    Leave a comment:


  • ramesh54
    replied to Reading the filename
    in Perl
    I have found the error in my code
    my $t6= substr($t5, 0,1) = "x";
    See more | Go to post

    Leave a comment:


  • ramesh54
    replied to Reading the filename
    in Perl
    Adding to my earlier query, I am unable to use the replace function in substr.

    From the filename, I store the particular file name as a variable and I would like to replace the firts variable. I tired this, but i find that it prints only the replaced letter. i would like to replace t01_r05_s089 as x01_a05_s089.
    Code:
    #!/usr/bin/perl 
    use strict;
    use File::Path;
    use File::Copy;
    print "Enter
    ...
    See more | Go to post
    Last edited by numberwhun; Sep 11 '08, 11:46 AM. Reason: Please use code tags

    Leave a comment:


  • ramesh54
    replied to Reading the filename
    in Perl
    Thanks for the hint. I have another query.
    Now that I have defined the filename in variable form like t1, t2 ,t3.
    When i need to create new folders, I need to specify the directory path in terms of variables.
    Code: ( text )

    1. my @dirs = qw[../../x01_a05_s089/RD_z121_18grad];

    How do I define the above path in terms of variables.
    See more | Go to post

    Leave a comment:


  • ramesh54
    replied to Reading the filename
    in Perl
    Yes it is fixed length. Is it right to define the variables separately as follows,

    1. $file ='d124_RD_SF_t0 1_r05_s089_z121 _18grad.txt'
    2. $t1 =substr($file,5 ,2) # which is RD
    3. $t2 =substr($file,1 1,12) # which is t01_r05_s089
    and so on.....

    Then I write the code in the form of defined variables. How do I combine two variables together. For example I have a folder name RD_z121_18grad.
    See more | Go to post

    Leave a comment:


  • ramesh54
    started a topic Reading the filename
    in Perl

    Reading the filename

    Hello All,

    I have a small problem in reading the filename of a file. I would like to have a script which could read my file and create the respective folders,

    The file to be read is as follows d124_RD_SF_t01_ r05_s089_z121_1 8grad.txt

    folders and sub folders should be as follows

    1. /x01_a05_s089/RD_z121_18grad

    2. /x01_c05_s089/RD_z121_18grad

    I have the following...
    See more | Go to post
    Last edited by numberwhun; Sep 10 '08, 06:24 PM. Reason: Please use code tags
No activity results to display
Show More
Working...