[23134] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5355 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Aug 14 03:05:47 2003

Date: Thu, 14 Aug 2003 00:05:08 -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           Thu, 14 Aug 2003     Volume: 10 Number: 5355

Today's topics:
    Re: 'make' implemented in Perl <tzz@lifelogs.com>
    Re: 'make' implemented in Perl <tzz@lifelogs.com>
    Re: 'make' implemented in Perl <tassilo.parseval@rwth-aachen.de>
    Re: FrontPage and perl (John M. Gamble)
    Re: Help w/ BNB Survey Script <-- (Gunnar Hjalmarsson)
    Re: Help w/ BNB Survey Script <-- <uri@stemsystems.com>
    Re: Help w/ BNB Survey Script <-- <noreply@gunnar.cc>
        Newbie question !! (Wesley Tam)
    Re: Newbie question !! <mbudash@sonic.net>
    Re: Perl scripts interconnectivity... Is it possible... (Tad McClellan)
    Re: Problem with join and unicode (Tad McClellan)
    Re: Simple tr/// script (Tad McClellan)
    Re: Simple tr/// script <REMOVEsdnCAPS@comcast.net>
    Re: Suggestions for further perl reading <nospam@please.com>
    Re: using Getopt::Long with option value having spaces <sunil_franklin@hotmail.com>
        Why doesn't this work? (jend)
    Re: Why doesn't this work? <bwalton@rochester.rr.com>
    Re: Why doesn't this work? <matthew.garrish@sympatico.ca>
    Re:  <bwalton@rochester.rr.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 13 Aug 2003 21:13:31 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: 'make' implemented in Perl
Message-Id: <4nadadyrb8.fsf@lockgroove.bwh.harvard.edu>

On Thu, 14 Aug 2003, merlyn@stonehenge.com wrote:

>>>>>> "Ted" == Ted Zlatanov <tzz@lifelogs.com> writes:
> Ted> This comes up periodically in Perl discussion lists, and
> Ted> usually the answer is "just wait for XYZ, it will do this and
> Ted> more."  I'm not sure what the current XYZ is/are, especially
> Ted> regarding why XYZ hasn't yet replaced 'make' in CPAN installs
> Ted> and standard Perl usage.  I'm very interested in any
> Ted> information, as I have needed tighter integration between Perl
> Ted> and 'make' many times.
> 
> There already *is* one.
> 
> <http://search.cpan.org/author/NI-S/Make-1.00/>
> 
> 11 April 1999 for the release date.

Right, and there's also make.pl and Cons as I mentioned.  Thanks for
the info!

Now, my question is why CPAN is still relying on the old-fashioned
external make.  Parrot seems to be aimed towards using the new Make
you mention above, which is very good news indeed.  Maybe it's just
easier not to change CPAN? :)

Ted


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

Date: Wed, 13 Aug 2003 21:27:36 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: 'make' implemented in Perl
Message-Id: <4n65l1yqnr.fsf@lockgroove.bwh.harvard.edu>

On Wed, 13 Aug 2003, emschwar@pobox.com wrote:

> Ted Zlatanov <tzz@lifelogs.com> writes:
>> I don't think it's that hard, as evidenced by the billion make
>> reimplementations.
> 
> Many of which are broken in some way or other.

Do you actually have experience using them, or are you basing this
opinion on hearsay?  If you know why make.pl, the CPAN Make module,
or Cons are broken, please let me know why their home pages seem so
optimistic and people are using them in production.

>> Right, but the question remains, why use it?
> 
> Because it's nigh-universal (it's even easy to get on Windows, with
> cygwin and other emulation environments), everybody knows it, and
> the old adage, "Standard is better than better".

Those are reasons for using the horse over the car, as I already
mentioned.  Let's rephrase the question: why use an external utility
that can be perfectly emulated (as far as CPAN needs it) by Perl?  I
mean, yes, maybe we don't have parallel builds and such, but we don't
really need them for installing a CPAN module either.  We don't need
to emulate he Makefile syntax either.  Hell, Makefile.PL is
sufficient and we can drive installations, etc. from it.

