[24199] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 6391 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Apr 13 00:05:44 2004

Date: Mon, 12 Apr 2004 21:05:09 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Mon, 12 Apr 2004     Volume: 10 Number: 6391

Today's topics:
        3x3 simple puzzle <perl@my-header.org>
        compression <todd@asgweb.net>
    Re: compression <noreply@gunnar.cc>
    Re: Design choice: subclassing or "supplementing" <abigail@abigail.nl>
    Re: Design choice: subclassing or "supplementing" <abigail@abigail.nl>
        Finding URL in Textfield, then editing it (Mike)
    Re: How can I follow links in my website <tore@aursand.no>
    Re: Many filename arguments: EOF in "while(@slurp=<>){. <fma@doe.carleton.ca>
        MS Access Date/Time Data type mismatch (Jacquo Johnson)
    Re: new bbs <robin @ infusedlight.net>
    Re: new bbs <robin @ infusedlight.net>
    Re: new bbs <ittyspam@yahoo.com>
    Re: new bbs <tadmc@augustmail.com>
    Re: new bbs <robin @ infusedlight.net>
    Re: new bbs <robin @ infusedlight.net>
    Re: new bbs (Sam Holden)
    Re: Newbie Question... (EddieJ)
    Re: Newbie Question... <ittyspam@yahoo.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Tue, 13 Apr 2004 01:12:43 +0200
From: Matija Papec <perl@my-header.org>
Subject: 3x3 simple puzzle
Message-Id: <ni8m70l17eic65l4ndp5d64j9rsb050qsp@4ax.com>


Ok, there are two solutions for these turtles,
http://globalnet.hr/~mpapec/perl/turtles3x3.jpg
They have to be in 3x3 matrix so that colors and body parts match
(head/tail).

I wrote a perl script which finds them in 8min (Duron 750mhz); anyone
interested in some turtle solving?


-- 
Matija


------------------------------

Date: Mon, 12 Apr 2004 16:47:49 -0600
From: Todd Anderson <todd@asgweb.net>
Subject: compression
Message-Id: <407B1B92.8851995F@asgweb.net>

Hello,
So what's the best program for crompressing my PERL scripts and creating
 .exe and zip archives?



------------------------------

Date: Tue, 13 Apr 2004 03:32:02 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: compression
Message-Id: <c5fftn$12tn2$1@ID-184292.news.uni-berlin.de>

Todd Anderson wrote:
> So what's the best program for crompressing my PERL scripts and
> creating .exe and zip archives?

WinZip? :)

As regards creating .zip archives with Perl, you can use the CPAN
module Archive::Zip. Don't know about .exe. Did you look in CPAN?

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



------------------------------

Date: 12 Apr 2004 22:50:09 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Design choice: subclassing or "supplementing"
Message-Id: <slrnc7m791.egl.abigail@alexandra.abigail.nl>

David K. Wall (dwall@fastmail.fm) wrote on MMMDCCCLXXIV September
MCMXCIII in <URL:news:Xns94C6993E413Edkwwashere@216.168.3.30>:
()  J Krugman <jkrugman@yahbitoo.com> wrote:
()  
() > I have this class from CPAN (let's call it, creatively enough,
() > Foo) that suits me fine in almost every respect, except for one
() > workhorse method (say, bar) that I think could be significantly
() > enhanced. One possibility would be to create a subclass MyFoo of
() > Foo just for the purpose of overriding bar.  Alternatively, I
() > could have a file FooSupplement.pm, in which I do something like
()  [redefining a method instead of subclassing and overriding it]
()  
()  I'm no OOP guru, in fact I'm a downright novice at OOP, so keep that
()  in mind.
()  
()  Subclassing and overriding the method seems to me the better way.  
()  
()  If you simply redefine the method, then someone reading your code
()  might look at the docs for Foo.pm and then wonder why bar() is not
()  functioning as documented. Yes, they should have looked at the docs 
()  for FooSupplement as well, but why look there for a method for a Foo 
()  object?

