nall@sun8.scri.fsu.edu (John Nall) (06/28/90)
The following script: #!/bin/perl if ($_ = <>) { print ; } will allow one to enter a line of data, and then print it out. Which is what it is supposed to do. However, the following script: #!/bin/perl if (<>) { print ; } will allow one to enter a line of data, and then exits without ever printing it out. (This is, of course, a simplified example). I thought that $_ was the default, so the two should be equivalent. Am I doing something wrong? Or is it a bug? (Obviously, it is easy to workaround, so I'm more concerned with whether or not I am misunderstanding the manual than anything else). -- John W. Nall | Supercomputation Computations Research Institute nall@sun8.scri.fsu.edu | Florida State University, Tallahassee, FL 32306 "They said it couldn't be done/they said nobody could do it/ But he tried the thing that couldn't be done!/He tried - and he couldn't do it"
merlyn@iwarp.intel.com (Randal Schwartz) (06/29/90)
In article <163@sun13.scri.fsu.edu>, nall@sun8 (John Nall) writes: | I thought that $_ was the default, so the two should be equivalent. | Am I doing something wrong? Or is it a bug? (Obviously, it is | easy to workaround, so I'm more concerned with whether or not I am | misunderstanding the manual than anything else). The relevant portion from the manpage says: ....... If (and only if) the input symbol is the only thing inside the conditional of a while loop, the value is automatically assigned to the variable "$_". .............. Doesn't say anything about the conditional of an "if". In fact, early releases wouldn't let you say: print while <>; Instead, you had to say: print while $_ = <>; print "$ARGV[push(@ARGV,'Just another Perl hacker,')]" -- /=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\ | on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III | | merlyn@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn | \=Cute Quote: "Welcome to Portland, Oregon, home of the California Raisins!"=/