Jeff Westman wrote:
>
> Could someone help me please?
>
> I am trying to write a simple script that will take input from the command
> line as well as input from a pipe.
>
> For example, the script should be able to do both of the following:
>
> $ cat someFile | myPerlScript.pl # from a pipe
>
> and
>
> $ myPerlScript.pl someFile # from command line
>
> This is what I have (very simple):
>
> #----------------------- (begin) --------------------#
> #-- myScript.pl --#
> #
> #!/bin/perl
> use warnings;
>
> sub parseFile()
> {
> while (<>) { ## I tried passing in \*STDIN or \*F but
> ## had nothing but problems with that
>
> # do some processing to the file
> # ...
> print ". "; ## just to do something in the loop for now
> }
> }
>
> if (@ARGV) {
> $file = shift;
<> will open open and read through each line of the files listed in
@ARGV but you are removing the file names from @ARGV.
> open(F, "< $file") or die "cannot open file $file: $!\n";
> parseFile;
> close(F);
> }
> else {
> parseFile;
> }
> #----------------------- (end) --------------------#
sub parseFile()
{
while (<>) { ## I tried passing in \*STDIN or \*F but
## had nothing but problems with that
# do some processing to the file
# ...
print ". "; ## just to do something in the loop for now
}
}
if (@ARGV) {
parseFile;
}
else {
parseFile;
}
Or just:
sub parseFile()
{
while (<>) { ## I tried passing in \*STDIN or \*F but
## had nothing but problems with that
# do some processing to the file
# ...
print ". "; ## just to do something in the loop for now
}
}
parseFile;
> What is obvious to one is not always obvious to another.
Obviously. :-)
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]