I don't buy that argument. Why would someone reading your code and
wanting to look up the documentation for 'bar()' in Foo.pm? The code
contains a call to a function 'bar()', which turns out not to be 
defined in the file. The code also uses two classes.

I'd say any programmer that just ignores 50% of the inherited modules,
and only searches the documentation for the other half deserves what
he gets.

()  If you subclass, then your "main" program says 'use MyFoo;' and the
()  maintenance programmer knows to look at MyFoo.pm instead of Foo.pm. 

But in the given example, the code says "use FooSupplement". So, why 
*wouldn't* the maintainance programmer look there (which he doesn't
according to you)?



Abigail
-- 
use   lib sub {($\) = split /\./ => pop; print $"};
eval "use Just" || eval "use another" || eval "use Perl" || eval "use Hacker";


------------------------------

Date: 12 Apr 2004 22:55:31 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Design choice: subclassing or "supplementing"
Message-Id: <slrnc7m7j3.egl.abigail@alexandra.abigail.nl>

Anno Siegel (anno4000@lublin.zrz.tu-berlin.de) wrote on MMMDCCCLXXIV
September MCMXCIII in <URL:news:c575e7$q5$1@mamenchi.zrz.TU-Berlin.DE>:
&&  J Krugman  <jkrugman@yahbitoo.com> wrote in comp.lang.perl.misc:
&& > 
&& > 
&& > 
&& > 
&& > I have this class from CPAN (let's call it, creatively enough, Foo)
&& > that suits me fine in almost every respect, except for one workhorse
&& > method (say, bar) that I think could be significantly enhanced.
&& > One possibility would be to create a subclass MyFoo of Foo just
&& > for the purpose of overriding bar.
&&  
&&  Overriding base class methods is more than just replacement.  If
&&  the base class uses the overridden method internally, it will call
&&  the *overriding* method on objects from your (inheriting) class.
&&  This is what allows old code to call new code in OO, and it is at the
&&  heart of inheritance.

I don't get your point here. If you replace the method, old code will
call new code as well. The difference is when the base class calls
the method in the non-OO way - then with overriding the original code
will be called, with replacing, the new code.

But calling methods as regular subs is a dubious practise.



Abigail
-- 
perl -we 'print q{print q{print q{print q{print q{print q{print q{print q{print 
               qq{Just Another Perl Hacker\n}}}}}}}}}'    |\
perl -w | perl -w | perl -w | perl -w | perl -w | perl -w | perl -w | perl -w


------------------------------

Date: 12 Apr 2004 19:41:37 -0700
From: csdude@hotmail.com (Mike)
Subject: Finding URL in Textfield, then editing it
Message-Id: <46cdc619.0404121841.5becacbd@posting.google.com>

I'm letting visitors submit things via a textfield to be saved to a
flat-text database. What I would like to do is search their submission
for anything appearing to be a website, then edit it to at the link to
it.

For instance, if they type in "go to www.google.com" or "go to
http://www.google.com," it would be edited to "go to <a
href='http://www.google.com' target='_new'>www.google.com</a>" (or
with the http://)

Before I try to re-invent the wheel here, I was wondering if there's a
simple way, or a way that's already being used, to do this?

If not, then I'm thinking that I could ask the visitor to surround it
by [ ] or something, then work with that, but if there's a better way,
I'm all for it!

TIA,

Mike


------------------------------

Date: Tue, 13 Apr 2004 01:48:25 +0200
From: Tore Aursand <tore@aursand.no>
Subject: Re: How can I follow links in my website
Message-Id: <pan.2004.04.12.23.38.56.904356@aursand.no>

On Mon, 12 Apr 2004 15:06:11 +0000, Danny wrote:
> I would like to browse a page in one of my websites and get info to
> populate a database.  But each page will have a NEXT and PREVIOUS link
> that takes you to another page.
> 
> I need something to look at one page and save it to a file on the HD,
> then follow the NEXT link and go to the next page, and do the same
> thing, and so on.

Just a question:  If it's one of _your_ sites ... don't you already have
the content for that site stored somewhere/somehow?


