diamond-operator

Perl's diamond operator: can it be done in bash?

Is there an idiomatic way to simulate Perl's diamond operator in bash? With the diamond operator, script.sh | ... reads stdin for its input and script.sh file1 file2 | ... reads file1 and file2 for its input. One other constraint is that I want to use the stdin in script.sh for something else other than input to my own script. Th...

Can I skip a whole file with the <> operator?

The following Perl code has an obvious inefficiency; while (<>) { if ($ARGV =~ /\d+\.\d+\.\d+/) {next;} ... or do something useful } The code will step through every line of the file we don't want. On the size of files this particular script is running on this is unlikely to make a noticeable difference, but for the sake of learnin...

Does the Perl diamond operator iterate over non-magic arrays (not @ARGV)?

I don't think the following should work, but it does: $ perl -e '@a = qw/1222 2 3/; while (<@a>) { print $_ ."\n";}' 1222 2 3 $ As far as I know, Perl's <> operator shoud work on filehandle, globs and so on, with the exception of the literal <> (instead of <FILEHANDLE>), which magically iterates over @ARGV. Does anyone know if it's s...

Why am I getting a closed filehandle error when using the diamond operator in list context in Perl?

This code: foreach my $file (@data_files) { open my $fh, '<', $file || croak "Could not open file $file!\n"; my @records = <$fh>; close $fh; .... } produces this error: readline() on closed filehandle $fh at nut_init_insert.pl line 29. and I have no idea why. EDIT: The original post had ',' instead of '<' in th...