Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: How to handle both a STDIN pipe and file from command line?

by ramlight (Friar)
on Mar 13, 2013 at 19:40 UTC ( #1023289=note: print w/replies, xml ) Need Help??

in reply to How to handle both a STDIN pipe and file from command line?

If you're going for the minimum in terseness; you can always use a temporary file:

./print_list >/temp/temp.txt; perl temp.txt file.txt; rm temp.txt would read from the first file, then use the contents to substitute in the second file:

use strict; use warnings; open(my $file1, '<', $ARGV[0]) or die "Can't open $ARGV[0]: $!\n"; my @substitutions = <$file1>; close($file1); chomp(@substitutions); open(my $file2, '<', $ARGV[1]) or die "Can't open $ARGV[1]: $!\n"; while(my $line = <$file2>) { for my $replace (@substitutions) { next unless $replace; # skip blanks $line =~ s/\Q$replace\E/foo/g; } print $line; } close($file2);

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2022-08-08 18:35 GMT
Find Nodes?
    Voting Booth?

    No recent polls found