-- 
Tore Aursand <tore@aursand.no>
"Anyone who slaps a 'this page is best viewed with Browser X'-label on
 a web page appears to be yearning for the bad old days, before the
 web, when you had very little chance of reading a document written on
 another computer, another word processor or another network." -- Tim
 Berners-Lee, July 1996


------------------------------

Date: 13 Apr 2004 01:23:39 GMT
From: Fred Ma <fma@doe.carleton.ca>
Subject: Re: Many filename arguments: EOF in "while(@slurp=<>){..}"?
Message-Id: <407B4114.2CEF81BF@doe.carleton.ca>

Tad McClellan wrote:
> 
> Fred Ma <fma@doe.carleton.ca> wrote:
> 
> > This was in order to understand
> > how perl recognizes different files so that it can rename the
> > originals, the case of "-i.bak".
> 
> >    #!/bin/perl -w
> >    my @slurp;
> >    while (@slurp=<>) {
> 
> Why a while() rather than the more usual foreach() ?

Haven't gotten to foreach yet.  I just wanted to understand at the
fundamental level the simple examples I encountered in the perldoc.  I
already have 4 xterms open to various pieces of perldoc, so I'm taking
a bite at a time.

> The 1st iteration will read all of the lines from all of the
> files named in @ARGV (at which point @ARGV will be empty).
> 
> The 2nd iteration will read lines from STDIN since @ARGV is empty.

Does this mean that the file handle in the 1st case are bound to the
actual files themselves (one after another), while in the 2nd case,
the lines of those files are somehow made to come from stdin?

Does the elements of @argv actually get consumed?  I'm trying to find
this in the perldoc....

> > Conclusion: perl has some other mechanism to recognize the different
> > files for renaming when using -p.bak.
> 
> Right you are. See eof(ARGV) in
> 
>    perldoc -f eof
> 
> > Now for the confusing part:  What is Perl waiting for?
> 
> Some input on STDIN for the 2nd loop iteration.

Thanks for that.  It certainly clears up some of my confusion.

> > Why is the
> > cursor waiting under the "D" until I press ^D?
> 
> Because you told it to.  :-)

Yes, I'm sure.  I guess I was trying to figure out how I did.
The eof page helps alot.

> > Why doesn't this
> > happen when the implied $_ is used instead of @slurp?
> 
> Because you eventually get to eof and <> gives you undef, which
> is false, so the loop exits at that point.

So this seems to support my guess that when assigning <> to a
scalar, the "pseudohandle" represents the file itself rather than
STDIN?

> > I can see that
> > if @slurp comes up empty, "DOG" is printed,
> > and the loop is repeated,
> 
> That is incorrect.
> 
> If @slurp comes up empty then the while() condition is false and
> the loop should exit, not repeat, and the continue block should
> not be executed since the loop is not continuing.

Right, of course.  Should have been obvious.....

> > but why isn't "DOG" printed again and again, forever?
> 
> Because @slurp is coming up empty.

Actually, based on your description, I would picture it more like
@slurp=<> hasn't even come back; it's still waiting for input.

> > And why this
> > hanging only for @slurp?
> 
> Your use of while() here has even me confused.
> 
>     @slurp=<>
> 
> is in scalar context (all booleans are scalar context).
> The <> expression is in list context, so it should give "all the lines"
> behavior.

I extrapolated based on what I saw in perldoc perlintro:

   |   You can read from an open filehandle using the <> operator. In
   |   scalar context it reads a single line from the filehandle, and
   |   in list context it reads the whole file in, assigning each line
   |   to an element of the list: 
   |
   |       my $line  = <INFILE>;
   |       my @lines = <INFILE>;  
   |
   |   Reading in the whole file at one time is called slurping. It
   |   can be useful but it may be a memory hog.

From this, it seems that context is determined by the target of the
assignment.  From your comment on scalar context, this doesn't seem to
be the right conclusion.