>> make may be portable, but that doesn't mean it's available,
> 
> Um, where isn't it available?  If you can download a perl module,
> you can download a copy of make.

Some users can't install software.  Some users don't want to.  Some
users are not allowed to.  Some users don't like the bother of having
to download several extra packages to install a pure Perl module.
Obviously this is enough of an issue that ActiveState provides PPMs
for the convenience of their users.  If you enjoy downloading extra
software, great.  I don't see the need.

>> I'm saying that it matters if make is broken or unavailable, for
>> instance on Windows.
> 
> Windows has perfectly functional make implementations, at least one
> of which is even free.

I meant that make may be broken or unavailable on any platform, most
commonly on Windows (because users haven't installed it).  Sorry for
being unclear.  I am aware of the make ports to Windows.

>> Perl can do the job by itself.
> 
> Sure, but why reinvent the wheel when there's a perfectly good one
> available?

Because a bicycle is faster than a tricycle.

>> - installing Perl software (the step Makefile.PL -> Makefile could
>>   be skipped)
> 
> Doesn't require integration.  It's a nice WIBNI, but irrelevant.

OK, obviously you don't think a pure Perl CPAN installation would be
useful.  Fine.  I disagree and I suspect I'm not the only one.

>> - general dependency-driven actions that use Perl syntax inside the
>>   Makefile
> 
> What's the advantage over using make syntax?

Make can't express most of Perl's syntax.  GNU Make gets closer, but
it's still not sufficient for complex tasks.  I could give examples
but I think it's really unnecessary.

Ted


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

Date: 14 Aug 2003 06:13:04 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: 'make' implemented in Perl
Message-Id: <bhf99g$666$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Ted Zlatanov:

> On Thu, 14 Aug 2003, merlyn@stonehenge.com wrote:
> 
>>>>>>> "Ted" == Ted Zlatanov <tzz@lifelogs.com> writes:
>> Ted> This comes up periodically in Perl discussion lists, and
>> Ted> usually the answer is "just wait for XYZ, it will do this and
>> Ted> more."  I'm not sure what the current XYZ is/are, especially
>> Ted> regarding why XYZ hasn't yet replaced 'make' in CPAN installs
>> Ted> and standard Perl usage.  I'm very interested in any
>> Ted> information, as I have needed tighter integration between Perl
>> Ted> and 'make' many times.
>> 
>> There already *is* one.
>> 
>> <http://search.cpan.org/author/NI-S/Make-1.00/>
>> 
>> 11 April 1999 for the release date.
> 
> Right, and there's also make.pl and Cons as I mentioned.  Thanks for
> the info!
> 
> Now, my question is why CPAN is still relying on the old-fashioned
> external make.  

Because it generally works. The whole of CPAN currently consist of
modules which are installed using ExtUtils::MakeMaker. This one produces
a Makefile that does the right thing for all imaginable platforms.
Changing that would surely cause problems for a considerable number of
the many thousand CPAN distributions.

However, there is Module::Build which will sooner or later replace
ExtUtils::MakeMaker. It no longer relies on make but instead produces a
framework that will obey to

    perl Build.PL
    ./Build
    ./Build test
    ./Build install

The first line will produce a Perl script 'Build' that contains all the
functionality that was previously specified in Makefile.

Of course, such a change in the build process only makes sense when
other tools can deal with it. For instance, h2xs wont yet create a
module skeleton for Module::Build. I am not sure about CPAN.pm either.
Current release might already be able to deal with those modules, but
older ones certainly aren't.

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


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

Date: Thu, 14 Aug 2003 06:36:14 +0000 (UTC)
From: jgamble@ripco.com (John M. Gamble)
Subject: Re: FrontPage and perl
Message-Id: <bhfaku$da7$1@e250.ripco.com>

In article <UhA_a.11627$M6.992647@newsread1.prod.itd.earthlink.net>,
Christopher Shatto  <l0g0m0tion@earthlink.net> wrote:
>John M. Gamble wrote:
>
>> Are there any known "gotchas" when developing with FrontPage
>> and perl?  The ISP provides perl for the server side, and my
>> friend's husband is very insistent about using FrontPage for
>> designing the website.
>> 
>> It's not my first choice, but i'm willing to go along.  So...
>> 
>> Anything i should look out for (excluding the usual MS-bashing)?
>> This will be my first foray into FrontPage.
>> 
>I too am forced to use FrontPage, but I'm desperately trying to replace 
>the Extensions "functionality" with Perl.  The only thing I've ever had 
>trouble with was using HTML::Template templates.  FrontPage will 
>gleefully eliminate your TMPL_ tags without warning if you try to edit 
>the files in design view.  Caveat coder.
>
>Actually, with all the problems FP has caused me over the two years I've 
>been forced to use it, I've been extremely happy that I had Perl around 
>to fix things.
>

Thanks.  Frankly, i was expecting that nothing would interfere with
each other, so this bit of info will be quite useful.  Do you have
any examples of using perl to overcome an FP problem?

Thanks again,

-- 
	-john

February 28 1997: Last day libraries could order catalogue cards
from the Library of Congress.


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

Date: 13 Aug 2003 18:11:54 -0700
From: noreply@gunnar.cc (Gunnar Hjalmarsson)
Subject: Re: Help w/ BNB Survey Script <--
Message-Id: <3fcbff18.0308131711.89ae07e@posting.google.com>

Uri Guttman wrote:
> >>>>> "LF" == Lori Fleetwood writes:
> 
>   LF> don't you mean "ask the moron authors for help"?
> 
> moron authors is always implied when someone asks for help
> with free scripts.

Does a question from a user make the script's author a moron?? As a
Perl hobbyist, I'm providing a couple of free scripts, and I find
those comments utterly unintelligent.

Is programming skill incompatible with a civil manner?

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


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

Date: Thu, 14 Aug 2003 03:04:18 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Help w/ BNB Survey Script <--
Message-Id: <x7ekzp2b4d.fsf@mail.sysarch.com>

>>>>> "GH" == Gunnar Hjalmarsson <noreply@gunnar.cc> writes:

  GH> Uri Guttman wrote:
  >> >>>>> "LF" == Lori Fleetwood writes:
  >> 
  LF> don't you mean "ask the moron authors for help"?
  >> 
  >> moron authors is always implied when someone asks for help
  >> with free scripts.

  GH> Does a question from a user make the script's author a moron?? As a
  GH> Perl hobbyist, I'm providing a couple of free scripts, and I find
  GH> those comments utterly unintelligent.

well, you haven't scanned most free scripts out there. start with matt
wright's and all of the variants from them. and go to the many script
sites and try to find good code. your couple of scripts (however good
they may be) are microscopic drop in the bucket compared to the sea of
crap out there in the free script ocean. and not only are they crap,
they are never maintained, never written using standard modules, never
secure, mostly cut and pasted, use poor coding style, etc. the only
conclusion is that the authors are moron or teenagers or both. and
notice that none of those scrit authors are part of the perl community
where they might learn something, get constructive criticism, contribute
to cpan, etc. they are a sargasso sea with no connecting currents to the
rest of the waters.

  GH> Is programming skill incompatible with a civil manner?

nope. but asking for help here for a free script written by someone who
is not around here is uncivil in my book.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Thu, 14 Aug 2003 09:01:46 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Help w/ BNB Survey Script <--
Message-Id: <bhfc44$3nbn$1@ID-184292.news.uni-berlin.de>

Uri Guttman wrote:
>>>>>> "GH" == Gunnar Hjalmarsson <noreply@gunnar.cc> writes:
> GH> Does a question from a user make the script's author a moron??
> As a GH> Perl hobbyist, I'm providing a couple of free scripts, and
> I find GH> those comments utterly unintelligent.
> 
> well, you haven't scanned most free scripts out there. start with
> matt wright's and all of the variants from them. and go to the many
> script sites and try to find good code. your couple of scripts
> (however good they may be) are microscopic drop in the bucket
> compared to the sea of crap out there in the free script ocean. and
> not only are they crap, they are never maintained, never written
> using standard modules, never secure, mostly cut and pasted, use
> poor coding style, etc. the only conclusion is that the authors are
> moron or teenagers or both. and notice that none of those scrit
> authors are part of the perl community where they might learn
> something, get constructive criticism, contribute to cpan, etc.
> they are a sargasso sea with no connecting currents to the rest of
> the waters.

1) Lori and you said in effect that all authors of free scripts are
morons. That is obviously not true.

