CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
stdin input

 



frist44
User

Oct 1, 2009, 11:27 AM

Post #1 of 5 (411 views)
stdin input Can't Post

I'm trying to get a log file parse out from the command line. When I do the following, i get no output:


Code
while ($test = <STDIN>) { 
print $test;
}


However, if i do the following, I get the output


Code
foreach (@ARGV) { 
open(F,$_);
while (<F>) {
print;
}
}


Why doesn't the first one work?

I'm doing the following on the command line: script.pl < logfile.log


shawnhcorey
Enthusiast


Oct 1, 2009, 12:11 PM

Post #2 of 5 (407 views)
Re: [frist44] stdin input [In reply to] Can't Post


In Reply To
I'm trying to get a log file parse out from the command line. When I do the following, i get no output:


Code
while ($test = <STDIN>) { 
print $test;
}


However, if i do the following, I get the output


Code
foreach (@ARGV) { 
open(F,$_);
while (<F>) {
print;
}
}


Why doesn't the first one work?

I'm doing the following on the command line: script.pl < logfile.log


Try:

Code
while( $test = <> ){ 
print $test;
}


The operator <> reads from the pseudo-file created from the files listed on the command line. If there are none, it reads from the STDIN.

See `perldoc perlop` and search for /I/O Operators/ http://perldoc.perl.org/perlop.html#I%2fO-Operators

__END__

I love Perl; it's the only language where you can bless your thingy.

Perl documentation is available at perldoc.perl.org. The list of standard modules and pragmatics is available in perlmodlib.

Get Markup Help. Please note the markup tag of "code".


frist44
User

Oct 1, 2009, 12:31 PM

Post #3 of 5 (406 views)
Re: [shawnhcorey] stdin input [In reply to] Can't Post

No change.


frist44
User

Oct 1, 2009, 1:44 PM

Post #4 of 5 (400 views)
Re: [frist44] stdin input [In reply to] Can't Post

I had to run it from the command line without the "<"


shawnhcorey
Enthusiast


Oct 1, 2009, 1:45 PM

Post #5 of 5 (400 views)
Re: [frist44] stdin input [In reply to] Can't Post


In Reply To
No change.


Does this command work with my suggestion?

script.pl logfile.log

__END__

I love Perl; it's the only language where you can bless your thingy.

Perl documentation is available at perldoc.perl.org. The list of standard modules and pragmatics is available in perlmodlib.

Get Markup Help. Please note the markup tag of "code".

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives