[24158] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6352 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Apr 1 14:05:56 2004

Date: Thu, 1 Apr 2004 11:05:07 -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: 6352

Today's topics:
        "which perl": Different for root and users <footnipple@indiatimes.com>
    Re: "which perl": Different for root and users (Anno Siegel)
    Re: CGI script does not print values selected??? <glex_nospam@qwest.invalid>
        DBI:mysql and huge tables <t.goetz@dkfz.de>
    Re: DBI:mysql and huge tables <tore@aursand.no>
    Re: DBI:mysql and huge tables ctcgag@hotmail.com
    Re: DBI:mysql and huge tables <tore@aursand.no>
        include different files at run time (rzhu)
    Re: include different files at run time (Anno Siegel)
    Re: Is Perl supposed to use 100% of the CPU? <rwbean@yahoo.com>
    Re: Is there any standard newsgroup messages parser? <glex_nospam@qwest.invalid>
    Re: Ptkdb 1.1091 Available at SourceForge.net (Andrew E Page)
        Subliminals.  Stop it. <bmb@ginger.libs.uga.edu>
    Re: trapping errors (Randal L. Schwartz)
    Re: trapping errors <simalt@totalise.co.uk>
        uninitialized value in concatenation ... (Chris Conwell)
    Re: uninitialized value in concatenation ... <tore@aursand.no>
    Re: uninitialized value in concatenation ... (Anno Siegel)
    Re: uninitialized value in concatenation ... <tadmc@augustmail.com>
    Re: validate links?? <dnp@ams.org>
    Re: validate links?? <nobull@mail.com>
        What is the current package? (nospam)@usit.uio(nospam)
    Re: What is the current package? <ittyspam@yahoo.com>
    Re: What is the current package? <bmb@ginger.libs.uga.edu>
    Re: What is the current package? (nospam)@usit.uio(nospam)
    Re: What is the current package? (nospam)@usit.uio(nospam)
    Re: What is the current package? <ittyspam@yahoo.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 01 Apr 2004 16:21:29 GMT
From: "sdfgsd" <footnipple@indiatimes.com>
Subject: "which perl": Different for root and users
Message-Id: <dkXac.371633$B81.5482404@twister.tampabay.rr.com>

Hello again,

Just solved one set of problems with a 5.8.0 => 5.8.3 upgrade and now I have
another:

When I type 'which perl' I get '/usr/local/bin/perl' for users and
'/usr/bin/perl' for root! Is this a Suse/Linux issue or a Perl issue? I've
googled, perldoc'ed and still can't figure this out.

Incidently, my new Perl executable (compiled as root) is in /usr/bin and
user scripts still want /usr/local/bin/perl even when I place
'#!/usr/bin/perl' at the top of the script.




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

Date: 1 Apr 2004 17:25:39 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: "which perl": Different for root and users
Message-Id: <c4hjaj$h48$2@mamenchi.zrz.TU-Berlin.DE>

sdfgsd <footnipple@indiatimes.com> wrote in comp.lang.perl.misc:
> Hello again,
> 
> Just solved one set of problems with a 5.8.0 => 5.8.3 upgrade and now I have
> another:
> 
> When I type 'which perl' I get '/usr/local/bin/perl' for users and
> '/usr/bin/perl' for root! Is this a Suse/Linux issue or a Perl issue? I've
> googled, perldoc'ed and still can't figure this out.

It's a Unix issue.

Presumably users have /usr/local/bin before /usr/bin on their path, and
root hasn't.  This is as it should be.  In fact, it isn't a bad idea to
keep root's perl separate and not have it hop along with every version
change.

> Incidently, my new Perl executable (compiled as root) is in /usr/bin and
> user scripts still want /usr/local/bin/perl even when I place
> '#!/usr/bin/perl' at the top of the script.

I don't understand what you are saying.

Anno



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

Date: Thu, 01 Apr 2004 11:51:34 -0600
From: "J. Gleixner" <glex_nospam@qwest.invalid>
Subject: Re: CGI script does not print values selected???
Message-Id: <GEYac.134$Ru5.36872@news.uswest.net>

