Please don't top post.

On 4/27/07, Somu <[EMAIL PROTECTED]> wrote:
Please give me one simple example using glob.. I saw the perlopentut,
and perldoc -f open, and perldoc -f glob, but i am unable to make out
anything from them.. I know only how to open files which are in the
same dir or child dir.. But suppose i am in dir D:/Scripts/Test and i
want to open another file E:/Games/readme.txt how do i do it?


open(FH, "<", 'E:\Games\readme.txt');

You've asked four separate questions here: one on paths, one on
globbing, one on finding files, and one pipes. You should probably
split them up into four threads, but here goes:

If you had really read the glob perldoc, you would have seen that it
points you to File::Glob where everything is expalined and there are
at least six examples.  Briefly, then, globbing is a way of generating
lists of files that match certain criteria. It deliberately imitates
the behavior of popular unix shells. Something like

   my @files = <*.doc>;

will find all the files in the current directory with filenames ending
in ".doc". To use it with open, you'd put it in a loop, e.g.:

   while (<*.doc>) {
       open(FH, ">", $_) or die "$!\n";
       # do something
       close FH;
   }

This makes it convenient to work with multiple files that match a
particular patter, but it doesn't change the fact that to open a file,
you have to know where it is. since only you know your filesystem and
where your files might be stored, you have to provide a valid relative
or absolute path. If you don't know where the file is, you need to
find it somehow. File::Find would be a good place to start.

Pipes are something else entirely. A pipe lets you pass output from
from one program to another. opening a pipe for reading will let you
read the output of another program into your perl program. Opening a
pipe for writing will pass whatever you write to the filehandle to an
external program. So something like

   open(FH, ">", "| /WINDOWS/System32/notepad.exe") or die "$!\n";

Would send anythig you print to FH on along to notepad. But since
notepad doesn't, I think, read from STDIN, it probably won't do
anything useful. You'll probably need to use Win32::OLE or some other
Windows API to pass your data to notepad.

HTH

-- jay
--------------------------------------------------
This email and attachment(s): [  ] blogable; [ x ] ask first; [  ]
private and confidential

daggerquill [at] gmail [dot] com
http://www.tuaw.com  http://www.downloadsquad.com  http://www.engatiki.org

values of β will give rise to dom!

Reply via email to