> > Thanks for any insight into this.  I don't think this is just
> > pedagogical.
> 
> Aha. What is it then that you are actually trying to accomplish?
> I cannot guess due to the while(ARRAY) thing.

Just trying to understand the basics of what's going on when I write
a few lines of Perl so that I don't do alot of trial/error and wishful
thinking.

> But I'll bet the last part of eof()'s docs will help you.

Yes, it did.  Thanks.

Fred
-- 
Fred Ma
Dept. of Electronics, Carleton University
1125 Colonel By Drive, Ottawa, Ontario
Canada, K1S 5B6


------------------------------

Date: 12 Apr 2004 19:45:36 -0700
From: genxgeek@hotmail.com (Jacquo Johnson)
Subject: MS Access Date/Time Data type mismatch
Message-Id: <22a88b03.0404121845.27be69a1@posting.google.com>

I am receiving the following error:

MS Access Date/Time DBD::ODBC::st execute failed: [Microsoft][ODBC
Data type mismatch in criteria expression

when executing the following code.

$sqlstatement="SELECT [Import Date], [Transaction Type], [Item
Number]" .
	"FROM [Open Transactions] WHERE [Import Date] > '2004/02/01
11:16:16'";

$sth = $dbh->prepare($sqlstatement);
$sth->execute || 
       die "Could not execute SQL statement ... maybe invalid?";

The [Import Date] is defined as an MS Date/Time type and contains the
following Db entry format: 4/12/2004 9:22:37 AM

I've tried numerous literal values within the SELECT/WHERE but I am
having absolutely no luck with other formats as well as locating a
solution via the web.

Any help would be greatly appreciated!

Thanks!


------------------------------

Date: Mon, 12 Apr 2004 15:36:38 -0700
From: "Robin" <robin @ infusedlight.net>
Subject: Re: new bbs
Message-Id: <c5f93j$th8$1@reader2.nmix.net>


"Matt Garrish" <matthew.garrish@sympatico.ca> wrote in message
news:YCoec.1757$2Z6.197142@news20.bellglobal.com...
>
> "Robin" <robin @ infusedlight.net> wrote in message
> news:c5ad39$cqo$1@reader2.nmix.net...
> > http://www.infusedlight.net/robin/bbs/bbs.pl?action=view
> > my latest opus. I hope you like it. I'd like to see if some hacker can
> hack
> > this baby. I uses cgi.pm and is way more secure.
> > Admin script isn't done yet.
> >
>
> Took all of two minutes to hack you...
could you tell me how so I could fix it?
Thanks,
-Robin




------------------------------

Date: Mon, 12 Apr 2004 16:16:22 -0700
From: "Robin" <robin @ infusedlight.net>
Subject: Re: new bbs
Message-Id: <c5f969$tm0$1@reader2.nmix.net>


"Matt Garrish" <matthew.garrish@sympatico.ca> wrote in message
news:YCoec.1757$2Z6.197142@news20.bellglobal.com...
>
> "Robin" <robin @ infusedlight.net> wrote in message
> news:c5ad39$cqo$1@reader2.nmix.net...
> > http://www.infusedlight.net/robin/bbs/bbs.pl?action=view
> > my latest opus. I hope you like it. I'd like to see if some hacker can
> hack
> > this baby. I uses cgi.pm and is way more secure.
> > Admin script isn't done yet.
> >
>
> Took all of two minutes to hack you...

glad you got ur rocks off.

> Matt
>
>




------------------------------

Date: Mon, 12 Apr 2004 20:05:07 -0400
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: new bbs
Message-Id: <20040412195940.V27629@dishwasher.cs.rpi.edu>

On Mon, 12 Apr 2004, Robin wrote:

> "Matt Garrish" <matthew.garrish@sympatico.ca> wrote in message
> news:YCoec.1757$2Z6.197142@news20.bellglobal.com...
> >
> > "Robin" <robin @ infusedlight.net> wrote in message
> > news:c5ad39$cqo$1@reader2.nmix.net...
> > > http://www.infusedlight.net/robin/bbs/bbs.pl?action=view
> > > my latest opus. I hope you like it. I'd like to see if some hacker can
> > hack
> > > this baby. I uses cgi.pm and is way more secure.
> > > Admin script isn't done yet.
> > >
> >
> > Took all of two minutes to hack you...
> could you tell me how so I could fix it?
> Thanks,
> -Robin