Bing Du wrote:
> 
> Greetings,
> 
> No matter what year(s) I select from the list on the web, the selected 
> years are not printed out as they are supposed to be.  Would anybody 
> tell me what's wrong?  Appreciate any help!
> 
> test.cgi:
> 
> ================================
> #!/usr/bin/perl
> 
> use CGI;
use strict;

> 
> print "content-type: text/html\n\n";

If you're going to "use CGI" then use its methods, instead of doing 
things incorrectly.

> 
> $program = "test.cgi";
my $program = 'test.cgi'; #actually it's not needed.. see the
documentation for CGI.

> my $q = new CGI;

Ok.. This should help you see your problem.  Display the parameters and 
their values:

foreach ($q->param()) {
	print "param($_) = ", $q->param($_), $q->br;
}

> 
> 
>  if ($q->param('select_year'))
>  {
>     @years = $q->param('years');

hint.. 'years' does not equal 'years[]'

>     print "Class Schedules for years (",join(',',@years),")<br>";
>     exit;
>  }
> 
> print <<_HTML;
> 
> <form method=post action=$program>
> 
> <select name=years[] size=5 multiple>
> <option>2003
> <option>2004
> </select>
> <input type=submit name=select_year value=GO>
> 
> </form>
> 
> _HTML


Generally, it's easier to use the :standard methods in CGI, then you 
don't have to explicitly create an object or reference it everywhere.

use CGI qw(:standard);
print header();  #... note no $q.. much cleaner.. :-)

Also,  poor HTML.  I know this is a basic example, however starting with 
good HTML will really help in the long run.. See the example in the 
documentation for CGI (header, start_html, end_html) should be in most 
CGI scripts that output a page.  Those methods do all the work for you.

See ya


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

Date: Thu, 01 Apr 2004 14:16:30 GMT
From: Thomas =?ISO-8859-15?Q?G=F6tz?= <t.goetz@dkfz.de>
Subject: DBI:mysql and huge tables
Message-Id: <2vVac.12175586$Of.2032937@news.easynews.com>

hi there,

I have the following problem:

I'm using a MySQL database with a table that contains around 500.000
records. If I now want to select all that rows to do something with them,
this is getting _very_ memory-consuming.
Here's the code I use:

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

use strict;
use warnings;
use DBI;

my $dsn         = "DBI:mysql:SOME_DATABASE:localhost";
my $user        = "tom";
my $pwd         = "*********";

my $dbh = DBI->connect($dsn, $user, $pwd) or die;
my $sql = qq{SELECT `SOME_FIELD` ` FROM `SOME_TABLE`};
my $sth = $dbh->prepare($sql);
$sth->execute;

while (my $result = $sth->fetchrow_array) {
        print "$result\n";
}
$sth->finish;
$dbh->disconnect;
exit;
---------

So, when executing the statement it seems that all result are loaded into
memory before they are processed, which is not what I want. What could I do
to speed up things and become less memory hungry?

Tom



-- 
Thomas Götz
German Cancer Research Center


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

Date: Thu, 01 Apr 2004 17:16:30 +0200
From: Tore Aursand <tore@aursand.no>
Subject: Re: DBI:mysql and huge tables
Message-Id: <pan.2004.04.01.15.13.01.354134@aursand.no>

On Thu, 01 Apr 2004 14:16:30 +0000, Thomas Götz wrote:
> my $sql = qq{SELECT `SOME_FIELD` ` FROM `SOME_TABLE`};
> my $sth = $dbh->prepare($sql);
> $sth->execute;
> while (my $result = $sth->fetchrow_array) {
>         print "$result\n";
> }
> $sth->finish;
> $dbh->disconnect;
> exit;
> 
> So, when executing the statement it seems that all result are loaded
> into memory before they are processed, which is not what I want. What
> could I do to speed up things and become less memory hungry?

I have never thought of this, even though I've created scripts which deal
with a "fair amount" of data.  Are you _absolutely_ sure that this happens?

