A minor but (IMO) important quibble: <STDIN> and <> are not identical constructs. If you use the script without command-line arguments, they are, but if a file is specified in @ARGV, reading from the magic filehandle (<>) will read from that file, while reading from STDIN (<STDIN>) will read from the standard input, aka the terminal.

Example code:

#!/usr/bin/perl use strict; my $color; print "What is your favorite color? "; chomp ($color = <STDIN>); print <>; print "Just to check, your favorite color is $color, right? "; $_ = <STDIN>; if ( /^y/i ) { print "Phew!\n" } else { print "I don't believe you!\n"}

If run thus

perl myscript.pl random_file.txt
this should give us

What is your favorite color? Blue
[ contents of random_file.txt ]
Just to check, your favorite color is Blue, right?Yes!
Phew!

This is occasionally very useful behavior--I wouldn't be at all surprised if it was pretty much what you need, Satira.

And of course, in real quibble land, tachyon didn't mean an infinite loop, he meant a loop until the filehandle reaches EOF. :-) If you're looping on <>, this will take care of itself unless you do something foolish; if you're looping on STDIN, you can break out by giving the locally appropriate EOF character (control-D on most Unices and MacPerl, control-Z on Windows I think...).



If God had meant us to fly, he would *never* have give us the railroads.
    --Michael Flanders


In reply to Re: Re: Searching and Replacing by ChemBoy
in thread Searching and Replacing by Satira

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.