That's a joke, right?  People in this newsgroup have been trying to help
you for MONTHS.   You don't listen to them.  You keep assuming you can
just use quick little one line fixes and suddenly your scripts will be
okay.  They won't.  You need to actually LEARN THE LANGUAGE.  You haven't
done that.  You've learned just enough to post shitty code that either
doesn't work, works poorly, or is filled with security holes.  You taught
yourslef the language, and you had a very bad instructor.

Go buy a book.  Start with the Llama and the Camel.  Move on to "Advanced
Perl Programming" and "CGI Programming with Perl."  Read, re-read,
memorize, and read again the output of `perldoc perlsec`.  Then trash
everything you've written to date and start again.  Do not simply try to
apply fixes to the already existing code.  It won't work.  You're trying
to plug a thousand leaks in a wooden dam using cellophane tape, when what
you need to do is learn how to use concrete.

Programming is not easy.  It is insulting to those of us who do this
for a living to keep assuming that it is.  Simply producing output does
not mean you know how to program.  If you want to produce something that
works - reliably and securely - you need to actually put the time into
learning how to do it correctly.

Paul Lalli


------------------------------

Date: Mon, 12 Apr 2004 20:39:16 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: new bbs
Message-Id: <slrnc7mh64.64f.tadmc@magna.augustmail.com>

Robin <robin@infusedlight.net> wrote:
> "Matt Garrish" <matthew.garrish@sympatico.ca> wrote in message
> news:YCoec.1757$2Z6.197142@news20.bellglobal.com...

>> Took all of two minutes to hack you...
> could you tell me how so I could fix it?


_You_ can't fix it.

You do not (yet) have what it takes to fix it.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: Mon, 12 Apr 2004 18:17:53 -0700
From: "Robin" <robin @ infusedlight.net>
Subject: Re: new bbs
Message-Id: <c5fgfh$vn9$1@reader2.nmix.net>

well, I figure the best way to do something is to do it. I'd like to have a
better capability for memorizing code, but it takes me a while, that's why I
don't do it for a living. I don't think this bbs is really that hackable,
perl gurl was actually very helpful! Thanks!

-Robin




------------------------------

Date: Mon, 12 Apr 2004 18:20:47 -0700
From: "Robin" <robin @ infusedlight.net>
Subject: Re: new bbs
Message-Id: <c5fgfi$vn9$2@reader2.nmix.net>

also, this bbs is a complete rewrite. Later,
-Robin




------------------------------

Date: 13 Apr 2004 02:16:43 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: new bbs
Message-Id: <slrnc7mjcb.1kd.sholden@flexal.cs.usyd.edu.au>

On Mon, 12 Apr 2004 18:17:53 -0700, Robin <robin@infusedlight.net> wrote:
> well, I figure the best way to do something is to do it. I'd like to have a
> better capability for memorizing code, but it takes me a while, that's why I
> don't do it for a living. I don't think this bbs is really that hackable,
> perl gurl was actually very helpful! Thanks!

You figure wrong. Doing it is part of learning and for some domains a
perfectly reasonable approach by itself (learning to walk for example).
However, for other domains, the doing it part comes only after being
taught by someone who can do it already. Learning to land a plane, for
example, is generally not best done by just doing it without having some
lessons first, or at least observing someone experienced a few times, or
getting a *very* good book.

There are many ways to do things in programming, many of those ways
are bad, either incorrect or inefficient, lots of those bad ways seem
good at first. Developing bad habits because you can't be bothered
learning how to tell the difference just means you will never be able
code. Well not without spending a few years unlearning the garbage you
taught yourself.

It is possible to teach yourself programming, though you don't have
that skill.

I do program for a living, but I don't memorise code.

-- 
Sam Holden


------------------------------

