Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re: how to delete part of the line?

by linuxer (Curate)
on May 22, 2009 at 00:50 UTC ( #765581=note: print w/replies, xml ) Need Help??

in reply to how to delete part of the line?

Instead of deleting the unwanted part, you could split each line into parts and just use the wanted part.

#! /usr/bin/perl use strict; use warnings; my $in_file = 'input.txt'; my $out_file = 'output.txt'; my @result; open my $handle_in, '<', $in_file or die "$in_file: $!"; while ( <$handle_in> ) { # split (into 2 parts) at = (enclosed in optional whitespaces) # use the last part and store it in @result push @result, ( split( /\s*=\s*/, $_, 2 ) )[-1]; } close $handle_in; # remove line breaks from array elements chomp @result; open my $handle_out, '>', $out_file or die "$out_file: $!"; # print elements (ignore undefined and empty ones) print $handle_out join( '/', grep { defined && length > 0 } @result ) or die "$out_file: $!"; close $handle_out or die "$out_file: $!"; __END__

Considering ww's message you might need to add more checks and logic to match more complicated input files.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://765581]
Happy-the-monk orders a Punk IPA.
[Your Mother]: Also, I'm too old to start fights with strangers anymore.
[LanX]: concentrating on omestic violence?
[LanX]: d
[Your Mother]: Open air violence. Or on campus.

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (18)
As of 2018-03-19 13:49 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (240 votes). Check out past polls.