[24160] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6354 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Apr 1 21:10:28 2004

Date: Thu, 1 Apr 2004 18:10:09 -0800 (PST)
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, 1 Apr 2004     Volume: 10 Number: 6354

Today's topics:
        Need help with a Perl Script Error (Darren Clark)
    Re: Need help with a Perl Script Error <noreply@gunnar.cc>
    Re: Need help with a Perl Script Error <spamtrap@dot-app.org>
    Re: Need help with a Perl Script Error (Gary E. Ansok)
    Re: uninitialized value in concatenation ... <ittyspam@yahoo.com>
    Re: uninitialized value in concatenation ... <uri.guttman@fmr.com>
    Re: uninitialized value in concatenation ... (Chris Conwell)
    Re: uninitialized value in concatenation ... (Chris Conwell)
    Re: uninitialized value in concatenation ... <tadmc@augustmail.com>
    Re: validate links?? <dnp@ams.org>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 1 Apr 2004 15:22:19 -0800
From: darren.clark@clarkcompservice.com (Darren Clark)
Subject: Need help with a Perl Script Error
Message-Id: <21cd07f.0404011522.32d62c2f@posting.google.com>

I'm fairly new to writing Perl CGI Scripts.  The script I've written
uploads a file to a web server.  The script runs fine when I am using
IE from a windows machine, but when I use a MAC to call the script, I
get the following error message:

Undefined subroutine &main::Error called at
/home/comp/corp/ici1/www/scripts/upload.cgi line 28.
Program returned result 21. A value larger than 0 is an error.

The following is my script:

#!/bin/perl
# use strict;
use CGI ':standard';

#Define variables
$query = new CGI;


my $name= $query->param('u_file');
my $workorder= $query->param('work_order');
my $info= uploadInfo ($name);
my $type = $info -> {'Content-Type'};

$mypath = '../upload/'.$workorder;

#Create upload directory
# mkdir ($mypath, 0777);

#Strip directory structure
$name=~m/^.*(\\|\/)(.*)/; # strip the remote path and keep the
filename
my $newname = $2;

# Concatenate the path & file name for UPLOAD
$myupload = '>'.$mypath.'/'.$newname;


if ($name) {
	open (UPLOAD, $myupload) || Error ();
	
	my ($data, $chunk);
		while ($chunk = read ($name, $data, 1024)) {
		print UPLOAD $data;
		}
	close (UPLOAD);
	
	
	}

I assume it has something to do with how a MAC passess the file
information that is being uploaded but am not sure if I am right or if
I am how to correct it.  I've scoured the web and have come up with
nothing.

I'd appreciate it if someone could give me some direction.

Please reply to darren.clark@{no spam}clarkcompservice.com

Thank you,

Darren


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

Date: Fri, 02 Apr 2004 02:10:15 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Need help with a Perl Script Error
Message-Id: <c4ib8o$2i7hc8$1@ID-184292.news.uni-berlin.de>

Darren Clark wrote:
> The following is my script:
> 
> #!/bin/perl
> # use strict;
--^
Please study the posting guidelines for this group: 
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html

and follow the advices therein. If that doesn't solve your problem, 
please post again in compliance with the guidelines.

> Please reply to darren.clark@{no spam}clarkcompservice.com

No way. This is not a help desk.

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



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

Date: Thu, 01 Apr 2004 20:15:42 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Need help with a Perl Script Error
Message-Id: <NpudnchzZs87I_HdRVn-gg@adelphia.com>

Darren Clark wrote:

> The following is my script:
> 
> #!/bin/perl
> # use strict;

The error is above, on line 2. You've mistakenly commented out an important
piece of code.

sherm--

-- 
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org


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

Date: Fri, 2 Apr 2004 01:21:11 +0000 (UTC)
From: ansok@alumni.caltech.edu (Gary E. Ansok)
Subject: Re: Need help with a Perl Script Error
Message-Id: <c4if67$hi8$1@naig.caltech.edu>