2) I'm sure it's true that many of the free scripts are badly written
and provided without support and/or maintenance. Sad, but natural.
That's how it is. And, still, somebody who shares his or her work with
the world is not automatically a moron, even if s/he does not provide
free support etc. in addition to the free code.

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



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

Date: 13 Aug 2003 22:01:43 -0700
From: lokman@gate.net (Wesley Tam)
Subject: Newbie question !!
Message-Id: <e4e1f968.0308132101.46597da@posting.google.com>

Hi !

What is the different between ??

#!/usr/bin/perl -w
and 
#!/usr/bin/perl


I'm newbie, I just start to learn perl

Thanks


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

Date: Thu, 14 Aug 2003 05:13:33 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: Newbie question !!
Message-Id: <mbudash-930472.22133213082003@typhoon.sonic.net>

In article <e4e1f968.0308132101.46597da@posting.google.com>,
 lokman@gate.net (Wesley Tam) wrote:

> Hi !
> 
> What is the different between ??
> 
> #!/usr/bin/perl -w
> and 
> #!/usr/bin/perl
> 
> 
> I'm newbie, I just start to learn perl
> 
> Thanks

type:

perldoc perlrun

at your command line.

it's all in there...

-- 
Michael Budash


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

Date: Wed, 13 Aug 2003 20:16:13 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Perl scripts interconnectivity... Is it possible...
Message-Id: <slrnbjlomt.62r.tadmc@magna.augustmail.com>