Unfortunately, I don't have a large (enough) dataset to this on, but you
could always try 'fetchrow_arrayref()' instead of 'fetchrow_array()'.  I
doubt it will consume less memory (hey, who knows?), but according to the
DBI documentation (AFAIR) it's faster.


-- 
Tore Aursand <tore@aursand.no>
"When you love someone, all your saved-up wishes start coming out." --
 Elizabeth Bowen


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

Date: 01 Apr 2004 16:54:11 GMT
From: ctcgag@hotmail.com
Subject: Re: DBI:mysql and huge tables
Message-Id: <20040401115411.681$9T@newsreader.com>

Thomas =?ISO-8859-15?Q?G=F6tz?= <t.goetz@dkfz.de> wrote:
> hi there,
>
> I have the following problem:
>
> I'm using a MySQL database with a table that contains around 500.000
> records. If I now want to select all that rows to do something with them,
> this is getting _very_ memory-consuming.
> Here's the code I use:
 ...
> my $sql = qq{SELECT `SOME_FIELD` ` FROM `SOME_TABLE`};
> my $sth = $dbh->prepare($sql);

$sth->{mysql_use_result}=1; ## Add this line here

> $sth->execute;
>
> while (my $result = $sth->fetchrow_array) {
>         print "$result\n";
> }
> $sth->finish;
> $dbh->disconnect;
> exit;
> ---------
>
> So, when executing the statement it seems that all result are loaded into
> memory before they are processed,

Yep, that does appear to be the default behavior.  I guess it is because
readers block writers in mysql, so it wants to read the data as fast as
possible (i.e. into memory) to get out of the way.

> which is not what I want. What could I
> do to speed up things and become less memory hungry?

set the mysql_use_result attribute after prepare but before execute.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: Thu, 01 Apr 2004 19:39:02 +0200
From: Tore Aursand <tore@aursand.no>
Subject: Re: DBI:mysql and huge tables
Message-Id: <pan.2004.04.01.17.37.57.244284@aursand.no>

On Thu, 01 Apr 2004 16:54:11 +0000, ctcgag wrote:
>> which is not what I want. What could I do to speed up things and become
>> less memory hungry?

> set the mysql_use_result attribute after prepare but before execute.

Ah.  Excellent.  This teaches me to read the DBD::mysql documentation, not
only the DBI documentation.

One suggestion, though:  It's possible to set this "flag" on a per-query
basis, so that only a few queries are affected;

  my $sth = $dbh->prepare('SELECT lots_of_data
                           FROM   huge',
                         {'mysql_use_result' => 1});
  $sth->execute();
  ...
  $sth->finish();

One should have this in mind, though:

  "...the 'mysql_use_result' attribute: This forces the driver to
   use 'mysql_use_result' rather than 'mysql_store_result'. The
   former is faster and less memory consuming, but tends to block
   other processes."

In other words:  As long as you're running this script quite stand-alone,
you could very well go fo the 'mysql_use_result' solution.

Thanks to 'ctcgag' for pointing this out!


-- 
Tore Aursand <tore@aursand.no>
"Omit needless words. Vigorous writing is concise. A sentence should
 contain no unnecessary words, a paragraph no unnecessary sentences,
 for the same reason that a drawing should have no unnecessary lines
 and a machine no unnecessary parts." -- William Strunk Jr.


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

Date: 1 Apr 2004 09:31:06 -0800
From: rzhu@devonit.com (rzhu)
Subject: include different files at run time
Message-Id: <56fb1d87.0404010931.7b9dc556@posting.google.com>

Hi, Guys

I'm a newbie in Perl, and I have this question for web development. To
support different languages, I'm planning to extract all the text
strings from the perl CGI code, and define them in different hashes in
separate file. The idea is that at run time, depending on which
language user select, I can load proper file, hence the proper hash
for that language. Drop those strings into a static template HTML file
(also grouped in different directories for different language). The
ultimate goal is that to add support for a new language, I just have
to create a new file, translate all strings in that hash, stick it
into a new directory, and I'm done. No code mod needed.

The question is, how do I do this in perl? It seems there is not a
perl equivalent of ASP "include". Can anyone help?

Thanks in advance. 


R. Zhu


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

Date: 1 Apr 2004 17:44:32 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: include different files at run time
Message-Id: <c4hke0$h48$3@mamenchi.zrz.TU-Berlin.DE>

rzhu <rzhu@devonit.com> wrote in comp.lang.perl.misc:
> Hi, Guys
> 
> I'm a newbie in Perl, and I have this question for web development. To
> support different languages, I'm planning to extract all the text
> strings from the perl CGI code, and define them in different hashes in
> separate file. The idea is that at run time, depending on which
> language user select, I can load proper file, hence the proper hash
> for that language. Drop those strings into a static template HTML file
> (also grouped in different directories for different language). The
> ultimate goal is that to add support for a new language, I just have
> to create a new file, translate all strings in that hash, stick it
> into a new directory, and I'm done. No code mod needed.
> 
> The question is, how do I do this in perl? It seems there is not a
> perl equivalent of ASP "include". Can anyone help?

I don't know what ASP "include" does.

Look at Perl's "use", "require", etc.

Anno



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

Date: Thu, 1 Apr 2004 08:37:19 -0600
From: "Ron Bean" <rwbean@yahoo.com>
Subject: Re: Is Perl supposed to use 100% of the CPU?
Message-Id: <c4h9ev$2jd5k6$1@ID-15411.news.uni-berlin.de>

"Sherm Pendley" <spamtrap@dot-app.org> wrote in message
news:eKednW3IE-0Cf_fdRVn-ig@adelphia.com...
> Ron Bean wrote:
>
> > The question is:  Is it supposed to use so much of the CPU?
>
> Perl, by itself, uses 0% CPU.
>
> A badly-written Perl script, just like a badly-written program in any
other
> language, can use up 100% of your CPU and beg for more.
>
> > Any ideas as to get my site speed back up?
>
> Sure, three simple steps:
>
> 1. Figure out what script is swamping your server. If there is only one
> script, it's obviously the culprit. If XP provides some means of listing
> CPU usage for Perl scripts individually, do that. Otherwise, look to see
if
> any of the scripts on the system have been added or changed recently. As a
> last resort, take scripts offline one at a time, observing the CPU load
> each time. When removing one of them reduces the load, you've found the
> culprit.
>
> 2. Profile the problem script to determine where it's slow. Take care of
the
> low-hanging fruit first; i.e. see what's changed recently. For example, if
> the script was running fine, but a new function to calculate foo was added
> and now it's bog-slow, then that function is what you should be looking
at.
> You could also use Devel::DProf to profile your code.
>
> 3. Fix it. This is an exercise left to the reader. ;-)
>

Printed and archived this post for future reference.

Many thanks!  I think I may have narrowed it down to the script that is
causing the problem.  Luckily I haven't added too many scripts.  :-)

Also changed the way XP allocates memory and CPU cycles, as the pc I'm using
is now a dedicated server.  So far it seems to be working just fine.

Thanks again,

Ron




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

Date: Thu, 01 Apr 2004 11:53:56 -0600
From: "J. Gleixner" <glex_nospam@qwest.invalid>
Subject: Re: Is there any standard newsgroup messages parser?
Message-Id: <UGYac.135$Ru5.37267@news.uswest.net>

Darek Adamkiewicz wrote:
> Hello Folks
> 
> Till now I used self-made parser script for self-made message file 
> format - I was wondering if there is a standard perl parser for standard 
> nntp messages files? (with ability to build thread of messages)?

Take a look at CPAN:

	http://search.cpan.org/

A lot of NNTP related modules.


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

Date: 1 Apr 2004 10:13:19 -0800
From: aepage@users.sourceforge.net (Andrew E Page)
Subject: Re: Ptkdb 1.1091 Available at SourceForge.net
Message-Id: <617a8128.0404011013.7d2d65a2@posting.google.com>

aepage@users.sourceforge.net (Andrew E Page) wrote in message news:<617a8128.0403311729.5fa2ffac@posting.google.com>...

Information about what ptkdb is and what it does can be found at:

http://ptkdb.sourceforge.net

ptkdb is a debugger for perl based on the PerlTk GUI Toolkit.  

It is NOT a wrapper around the existing perl debugger.  It is a
complete and independent implementation of a debugger for perl.


> The latest release of ptkdb is now on sourceforge.net.  
> 
> This release corrects problems with the latest releases of perl(5.8.3)
> and PerlTk(804.026)
> 
> 
> Use the following link to get the distribution file.
> 
> 
> http://sourceforge.net/project/showfiles.php?group_id=43854
> 
> Please Report bugs through the following link:
> 
> 
> http://sourceforge.net/tracker/?group_id=43854&atid=437609


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

Date: Thu, 1 Apr 2004 09:37:47 -0500
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Subliminals.  Stop it.
Message-Id: <Pine.A41.4.58.0404010928300.14472@ginger.libs.uga.edu>

Last night I was reading the docs for Filter::Simple.  This morning the
following chorus, music AND lyrics, is ringing in my brain.  I am not
amused.

Here, let me share my joy:

    Bang Bang Chitty Chitty Bang Bang,
    My fine four-fendered friend,

    ... All together now! ...

    Bang Bang Chitty Chitty Bang Bang,
    My fine four-fendered friend,

Mercifully, there are antidotes.  May I recommend Satin Doll, or perhaps
some ZZ Top ...

Regards,

Brad
-- 

You need just enough of that sticky stuff
to hold the seams of your fine blue jeans.
I say yeah yeah.
I say yeah yeah.
There ain't never a catch, all you got to do is snatch,
do the velcro fly,
do the velcro fly.


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

Date: 01 Apr 2004 06:13:18 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: trapping errors
Message-Id: <86r7v7lrb5.fsf@blue.stonehenge.com>

*** post for FREE via your newsreader at post.newsfeed.com ***

>>>>> "Tad" == Tad McClellan <tadmc@augustmail.com> writes:

Tad> Or make that:

Tad>    my($file_count) = readdir(DIR);

Errr, no.  That puts the first element of readdir into $file_count.
Tad, you're slipping. :-)

print "Just another Perl hacker,"; # the first (or is that 0th?)

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


 -----= Posted via Newsfeed.Com, Uncensored Usenet News =-----
http://www.newsfeed.com - The #1 Newsgroup Service in the World!
-----== 100,000 Groups! - 19 Servers! - Unlimited Download! =-----
                  


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

Date: Thu, 1 Apr 2004 16:57:35 +0100
From: "Simon" <simalt@totalise.co.uk>
Subject: Re: trapping errors
Message-Id: <406c3bf0$1@primark.com>

Thanks Ted

That acutally prints this...

/active .
/test .
/develop .
/utils .

Simon
"Randal L. Schwartz" <merlyn@stonehenge.com> wrote in message
news:86r7v7lrb5.fsf@blue.stonehenge.com...
> *** post for FREE via your newsreader at post.newsfeed.com ***
>
> >>>>> "Tad" == Tad McClellan <tadmc@augustmail.com> writes:
>
> Tad> Or make that:
>
> Tad>    my($file_count) = readdir(DIR);
>
> Errr, no.  That puts the first element of readdir into $file_count.
> Tad, you're slipping. :-)
>
> print "Just another Perl hacker,"; # the first (or is that 0th?)
>
> -- 
> Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777
0095
> <merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
> Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
> See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl
training!
>
>
>  -----= Posted via Newsfeed.Com, Uncensored Usenet News =-----
> http://www.newsfeed.com - The #1 Newsgroup Service in the World!
> -----== 100,000 Groups! - 19 Servers! - Unlimited Download! =-----
>




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

Date: 1 Apr 2004 06:19:51 -0800
From: chris@mobiles.co.uk (Chris Conwell)
Subject: uninitialized value in concatenation ...
Message-Id: <5f675152.0404010619.6299847@posting.google.com>

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: 
 
"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"?!?!?

Thanks in advance,


Chris


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

Date: Thu, 01 Apr 2004 17:16:30 +0200
From: Tore Aursand <tore@aursand.no>
Subject: Re: uninitialized value in concatenation ...
Message-Id: <pan.2004.04.01.15.16.08.101246@aursand.no>

On Thu, 01 Apr 2004 06:19:51 -0800, Chris Conwell wrote:
> 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: 
>  
> "Use of uninitialized value in concatenation (.) or string at
> cgi/phones.pl line 3917."

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 )'.

(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...)

:)


-- 
Tore Aursand <tore@aursand.no>
"Fighting terrorism is like being a goalkeeper. You can make a hundred
 brilliant saves but the only shot that people remember is the one that
 gets past you." -- Paul Wilkinson


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

Date: 1 Apr 2004 15:17:43 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: uninitialized value in concatenation ...
Message-Id: <c4hbqn$ce3$1@mamenchi.zrz.TU-Berlin.DE>

Chris Conwell <chris@mobiles.co.uk> wrote in comp.lang.perl.misc:
> 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: 
>  
> "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"?!?!?

Are there else-clauses?

Anno


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

Date: Thu, 1 Apr 2004 11:55:05 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: uninitialized value in concatenation ...
Message-Id: <slrnc6olrp.3re.tadmc@magna.augustmail.com>

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).


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


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

Date: Thu, 01 Apr 2004 09:56:37 -0500
From: Dan Pelton <dnp@ams.org>
Subject: Re: validate links??
Message-Id: <c4hfq7$184$1@sun06.ams.org>

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

Here is the code:
----------------------------------------------------
#!/usr/bin/perl -w
# check html link

use LWP::UserAgent;
my $url;
 
my $ua = LWP::UserAgent->new;
$ua->timeout(100);
$ua->max_redirect(100);

$url = 'http://www.mathsoft.com/asolve/';

my $response = $ua->get($url);

if ($response->is_success()) {
    print "valid\n"; 
} else {
    print "Bad Url: $url\n"; 
    print "Error while getting " . $response->request->uri . "\n";
    print "    response " . $response->status_line . "\n";
}
exit;


thanks,
Dan

> Dan Pelton wrote:
> 
>> Whats the best way to check for broken links on a web page. These 
>> links goto to CGIs and some of the links a redirected. I tried the 
>> code below from the perl cook book. It works fine for links to html 
>> pages only.
>>
>> "churl.pl http://www.ams.org" reports that http://www.ams.org/eims is 
>> BAD, but it is a valid URL.
>>
>> Any suggestions?
>>
>> thanks,
>> Dan
>>
>> --------------------------------------------------------
>> #!/usr/bin/perl -w
>> # churl - check urls
>> use HTML::LinkExtor;
>> use LWP::Simple;
>> $base_url = shift
>>    or die "usage: $0 <start_url>\n";
>> $parser = HTML::LinkExtor->new(undef, $base_url);
>> $html = get($base_url);
>> die "Can't fetch $base_url" unless defined($html);
>> $parser->parse($html);
>> @links = $parser->links;
>> print "$base_url: \n";
>> foreach $linkarray (@links) {
>>    my @element  = @$linkarray;
>>    my $elt_type = shift @element;
>>    while (@element) {
>>        my ($attr_name , $attr_value) = splice(@element, 0, 2);
>>        if ($attr_value->scheme =~ /\b(ftp|https?|file)\b/) {
>>            print "  $attr_value: ", head($attr_value) ? "OK" : "BAD", 
>> "\n";
>>        }
>>    }
>> }
>>
> 
> The URL http://www.ams.org/eims results in a redirection response from 
> the server to https://www.ams.org/eims/. In scalar context the head() 
> function returns a false value when the attempt to access the URL fails, 
> therefore you get 'BAD'. Make sure you have Crypt::SSLeay installed:
> 
> perl -MCrypt::SSLeay
> 
> If you don't, you won't be able to access URLs with the https scheme and 
> need to install the module. Do a 'perldoc lwpcook' from your shell for 
> an explanation - look under the 'HTTPS' heading.
> 
> If you're going to be doing more complicated things in the future, have 
> a look at LWP::UserAgent - it gives you a lot more options. For example, 
> in this case you could have checked the server response code with the 
> LWP::UserAgent is_error() method.
> 
> HTH - keith



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

Date: 01 Apr 2004 17:47:59 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: validate links??
Message-Id: <u9oeqb63wg.fsf@wcl-l.bham.ac.uk>

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?

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: 01 Apr 2004 16:18:53 +0200
From: Hallvard B Furuseth <h.b.furuseth(nospam)@usit.uio(nospam).no>
Subject: What is the current package?
Message-Id: <HBF.20040401xdhv@bombur.uio.no>

Is there a standard way to refer to the current package?  It feels a
little strange for code in a class to put its own package name in
quotes.  Though I suppose I could do this:

  package Foo;
  use constant This_class => ref(bless []); # "Foo"
  ...
  if ($val->isa(This_class)) { ... }

-- 
Hallvard


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

Date: Thu, 1 Apr 2004 09:54:21 -0500
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: What is the current package?
Message-Id: <20040401095353.C19862@dishwasher.cs.rpi.edu>

On Thu, 1 Apr 2004, Hallvard B Furuseth wrote:

> Is there a standard way to refer to the current package?  It feels a
> little strange for code in a class to put its own package name in
> quotes.  Though I suppose I could do this:
>
>   package Foo;
>   use constant This_class => ref(bless []); # "Foo"
>   ...
>   if ($val->isa(This_class)) { ... }
>

perldoc -q 'current package'


Sheesh.



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

Date: Thu, 1 Apr 2004 09:55:32 -0500
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Re: What is the current package?
Message-Id: <Pine.A41.4.58.0404010954360.14472@ginger.libs.uga.edu>

On Thu, 1 Apr 2004, Hallvard B Furuseth wrote:

> Is there a standard way to refer to the current package?  It feels a
> little strange for code in a class to put its own package name in
> quotes.  Though I suppose I could do this:
>
>   package Foo;
>   use constant This_class => ref(bless []); # "Foo"
>   ...
>   if ($val->isa(This_class)) { ... }

Is this what you're after:

package Foo;
use constant This_class => __PACKAGE__;
my $val = bless [], __PACKAGE__;
if($val->isa(This_class)) { print "Yes!\n" }
print ref($val), "\n";

__END__

Yes!
Foo

Regards,

Brad


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

Date: 01 Apr 2004 17:05:42 +0200
From: Hallvard B Furuseth <h.b.furuseth(nospam)@usit.uio(nospam).no>
Subject: Re: What is the current package?
Message-Id: <HBF.20040401wlbf@bombur.uio.no>

Paul Lalli wrote:

> perldoc -q 'current package'
> 
> Sheesh.

Not in per5.004_04.  Perhaps it's time to ask someone to upgrade...
Anyway, I found a newer Perl where that command worked.  Thanks.

-- 
Hallvard


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

Date: 01 Apr 2004 17:09:18 +0200
From: Hallvard B Furuseth <h.b.furuseth(nospam)@usit.uio(nospam).no>
Subject: Re: What is the current package?
Message-Id: <HBF.20040401wj5d@bombur.uio.no>

Brad Baxter wrote:

> Is this what you're after:
> 
> package Foo;
> use constant This_class => __PACKAGE__;
> my $val = bless [], __PACKAGE__;
> if($val->isa(This_class)) { print "Yes!\n" }
> print ref($val), "\n";

Yup.  Except I hoped to avoid This_class.
$val->isa(__PACKAGE__) looks nicer.
Thanks.

-- 
Hallvard


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

Date: Thu, 1 Apr 2004 13:23:16 -0500
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: What is the current package?
Message-Id: <20040401132148.O19862@dishwasher.cs.rpi.edu>

On Thu, 1 Apr 2004, Hallvard B Furuseth wrote:

> Paul Lalli wrote:
>
> > perldoc -q 'current package'
> >
> > Sheesh.
>
> Not in per5.004_04.  Perhaps it's time to ask someone to upgrade...
> Anyway, I found a newer Perl where that command worked.  Thanks.

I don't want to be too much of a bastard, but having an outdated version
of perl is not an excuse for not reading the FAQs.

www.perl.com -> documentation -> FAQs -> About the Perl FAQ
search for "current package".

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


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