Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!wuarchive!zaphod.mps.ohio-state.edu!sdd.hp.com!elroy.jpl.nasa.gov!jpl-devvax!lwall From: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Newsgroups: comp.lang.perl Subject: Re: bug with combination of loops and mechanism Message-ID: <9388@jpl-devvax.JPL.NASA.GOV> Date: 2 Sep 90 23:12:28 GMT References: Reply-To: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Organization: Jet Propulsion Laboratory, Pasadena, CA Lines: 47 In article composer@chem.bu.edu writes: : The script: : : #!/usr/bin/perl : # : while (1) { : $dir=<~user>; : print "DIR=$dir\n"; : } : : prints, assuming `~user' == `/foo/bar', : : DIR=/foo/bar : DIR= : DIR=/foo/bar : DIR= : : : : : : It seems that on every other iteration through the loop, no globbing is done : (i.e. no exec of csh occurs). That is the intended behaviour. <> is an iterator meant primarily to be used within a while. It's supposed to return false when it's done giving you the list of globbed filenames, one in this case. It then resets and starts over the next time. You want to say ($dir) = <~user>; though if you're just doing it for one user, it ought to be done outside the loop. Furthermore, it'll be much more efficient with the current implementation if you say $dir = (getpwnam('user'))[7]; because it won't have to start up csh, and will also be portable to machines that don't have csh. If you're doing it for many users, you should slurp it in like this: while (($user,$pass,$uid,$gid,$quota,$comment,$gcos,$dir,$shell) = getpwent) { $dir{$user} = $dir; # anything else you might want to know about them... } Larry