Hudson <scripts_you-know-the-drill_@hudsonscripting.com> wrote:

> I think you just want to make a module. This is not really so hard.
> See perlmod and perlsub.


And don't forget the Perl FAQ:

   perldoc -q module


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


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

Date: Wed, 13 Aug 2003 21:06:59 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Problem with join and unicode
Message-Id: <slrnbjlrm3.62r.tadmc@magna.augustmail.com>


derek / nul <abuseonly@sgrail.org> wrote:

> Please keep in mind I am at best a part time programmer,

> My ugly code is at the bottom,

> I have my fireproof suit on :-))) 


In that case, I'll add a few comments, none of which have to do
with the problem you are trying to solve, and each of which will
help you avoid many other errors at some point in your programming.


> my $currenttableentry;


Thatsureisahardtoreadchoiceofvariablename.


   my $current_table_entry;


[ snip 30 global variables ]


Having that many global variables is Not Good. It could lead
to "action at a distance" bugs, which can be very hard to find.

Programmers guard against that potential future pain by limiting
the "scope" of variables to the smallest possible part of the 
program.

For more on scoping see:

   "Coping with Scoping":

      http://perl.plover.com/FAQs/Namespaces.html


They also pass arguments instead of using global variables to
communicate with subroutines.


> find(\&readfile, "c:/program files/microsoft games/train simulator/trains/"); #
> &readfile is a subroutine


It is bad practice to repeat in a comment what is already said in code.

You use comments to add info that is _not_ in the code, like _why_
you are doing something rather than _what_ you are doing, the
code says what you are doing anyway.


> #####################################################################
> #
> sub readfile {		# need to get eng and wag files
> #
> #####################################################################
> 
> 	$datam = $File::Find::name;


Ummm, you never use this variable again. What is it for?


> 	if ($_=~/.bak$/){		# lets not modify all the backup files


That will also match when $_ = 'Studebak'.

Spaces are not a scarce resource. Feel free to use as many of them
as you need to help make your code easier to read.


> 		# do nothing
> 	}	elsif ($_=~/.phy$/) {
> 		# do nothing
> 	}	elsif ($_=~/.eng$/) {
> 		&readfile1

   perldoc -q "&"

      What's the difference between calling a function as &foo and foo()?


> 	}	elsif ($_=~/.wag$/) {
> 		&readfile1
> 	}	else {
> 		# do nothing
> 	}
> }


