GGA Discussion Forums
GGA Forums
Non-Geocaching Topics Forum
Any Perlmonks in the house?|
Go
![]() |
New
![]() |
Find
![]() |
Notify
![]() |
Tools
![]() |
Reply
![]() |
|
Rinocacher![]() |
I'm a Perl novice, but have a few scripts I need to write. Can somebody tell me why either htis doesn't work or what I'm doing wrong? This is on a Win32 system, but shouldn't matter methinks. This will eventually be used on a mixture of Win32 and linux machines, but i'm testing it on Win for now, so the directory structure syntax isn't that important.
I'm trying to erase all files in explicit directories. To keep it simple, here's a few examples. unlink ("c:\\jason\\linktest\\*.*") || print "Cant unlink\n";gets me "Can't unlink", and no files deleted. unlink glob ("c:\\jason\linktest\*.*") || print "Cant link\n";gets me the first file in the directory deleted, not all of them. What gives? WRong command? Not enough syntax? Update: Found this in on oreilly gecko perl for win32, and it works, but i don't understand why: foreach (<c:\\jason\\linktest\\*.pl>) {unlink || print "Cant unlink.\n";}Still wanna know what's the best portal way if anybody has any advice. Thanks. [This message was edited by Cymbaline on February 13, 2004 at 05:29 PM.] |
||
|
Neutiquam erro.![]() |
I wouldn't call myself a perlmonk.
However here is my take on the problem unlink ("c:\\jason\\linktest\\*.*") || print "Cant unlink\n";This doesn't work becache unlink wants either a single file name or a list of file names. Since you didn't provide a list it tried to delete a file named c:\jason\linktest\*.* and didn't find one so deleted nothing. unlink glob ("c:\\jason\linktest\*.*") || print "Cant link\n";This one is somewhat esoteric, glob can return either a list of file names, which is what you were expecting or it can return one name at a time so that it can be put in a loop. This syntax cause it to return one name, the first name so it deleted that file. This is closer to what you want $DelCt = unlink glob ("c:\\jason\linktest\*.*");The "=" causes glob to return a list and unlink deletes them. But you don't know if all the files were deleted. I would have used something similar to oreilly version i.e foreach (glob("c:/jason/linktest/*.*")) {
unlink || print "Can't unlink $_.\n";
}The loop is needed if you want/need to know which file did not get deleted. I could have used <> instead of glob, they are equivalent, but I prefer to spell it out. The code could have been placed on one line but I like multiple lines for ease of reading. Also I changed your \\ to / because I write Perl on win32, Unix and Unix like OS's. Win32 Perl is smart enough to know if it the code is about files to translate the / to a \ when it does actual work so I just always use /. Also I inserted a $_ to print the filename. After what is the benefit of being able to tell which files were not deleted if you don't take advantage of it. As for which code is best? TMTOWTDI ----- Some of those that wander are lost! [This message was edited by AllenLacy on February 13, 2004 at 08:54 PM.] |
|||
|
phat.us cache.us![]() |
let me outta here!
Huh?! "Give to a pig when it grunts and a child when it cries, and you'll have a fine pig and a bad child." -Proverb |
|||
|
|
I Never Find Anything |
My head hurts -- AGAIN!
|
|||
|
Rinocacher![]() |
Actually, I'm gonna contact you offline 'cos perl is smarter than I am... you'll see the errors.
And apologizes to Phat and Trailerman. <edited to crrect spelling of names> [This message was edited by Cymbaline on February 16, 2004 at 11:23 AM.] |
|||
|
Geocacher![]() |
On the topic of perl monks, I seem to have lost my camel book, and I need a wee bit of guidance. I have gotten the image-switching perl script, and am interested in adapting it so that it can be called with a special parameter in the URL used to reference it, so that the images can be selected from multiple folders. Basically, I'd like to be able to have exactly one copy of the perl script, but multiple folders of images to choose from. I would then like to be able to pass a variable through the referencing URL (ala http://domain.com/cgi-bin/imagerotate.pl?=foldername) and the perl script will grab that and use that to select the folder to find the images to rotate in... Can this be done in perl?
|
|||
|
Neutiquam erro.![]() |
Yes, it can be done. But while not extremely complicated, it isn’t as simple as the current banner. It can be done with the CGI module.
----- Some of those that wander are lost! |
|||
|
| Previous Topic | Next Topic | powered by eve community |
| Please Wait. Your request is being processed... |
|
GGA Discussion Forums
GGA Forums
Non-Geocaching Topics Forum
Any Perlmonks in the house?
