in reply to how to delete part of the line?

I am still stucks guys...

here is what I am doing:

my result.txt file has final output and it looks like below:
blah1.blah1.blah1=10 blah2.blah2.blah2=0 bhal3.blah3.blah3=false

here is my code after I get the result.txt file:

my $value = "value.txt" ;#final file I want with output as 10/0/false open RESULT, "<$result"; open VALUE, ">$value"; s/line\d+=(.*)// and print "$1/" while (<RESULT>); close VALUE; close RESULT;

am I doing anything wrong?

Please help!

Replies are listed 'Best First'.
Re^2: how to delete part of the line?
by ww (Archbishop) on May 23, 2009 at 02:19 UTC
    Yes! You are doing several things "wrong."

    Just for starters, you can't simply plug someone else's regex (cf: Cargo Cult) into an script to process utterly unrelated data and expect it to be anything other than "wrong."

    Your (borrowed) substitution looks for the word "line" followed by one-or-more digits, followed by anything, capturing the last of those. That's not the way your latest version of the data is structured. Since there isn't the word "line" anywhere in the data, the regular expression never matches.

    As linuxer advises "(p)lease see perlretut, perlrequick and perlre for more information about regular expressions."

    And to repeat myself, you need to be a great deal more precise in stating the problem. The use of "blah1.blah1.blah1" and so on as a stand-in for some actual data may be adequate to solve the question you asked, but is likely insufficient for us to provide help that will assist you to solve whatever your actual problem may be.

Re^2: how to delete part of the line?
by targetsmart (Curate) on May 22, 2009 at 05:54 UTC
    Where do you print the output to the output file?
    why can't you use chomp on input lines?
    watch other monk's replies to your post and experiment those, and chose the one which suits you.
    never go by the one liner method, it is not good for large programs, monks who showed those one liners actually wanted to say that your part of the requirement can be solved easily by those methods, it is not necessary that you have to follow that one liner method in your program, just understand that logic behind the one liner, and use it carefully at appropriate places inside your program.

    Vivek
    -- In accordance with the prarabdha of each, the One whose function it is to ordain makes each to act. What will not happen will never happen, whatever effort one may put forth. And what will happen will not fail to happen, however much one may seek to prevent it. This is certain. The part of wisdom therefore is to stay quiet.
Re^2: how to delete part of the line?
by walkingthecow (Friar) on May 22, 2009 at 07:03 UTC
    This may not be the best suggestion, but I can think of two ways to do this.

    At the unix command line: cat result.txt | cut -d"=" -f2 | sed 's/^ \t*//;s/ \t*$//' | tr "\n" "/"

    perl:
    #!/usr/bin/perl use strict; use warnings; while (chomp(my $line=<>)) { my (undef,$value)=split/=/,$line); $value =~ s/^\s+|\s+$//g; print "$value/"; }
Re^2: how to delete part of the line?
by linuxer (Curate) on May 22, 2009 at 08:20 UTC

    A regular expression line\d+= won't match with a text "blah1,blah1,blah1=".

    You must adjust your regular expression, so it can match your 'blah...' string.

    Please see perlretut, perlrequick and perlre for more information about regular expressions.

    And you must print to your output handle, if you want the result in value.txt. Currently you are printing to STDOUT; see print