This subroutine is equivalent to yours, I think:

   sub readfile {                     # untested
      readfile1() if /\.(eng|wag)$/;
   }


The problem with programming is that you are likely to have
to "eat your own dogfood" and debug this program weeks or
months after you've written it.

It is a big time-saver to invest a bit of time in observing some
CS fundamentals when creating the program.

Limit scope. Limit global variables. Write your code so that you
will be able to easily and quickly understand it (much?) later.

Use whitespace and indenting to help show the structure of your code.


> 	{ 										# block to localise the local command
> 	local $/;


Good! You _are_ limiting the scope for that variable, now go do
it for all of the other variables.  :-)


> 		open ENGWAG, "$File::Find::name"


See also this Perl FAQ, then lose the double quotes:

   What's wrong with always quoting "$vars"?



> 	{ 										# block to localise the local command


Huh?

This comments actually _hurts_ rather than helps with understanding,
it is misleading.

You are not localising the local function.

You are localising the value of the $/ variable.



> 		$datatable = <ENGTABLE>;
> 		close ENGTABLE;
> 	}
> 	@linesengtable = split /\n/, $datatable;	# \n for the text file


Errr, if you had left $/ with its default value, then you could
have just done:

    @linesengtable =  <ENGTABLE>;

to get the same result...


> 	# we now have the engtable.dat in memory


But we do not _need_ it all in memory.