In article <21cd07f.0404011522.32d62c2f@posting.google.com>,
Darren Clark <darren.clark@clarkcompservice.com> wrote:
>I'm fairly new to writing Perl CGI Scripts.  The script I've written
>uploads a file to a web server.  The script runs fine when I am using
>IE from a windows machine, but when I use a MAC to call the script, I
>get the following error message:
>
>Undefined subroutine &main::Error called at
>/home/comp/corp/ici1/www/scripts/upload.cgi line 28.
>Program returned result 21. A value larger than 0 is an error.
>
>The following is my script:
>
>#!/bin/perl
># use strict;
>use CGI ':standard';
>
>#Define variables
>$query = new CGI;
>
>
>my $name= $query->param('u_file');
>my $workorder= $query->param('work_order');
>my $info= uploadInfo ($name);
>my $type = $info -> {'Content-Type'};
>
>$mypath = '../upload/'.$workorder;
>
>#Create upload directory
># mkdir ($mypath, 0777);
>
>#Strip directory structure
>$name=~m/^.*(\\|\/)(.*)/; # strip the remote path and keep the
>filename
>my $newname = $2;
>
># Concatenate the path & file name for UPLOAD
>$myupload = '>'.$mypath.'/'.$newname;
>
>
>if ($name) {
>	open (UPLOAD, $myupload) || Error ();
>	
>	my ($data, $chunk);
>		while ($chunk = read ($name, $data, 1024)) {
>		print UPLOAD $data;
>		}
>	close (UPLOAD);
>	
>	
>	}
>
>I assume it has something to do with how a MAC passess the file
>information that is being uploaded but am not sure if I am right or if
>I am how to correct it.  I've scoured the web and have come up with
>nothing.

Since the only call to Error() is when the open fails, I suppose
that is what is resulting in the error message.

What do the various variables contain when the error occurs?  
Particularly $myupload and the parameters that are used to construct it.

What is in the Perl variable $! when the error occurs?  This might
give you a clue as to _why_ the open fails.

Since $mypath appears to start with '../', what is the current directory?
Do you have the proper permissions to create $myupload?

Why do you have 'use strict' commented out?

Why do you call a function called Error() and not define it?

What happens if $name does not contain a '/' or a '\\'?

It is quite possible that something in the way the upload is passed in
is causing $myupload to not be a valid filename on your system.  If
you were to print out the contents of $myupload, you would probably
be able to tell whether that is the case and what you might be able
to do about it.

Gary Ansok
-- 
Valuable Tip: Never assume that you and fighter pilots
have the same definition of "fun."
        -- Dave Barry


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

Date: Thu, 1 Apr 2004 14:26:35 -0500
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: uninitialized value in concatenation ...
Message-Id: <20040401142350.G19862@dishwasher.cs.rpi.edu>

On Thu, 1 Apr 2004, Tad McClellan wrote:

