sharan has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I am new to perl. I seek ur help in writing a program. I am trying to read a file with some whose data looks like:
process Iknow_thesimplecase_ is _finding_all_out; bdjh_pond_endannot_in; gsjad_pond_out; begin_in;
I need to get the output without any "_in" and "_out" at the end of the data. Output as:
Iknow_thesimplecase_ is _finding_all bdjh_pond_endannot gsjad_pond begin
I dont know hoe to proceed with this. Could you please guide me through this. Thanking you

Replies are listed 'Best First'.
Re: read few alphabets from a given data
by kennethk (Abbot) on Feb 25, 2009 at 17:03 UTC

    Welcome to the Monastery.

    Attacking your problem should have 3 steps: "How do I read a file?", "How do substitutions on a string?" and "How do I output the result?". For the first, you'll likely want to use open and read, for the second you'll want to use a regular expression and then lastly you'll want to use print statements. A sample code follows, though you could certainly create more succinct and faster code one you gain familiarity:

    use strict; use warnings; # Read data into an array open my $fh, "<", "input.txt"; my @strings = (); while (my $line = <$fh>) { chomp $line; push @strings, $line; } close $fh; # Replace trailing _in and _out foreach my $line (@strings) { $line =~ s/\_in$|\_out$//; } # Output to STDOUT foreach my $line (@strings) { print $line, "\n"; }
Re: read few alphabets from a given data
by Fletch (Bishop) on Feb 25, 2009 at 17:14 UTC

    Perhaps you'd be better off explaining what of the several solutions to your other all but identical post three hours ago wasn't sufficient . . .

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

Re: read few alphabets from a given data
by targetsmart (Curate) on Feb 25, 2009 at 16:59 UTC
    the below code will do it
    perl -e 's/(_in$)|(_out$)//g' -np
    see man perlre and perlretut and learn regular expressions.

    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.