> 	for (@linesengtable) {


   while ( <ENGTABLE> ) {

processes line-by-line but has only a single line in memory
at any one time.


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


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

Date: Wed, 13 Aug 2003 21:15:14 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Simple tr/// script
Message-Id: <slrnbjls5i.62r.tadmc@magna.augustmail.com>

Mike Flannigan <mikeflan@earthlink.net> wrote:

> I can't believe I can't figure this out,


Others have already helped with that part.


> 1)  The script runs as written, but gives an error after running
> "Use of uninitialized value in transliteration (tr///) . . . at line 12,


That is not an error message.

That is a warning message.

There is a significant difference between the two.


> Can anybody explain these errors for me. 


All of the messages that perl might issue are documented in
the perldiag.pod std doc, you should look up messages
there as a 1st debugging step.

Or, ask perl to do the looking-up for you by adding

   use diagnostics;

near the top of your program, then execute it again.


>     $num =~ tr/a-zA-Z\. /n-za-mN-ZA-M\. /;
                       ^               ^
                       ^               ^ useless backslashes

Why do you want to replace dot with dot and space with space?

Just leave them alone if you do not want them changed.


   $num =~ tr/a-zA-Z/n-za-mN-ZA-M/;


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


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

Date: Wed, 13 Aug 2003 21:30:27 -0500
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: Simple tr/// script
Message-Id: <Xns93D6E501C15C0sdn.comcast@206.127.4.25>

Christopher Shatto <l0g0m0tion@earthlink.net> wrote in news:9tA_a.11650
$M6.990763@newsread1.prod.itd.earthlink.net:

> You are calling while(<DATA>) which is reading a line into $_ . 
> Immediately thereafter, you call $ki = <DATA> which is reading in 
> ANOTHER line.  In effect, you are reading a line of DATA into $_, 
> ignoring it, then reading the NEXT line into $ki.  Try using
> 
> while ($ki = <DATA>)
> {
>    push @kites, $ki;
> }
> 
> instead.

Or simply:

    @kites = <DATA>;

-- 
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print


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

Date: Thu, 14 Aug 2003 06:51:49 GMT
From: Gunter Schelfhout <nospam@please.com>
Subject: Re: Suggestions for further perl reading
Message-Id: <9kG_a.66172$F92.7438@afrodite.telenet-ops.be>

Chad wrote:

> Ok I have finished the Llama book and am now creating simple scripts.
> 
> My question is what should I read to further myself at this.  is the
> camel book the way to go or is there something better?
> 
> One of my goals(among many) is to be able to streamline my code
> better(what takes me a whole screen would probably take you about 3
> lines).

Well, I only go to the Amazon site for the reviews. 
If I see a book that I'm interested in, I go trough these reviews. 
It can give you a good clue wether the book is right for you.

-- 
Blood, sweat & tears


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

Date: Thu, 14 Aug 2003 09:35:42 +0530
From: "Sunil" <sunil_franklin@hotmail.com>
Subject: Re: using Getopt::Long with option value having spaces
Message-Id: <h%D_a.24$Aj4.142@news.oracle.com>


"Tony Curtis" <tony_curtis32@yahoo.com> wrote in message
news:87r83pfzu4.fsf@limey.hpcc.uh.edu...
> >> On Wed, 13 Aug 2003 14:21:36 +0530,
> >> "Sunil" <sunil_franklin@hotmail.com> said:
>
> > All, I am trying to use GetOptions to get the values
> > corresponding to options in a string like in
>
> > #################################################### my
> > $eval_string = '@ARGV = qw (' . "$scriptOptions" . ' )'
> > ; eval $eval_string; GetOptions("fwk=s" => \$framework,
> > "mode=s" => \$errMode, "args=s" => \@arguments,
> > "comments=s" => \$comments );
> > ####################################################
>
> >  The problem I am having is that if $scriptOptions
> > contains something like -comments="this is a comment", I
> > get only "this as the comment as GetOptions does not
> > take kindly to option values having spaces. Is there any
> > workaround for this?
>
> The " around the value of $scriptOptions are part of the
> perl syntax, not part of the string.
>
> I'm not sure why you would want to fiddle with @ARGV
> though?  IMHO the point of something like Getopt::Long is
> to take unstructured text from the command-line and turn
> it into a usable data structure.  If you've already got
> the data in the program why try to push it back out and
> pull(*) it in again?
>

Sorry for not being clear the first time,
Let me try to make amends.

I have a file which has some metadata, like
----
t1.pl  -frwk=perl  -mode=1 -args=a,b,c  -comments="This is comment 1"
t2.sql  -frwk=sql -mode=2 -args=x -comments="This is comment 2"
----

I need to read this file line by line and parse it to get the values of
frwk, -mode and comments, so that I can create another string depending on
the different values for this string and pass it on to the corresponding
perl api I have which will execute it for me.

I am stuck because I am not able to pass spaces as part of comments. Is
there a workaround?

Thanks,
Sunil.





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

Date: 13 Aug 2003 18:33:00 -0700
From: dejen321@yahoo.com (jend)
Subject: Why doesn't this work?
Message-Id: <cc028093.0308131733.19c2578@posting.google.com>

See scripts below:  I get zero sized files. and an error message in the logs
like this: readline() on unopened filehandle at upload.cgi 

It seems that the follwing line is failing in my code 

+++ my $upload_filehandle = $query->upload("myfilename");   

but this is almost exactly the same as the perldoc CGI docs sample.

anyone?


This is the upload script 
#!/usr/local/bin/perl

use strict;
use warnings;

use CGI;
use CGI::Carp qw(fatalsToBrowser);

$CGI::DISABLE_UPLOADS = 0;

my $upload_dir = '/tmp/upload.txt;

my $query = new CGI;
my $filename = $query->param('myfilename');

print $filename;

$filename =~ s/.*\/\\(.*)/$1/;

print $filename;

my $upload_filehandle = $query->upload("myfilename");

open(UPLOADFILE, ">$upload_dir/$filename") or die $!;

binmode UPLOADFILE;

while ( <$upload_filehandle> )
{
    print UPLOADFILE;
}
close UPLOADFILE;
print $query->header ( );


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

Date: Thu, 14 Aug 2003 01:44:33 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Why doesn't this work?
Message-Id: <3F3AE944.20400@rochester.rr.com>

jend wrote:

> See scripts below:  I get zero sized files. and an error message in the logs
> like this: readline() on unopened filehandle at upload.cgi 
> 
> It seems that the follwing line is failing in my code 
> 
> +++ my $upload_filehandle = $query->upload("myfilename");   
> 
> but this is almost exactly the same as the perldoc CGI docs sample.
 ...


Quick dumb guess:


> my $upload_filehandle = $query->upload("myfilename");

$filename--------------------------------^^^^^^^^^^^^

Your code is trying to upload the literal filename "myfilename".  That's 
probably not the name of the file you actually want to upload.
 ...

-- 
Bob Walton



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

Date: Thu, 14 Aug 2003 01:11:36 -0400
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: Why doesn't this work?
Message-Id: <RSE_a.9109$VG.381552@news20.bellglobal.com>


"jend" <dejen321@yahoo.com> wrote in message
news:cc028093.0308131733.19c2578@posting.google.com...
> See scripts below:  I get zero sized files. and an error message in the
logs
> like this: readline() on unopened filehandle at upload.cgi
>
> It seems that the follwing line is failing in my code
>
> +++ my $upload_filehandle = $query->upload("myfilename");
>
> but this is almost exactly the same as the perldoc CGI docs sample.
>

That can't be true, because there's no way you could compile the code you've
pasted below.

>
> This is the upload script
> #!/usr/local/bin/perl
>
> use strict;
> use warnings;
>
> use CGI;
> use CGI::Carp qw(fatalsToBrowser);
>
> $CGI::DISABLE_UPLOADS = 0;
>
> my $upload_dir = '/tmp/upload.txt;
>

You're missing a closing quote there, and why does your directory include a
filename?

> my $query = new CGI;
> my $filename = $query->param('myfilename');
>
> print $filename;

Interesting...

>
> $filename =~ s/.*\/\\(.*)/$1/;
>

I don't think that's what you want, as I've never seen a filename with a
forward-slash followed by a slash. You might try this instead:

$filename =~ s#\\#/#g;           # make them all go one way
$filename =~ s#.*/(.*)#$1#;  # and then find the last

It's also probably not a good idea to blindly assume that whatever follows
the final slash is a valid file name.

> print $filename;
>

I take it this is some post-debugging rendering of your script?

> my $upload_filehandle = $query->upload("myfilename");
>

I ran into the same problem here, but since it was the only file upload
field I've ever written, I just went back to the old method and chalked it
up to a windows bug. I looked a little deeper this time, and it seems that
$param does not contain a reference, so the second 'return' below was
sending back a null value (always check your return values before continuing
on with a script!). Why, I'm not sure, but you might be having the same
problem ('The file upload feature doesn't work with every combination of
browser and server.', see
http://stein.cshl.org/WWW/software/CGI/#upload_caveats).

sub upload {
    my($self,$param_name) = self_or_default(@_);
    my $param = $self->param($param_name);
    return unless $param;
    return unless ref($param) && fileno($param);
    return $param;
}



> open(UPLOADFILE, ">$upload_dir/$filename") or die $!;

There are two possible problems here: 1) you specify a text file above, so
you shouldn't add another filename on (probably not a problem, but since I
don't know what your working code looks like...); and 2) see the regex note
above for why, if I were to upload the file c:\temp\whatever.dat, you would
now have a path called '/tmp/c:\temp\whatever.dat'.

Probably not the answers you were looking for in the end, but the best I can
come up with...

Matt




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

Date: Sat, 19 Jul 2003 01:59:56 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: 
Message-Id: <3F18A600.3040306@rochester.rr.com>

Ron wrote:

> Tried this code get a server 500 error.
> 
> Anyone know what's wrong with it?
> 
> if $DayName eq "Select a Day" or $RouteName eq "Select A Route") {

(---^


>     dienice("Please use the back button on your browser to fill out the Day
> & Route fields.");
> }
 ...
> Ron

 ...
-- 
Bob Walton



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

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.  

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 5355
***************************************


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