> Chris Conwell <chris@mobiles.co.uk> wrote:
> > I've been coding in Perl for some years now but here's a snippet of
> > code that's got me really stumped:
> >
> > --------------------------------------------------------------------------------
> >  Code
> > --------------------------------------------------------------------------------
> >
> > 3913 sub print_price_nicely {
> > 3914  my ($model,$link,$price) = (@_);
> > 3915  return unless ($price);
> > 3916  if ($price) {
> > 3917   if ($price eq "") {
> >
> > --------------------------------------------------------------------------------
> >
> > This is giving the error:
>
> It is not an "error". It is a "warning". There is a difference.
>
> > "Use of uninitialized value in concatenation (.) or string at
> > cgi/phones.pl line 3917."
> >
> > How can the script reach line 3917 and then report "uninitialized
> > value"?!?!?
>
> Some things are warn()able and some things aren't.
>
> Testing the "truth" of a variable whose value is undef
> is not warnable (3915 & 3916).
>
> Testing the "string equality" of a variable whose value is undef
> against a constant string _is_ warnable (3917).

None of which gives any kind of answer.  The point of the OP's question is
that clearly Perl believes on line 3915 that $price has a true value,
and on 3916 that $price has a true value.  But the compilation warning
he's getting indicates that $price is unintialized on line 3917.

No obviously, this isn't correct, and the warning isn't reporting the
correct line.   But the statements you posted have nothing to do with the
problem at hand.

Paul Lalli


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

Date: 01 Apr 2004 14:40:13 -0500
From: Uri Guttman <uri.guttman@fmr.com>
Subject: Re: uninitialized value in concatenation ...
Message-Id: <siscbrmbv65e.fsf@tripoli.fmr.com>

>>>>> "CC" == Chris Conwell <chris@mobiles.co.uk> writes:

  CC> 3913 sub print_price_nicely { 

i hope you don't actually use 1 char indents. 2 is bad enough with 3 or
4 being a good minimum. 

  CC> 3914  my ($model,$link,$price) = (@_); 

no need for () around @_. the left side provides the list context and
the () are not doing anything.

  CC> 3915  return unless ($price); 

no need for () there, any expression is fine. only if statements (as
below) need () for proper syntax.

  CC> 3916  if ($price) { 

why are you again testing $price when you just returned if you have no
price?

  CC> 3917   if ($price eq "") {  

  CC> This is giving the error: 
 
  CC> "Use of uninitialized value in concatenation (.) or string at
  CC> cgi/phones.pl line 3917."

  CC> How can the script reach line 3917 and then report "uninitialized
  CC> value"?!?!?

first off, you should never have a source file with so much code in
it. break it up into smaller files as it will make life easier for you
in many ways.

secondly, i bet your line numbering is at fault. how did you determine
those line numbers? perl may have a different view of what line numbers
are than you (or the program you used) do. did your line numbering thing
count long wrapped lines as 1 or multiple lines? perl counts them as one
line.

uri


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

Date: 1 Apr 2004 12:17:39 -0800
From: chris@mobiles.co.uk (Chris Conwell)
Subject: Re: uninitialized value in concatenation ...
Message-Id: <5f675152.0404011217.35e60353@posting.google.com>

Tore Aursand <tore@aursand.no> wrote in message news:<pan.2004.04.01.15.16.08.101246@aursand.no>...

> Give us the lines in the scope created on line 3917.  One other thing is
> that you don't need to check 'if ( $price )' and/or 'if ( $price eq "" )'
> as long as you do 'return unless ( $price )'.

The 'return unless ( $price )' was only added as a debugging line
after getting completely confused as to how the error message can
happen (and then getting more confused when the error continued :).

> (But please remember that '$price' with a value of 0 also will be skipped,
>  even though I recall extremely cheap is also a price to pay...)

Yes, if $price is zero then an "elsif" further on deals with it - see
next post.

Thanks for taking an interest in this problem.

Chris.


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

Date: 1 Apr 2004 12:28:17 -0800
From: chris@mobiles.co.uk (Chris Conwell)
Subject: Re: uninitialized value in concatenation ...
Message-Id: <5f675152.0404011228.3cce607e@posting.google.com>

anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message news:<c4hbqn$ce3$1@mamenchi.zrz.TU-Berlin.DE>...
> > How can the script reach line 3917 and then report "uninitialized
> > value"?!?!?
> 
> Are there else-clauses?

Yes, the script continues (where "..." signifies irrelevant code to
output data) :

--------------------------------------------------------------------------------
 
3913 sub print_price_nicely { 
3914  my ($model,$link,$price) = (@_); 
3915  return unless ($price); 
3916  if ($price) { 
3917   if ($price eq "") {  
 ...
3920   }
3921   elsif ($price =~ /TBC/i) {
 ...
3925   }
3926   elsif ($this_index =~ /INDEXU/) {
 ...
3929   }
3930   else {
 ...
3935   }
3936  }

--------------------------------------------------------------------------------
 
Are you thinking that the error is actually on one of the "elsif"
statements and is being incorrectly flagged as the first "if" line?

Thanks for your help,


Chris.


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

Date: Thu, 1 Apr 2004 15:36:06 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: uninitialized value in concatenation ...
Message-Id: <slrnc6p2q6.406.tadmc@magna.augustmail.com>

Paul Lalli <ittyspam@yahoo.com> wrote:
> On Thu, 1 Apr 2004, Tad McClellan wrote:

[ snip my drivel ]

> But the statements you posted have nothing to do with the
> problem at hand.


Oops.

Sorry.


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


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

Date: Thu, 01 Apr 2004 12:44:56 -0500
From: Dan Pelton <dnp@ams.org>
Subject: Re: validate links??
Message-Id: <c4hplp$g4h$1@sun06.ams.org>

Your right. I didn't look close enough at the page in my browser.

Brian McCauley wrote:
> Dan Pelton <dnp@ams.org> rudley vomits TOFU in our faces:
> 
> [ Please do not be so rude in future ]
> 
> 
>>I tried using LWP::UserAgent, but it still failed. Any ideas why?
>>
>>I get the error:   Error while getting http://www.mathsoft.com/asolve/
>>    response 404 Object Not Found
> 
> 
> You give it a bad URL, you get an error.  Why do you consider that
> to be a failure?
> 



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

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


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