Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re: sed in perl

by Corion (Patriarch)
on Nov 11, 2019 at 10:33 UTC ( #11108549=note: print w/replies, xml ) Need Help??

in reply to sed in perl

Why are you using sed when you can use Perl directly?

open my $fh1, '<', "file1" or die "Couldn't read 'file1': $!"; my %delete = map { s/\s*$//; $_ => 1 } <$fh1>; open my $fh2, '<', "file2" or die "Couldn't read 'file2': $!"; while( <$fh2>) { my( $key, $value ) = split /\s*=/; if( ! $delete{ $key }) { print $_; } else { # skip this key }; };

If you want to keep on using sed, my advice is to print all the commands you're launching and then inspecting them or running them from the command line separately.

Replies are listed 'Best First'.
Re^2: sed in perl
by GauCho (Initiate) on Nov 14, 2019 at 06:05 UTC
    I tried printing the sed command and to my surprise, sed is not working as expected. i get "/d' <file2>" as command and sed is nowhere part of the command. i will try out the perl code!

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11108549]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (2)
As of 2022-05-22 05:29 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (79 votes). Check out past polls.