Date: 12 Apr 2004 18:11:00 -0700
From: eddiejones64@hotmail.com (EddieJ)
Subject: Re: Newbie Question...
Message-Id: <859c7a6b.0404121711.67f86bf6@posting.google.com>

Paul Lalli <ittyspam@yahoo.com> wrote in message news:<20040412121432.X27629@dishwasher.cs.rpi.edu>...
> 
> Why are you bothering with this?  If the files exist when you try to open
> them for writing, they are automatically clobbered.

Oh, okay didnt realise that. I presumed it would append to anything
there already.

> 
> > system ("dir/s/b *.pp* >$outputfile1") && die "Cannot write to file1 $!";
> > system ("dir/s/b *.xyz >$outputfile2");
> 
> Good checking the return value of the first system().  Bad not checking
> the return value of the second system().

Well I didnt care about it really, as long as the file was created.
I didnt realise that you could open a file that didnt exist before
it was opened.
 
> What?  What exactly are you trying to do here?  You're opening two files
> for writing, and then trying to read from one of them, and exit the loop
> when you can't read any more.  This doesn't make sense.  You can't read
> from FILE1 because you opened FILE1 for writing.

Well I knew that, but I've been playing around with the program so
much I've been trying 101 things to try to get it to work. I only
wanted to read from the first one, and then write to the second one.
 
> I don't understand what data you're expecting to be in $_.  I also don't
> understand why you're trying to open these files at all when you already
> redirected the output of the system() calls to go to those files.

I was using $_ as a test to see if there was any input/output happening.
There wasnt.

> To answer b) "Yes, use File::Find".  This is a module that will
> recursively scan any directory you give to it.  For more info,
> perldoc File::Find
> 
> #!perl.exe
> use strict;
> use warnings;
> use File::Find;
> 
> my $dir = "C:";
> my ($out1, $out2);
> open $out1, "> output1.txt" or die "Cannot open output1.txt: $!";
> open $out2, "> output2.txt" or die "Cannot open output2.txt: $!";
> 
> 
> sub wanted {
> 	return unless /\.ppt$/i;  #skip non-powerpoint files
> 	print $out1 "$File::Find::name\n"; #print full path to one file
> 	$File::Find::name =~ s/^[a-z]://i; #strip C:
> 	print $out2 "$File::Find::name\n"; #print modified path to other
> }
> 
> find (\&wanted, $dir); #recursively scan all directories under C:
> __END__
> 
> 
> Hope this helps
> Paul Lalli

Well it has in that I can see there is a much easier way of doing
what I wanted without having to resort to DOS dir/s. However when
I use the program it doesnt work for me. It creates the two output
files, but they're empty. It runs the subroutine "wanted" alright,
and even does so the 14 times (ie for the 14 ppt files on my C:) in 
a much quicker time than the dir/s/b does. I presume if I play 
around with it for a while though I should get it working.

>Reading this one more time, I think I misunderstood you the first time
>around.  If you don't actually need the "full" pathname (with C:)
>attached, remove the lines that deal with the first input file from the
>code I posted in the previous message.  Instead:

Well no, I do require the output to the first file as well, and there
will be a third file with just the actual ppt file name (without the path)
once I get this part working. Then I have to somehow create a MS 
Access file (from reading I presume I'll be using Win32::ODBC), and 
create a table, and enter the output of the three files in to three 
columns of the same table. Whether thats possible or not I dont
know...

Thanks for your time and effort with this...

EJ


------------------------------

Date: Mon, 12 Apr 2004 22:09:36 -0400
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: Newbie Question...
Message-Id: <20040412215752.P27629@dishwasher.cs.rpi.edu>

On Mon, 12 Apr 2004, EddieJ wrote:

> Paul Lalli <ittyspam@yahoo.com> wrote in message news:<20040412121432.X27629@dishwasher.cs.rpi.edu>...
> >
> > Why are you bothering with this?  If the files exist when you try to open
> > them for writing, they are automatically clobbered.
>
> Oh, okay didnt realise that. I presumed it would append to anything
> there already.

Please read `perldoc -f open` to understand the different ways of opening
files - specifically writing vs appending.

> > > system ("dir/s/b *.pp* >$outputfile1") && die "Cannot write to file1 $!";
> > > system ("dir/s/b *.xyz >$outputfile2");
> >
> > Good checking the return value of the first system().  Bad not checking
> > the return value of the second system().
>
> Well I didnt care about it really, as long as the file was created.
> I didnt realise that you could open a file that didnt exist before
> it was opened.

That's my point.  You don't know whether or not the file was created
because you didn't check the return value of system().  That's the only
way of knowing whether or not the system() command was successful.

> > What?  What exactly are you trying to do here?  You're opening two files
> > for writing, and then trying to read from one of them, and exit the loop
> > when you can't read any more.  This doesn't make sense.  You can't read
> > from FILE1 because you opened FILE1 for writing.
>
> Well I knew that, but I've been playing around with the program so
> much I've been trying 101 things to try to get it to work. I only
> wanted to read from the first one, and then write to the second one.

Again, make sure you read `perldoc -f open` to find out how to open files
for reading, for writing, and for appending.

> > I don't understand what data you're expecting to be in $_.  I also don't
> > understand why you're trying to open these files at all when you already
> > redirected the output of the system() calls to go to those files.
>
> I was using $_ as a test to see if there was any input/output happening.
> There wasnt.

I don't think you quite understand how input/output works.  Testing for $_
would not tell you anything about output.  There was no input, of course,
because you were reading from a filehandle opened for writing.  You might
want to read the "I/O Operators" section of `perldoc perlop`.

> > #!perl.exe
> > use strict;
> > use warnings;
> > use File::Find;
> >
> > my $dir = "C:";
> > my ($out1, $out2);
> > open $out1, "> output1.txt" or die "Cannot open output1.txt: $!";
> > open $out2, "> output2.txt" or die "Cannot open output2.txt: $!";
> >
> >
> > sub wanted {
> > 	return unless /\.ppt$/i;  #skip non-powerpoint files
> > 	print $out1 "$File::Find::name\n"; #print full path to one file
> > 	$File::Find::name =~ s/^[a-z]://i; #strip C:
> > 	print $out2 "$File::Find::name\n"; #print modified path to other
> > }
> >
> > find (\&wanted, $dir); #recursively scan all directories under C:
> > __END__
> >
> >
> > Hope this helps
> > Paul Lalli
>
> Well it has in that I can see there is a much easier way of doing
> what I wanted without having to resort to DOS dir/s. However when
> I use the program it doesnt work for me. It creates the two output
> files, but they're empty. It runs the subroutine "wanted" alright,
> and even does so the 14 times (ie for the 14 ppt files on my C:) in
> a much quicker time than the dir/s/b does. I presume if I play
> around with it for a while though I should get it working.

Bravo for that.  Always good to see people who are willing to try to fix
their own code to get it working for them.  If you get stuck, do feel free
to post what you have here, and we'll be happy to help.

> >Reading this one more time, I think I misunderstood you the first time
> >around.  If you don't actually need the "full" pathname (with C:)
> >attached, remove the lines that deal with the first input file from the
> >code I posted in the previous message.  Instead:
>
> Well no, I do require the output to the first file as well, and there
> will be a third file with just the actual ppt file name (without the path)
> once I get this part working.

Just for a hint there, make sure you read `perldoc File::Find`.
Especially the little grid that shows the difference between $_,
$File::Find::name, and $File::Find::dir.  That will save you a lot of
needless search-and-replace work.

> Then I have to somehow create a MS
> Access file (from reading I presume I'll be using Win32::ODBC), and
> create a table, and enter the output of the three files in to three
> columns of the same table. Whether thats possible or not I dont
> know...

I haven't played with OBDC much, but I don't see why it wouldn't be.

> Thanks for your time and effort with this...

Quite welcome.

Paul Lalli


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 6391
***************************************


home help back first fref pref prev next nref lref last post