You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by SubbaReddy M <m_...@hotmail.com> on 2002/02/14 11:04:56 UTC

How to step over the , while input redirection is not given at commandline

Hello Gurus,
Source code: of printFile.pl
#########   File: printFile.pl  ##################
#! /usr/bin/perl -w
my (@data, $user);

# Input rediretion file

$user = (defined @ARGV) ? shift @ARGV : "Anonymous";

# I don't wish to prompt by program, but it's still waiting how to Step Over
here
@data = <STDIN> if ( defined <STDIN>);

die  " perl $0 < data.txt" if (@data);

print "User: $user \n";
foreach (@data){
                            print $_;
}

1;
########### EOF #############



I have a perl scripts, which expects the input file as redirection at
command line.
i.e.,
[user3@Linux] #  perl printFile.pl  < data.txt

=> This will display the inputed file content, if file name is piped as
redirection.
=> Otherwise, program will wait to accept the file.
=> So, I don't want program prompt for the file name,
=> I would like to check the file name is given or not.
=> But, becuase of <STDIN> statement in program to dump the content of the
file into Array, will cause to wait if  " < data.txt" is missing at command
line.
=> It's very easy, if @ARGV checking, will have the command line parameters.
But, it 's not in command line paramenters list.
=> It is input redirection.

<=> How to check the input direction is given or not in perl, @ = <STDIN>;
=> like @ = <STDIN> if ( defined <STDIN> );   But this will not full fill
the requirement, because, it's prompting
for input, if redirection missing at commandline.

Please, kindly give me suggestions to proceed.

Thanks in advance.

Regards,

~ SubbaReddy .M
   Sr. Programmer, Frontlinesoft, Hyderabad
   http://www.frontlinesoft.com
   Ph: 91-40-3392147, 3391683 (O)
         91-40-3307980 ( R)
   w3page: http://www.geocities.com/msubbareddy/
   ICQ: 56093095

Re: How to step over the , while input redirection is not given at commandline

Posted by Dan Boger <da...@peeron.com>.
On Thu, Feb 14, 2002 at 03:34:56PM +0530, SubbaReddy M wrote:
> <=> How to check the input direction is given or not in perl, @ = <STDIN>;
> => like @ = <STDIN> if ( defined <STDIN> );   But this will not full fill
> the requirement, because, it's prompting
> for input, if redirection missing at commandline.

#!/usr/bin/perl

unless (-t STDIN) {
  @a = <STDIN>;
} else {
  print "No file\n";
}

HTH!

-- 
Dan Boger
Linux MVP
brainbench.com


Re: How to step over the , while input redirection is not given at commandline

Posted by Joshua Chamas <jo...@chamas.com>.
You should not cross post like this, especially if it is
off topic for so many lists like this was.  If you 
are going to do an off topic post, hit just the one
list of your choice, and prefix the Subject with [OT]
or some such.  If this were on topic for a list, hit
just the one.  You just hit a few thousand email addresses
with this one post.

Even if I knew the answer ( which I don't ), I would not
answer this email because I do not want to support this
misuse of these mailing lists.

--Josh

SubbaReddy M wrote:
> 
> Hello Gurus,
> Source code: of printFile.pl
> #########   File: printFile.pl  ##################
> #! /usr/bin/perl -w
> my (@data, $user);
> 
> # Input rediretion file
> 
> $user = (defined @ARGV) ? shift @ARGV : "Anonymous";
> 
> # I don't wish to prompt by program, but it's still waiting how to Step Over
> here
> @data = <STDIN> if ( defined <STDIN>);
> 
> die  " perl $0 < data.txt" if (@data);
> 
> print "User: $user \n";
> foreach (@data){
>                             print $_;
> }
> 
> 1;
> ########### EOF #############
> 
> I have a perl scripts, which expects the input file as redirection at
> command line.
> i.e.,
> [user3@Linux] #  perl printFile.pl  < data.txt
> 
> => This will display the inputed file content, if file name is piped as
> redirection.
> => Otherwise, program will wait to accept the file.
> => So, I don't want program prompt for the file name,
> => I would like to check the file name is given or not.
> => But, becuase of <STDIN> statement in program to dump the content of the
> file into Array, will cause to wait if  " < data.txt" is missing at command
> line.
> => It's very easy, if @ARGV checking, will have the command line parameters.
> But, it 's not in command line paramenters list.
> => It is input redirection.
> 
> <=> How to check the input direction is given or not in perl, @ = <STDIN>;
> => like @ = <STDIN> if ( defined <STDIN> );   But this will not full fill
> the requirement, because, it's prompting
> for input, if redirection missing at commandline.
> 
> Please, kindly give me suggestions to proceed.
> 
> Thanks in advance.
> 
> Regards,
> 
> ~ SubbaReddy .M
>    Sr. Programmer, Frontlinesoft, Hyderabad
>    http://www.frontlinesoft.com
>    Ph: 91-40-3392147, 3391683 (O)
>          91-40-3307980 ( R)
>    w3page: http://www.geocities.com/msubbareddy/
>    ICQ: 56093095

---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe@perl.apache.org
For additional commands, e-mail: asp-help@perl.apache.org