At 17:53 -0500 17/08/2011, Bryan R Harris wrote:
How can I do a 3-argument open on STDIN? This doesn't work because the 3-argument open won't open STDIN when you tell it to open "-". ************************************** @files = ("-"); for (@files) { print reverse readfile($_); } [...]
That makes no sense to me at all. I see no mention of STDIN in the script and see you are trying to open and read a single file named "-", which is pretty odd.
If this below is your script "test.pl" and you run it from the Terminal or command line...
#!/usr/bin/perl use strict; use warnings; print "Enter file names separated by space\n--> "; my @files = split /\s+/, <STDIN>; foreach my $file (@files){ undef my @lines; open my $fh, "<$file" or die $!; print "\n____File: $file\____\n"; while (<$fh>){ chomp; unshift @lines, $_; } for (@lines){ print "$_\n"; } } END This is what you will get:
perl test.pl
Enter file names separated by space --> a.txt b.txt c.txt ____File: a.txt____ e d c b a ____File: b.txt____ j i h g f ____File: c.txt____ o n m l k -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/