[25557] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7801 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Feb 19 18:10:49 2005

Date: Sat, 19 Feb 2005 15:10:37 -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           Sat, 19 Feb 2005     Volume: 10 Number: 7801

Today's topics:
    Re: Newbie question sorting <phaylon@dunkelheit.at>
    Re: Newbie question sorting <noreply@gunnar.cc>
    Re: Newbie question sorting <mritty@gmail.com>
        Not printing before ftp command <yyusenet@yahoo.com>
    Re: Not printing before ftp command <yyusenet@yahoo.com>
    Re: Not printing before ftp command <jurgenex@hotmail.com>
    Re: Perl script timeout problem <jurgenex@hotmail.com>
    Re: Perl script timeout problem <nobull@mail.com>
    Re: Perl scripting course <amead@comcast.net>
        prob send and NET::SMTP <ekeith@free.fr>
    Re: variation on 'calling subroutine via reference'? <tassilo.von.parseval@rwth-aachen.de>
    Re: variation on 'calling subroutine via reference'? <noreply@gunnar.cc>
    Re: Why aren't 'warnings' on by default? <tassilo.von.parseval@rwth-aachen.de>
    Re: Why aren't 'warnings' on by default? <phaylon@dunkelheit.at>
    Re: Why aren't 'warnings' on by default? (Anno Siegel)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 18 Feb 2005 20:18:43 +0100
From: phaylon <phaylon@dunkelheit.at>
Subject: Re: Newbie question sorting
Message-Id: <pan.2005.02.18.19.18.43.11466@dunkelheit.at>

mdfoster44 wrote:

> Could someone please point me to some documentation on how to sort arrays
> such as these?

Sure: 'perldoc -f sort'.

hth,phay

-- 
http://www.dunkelheit.at/
thou shallst fear...



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

Date: Fri, 18 Feb 2005 20:37:17 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Newbie question sorting
Message-Id: <37mudjF5dir64U2@individual.net>

mdfoster44@netscape.net wrote:
> Could someone please point me to some documentation on how to sort
> arrays such as these?
> 
> a[0][0]= ANA a[0][1]= 1
> a[1][0]= MFI a[1][1]= 12
> a[2][0]= ABW a[2][1]= 1
> a[3][0]= LTL a[3][1]= 2
> a[4][0]= APD a[4][1]= 2

Which programming language are you dealing with? That does not look like 
Perl code to me.

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


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

Date: Fri, 18 Feb 2005 19:54:31 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Newbie question sorting
Message-Id: <XJrRd.31490$s16.1324@trndny02>

<mdfoster44@netscape.net> wrote in message
news:1108752461.443860.42760@o13g2000cwo.googlegroups.com...

> Could someone please point me to some documentation on how to sort

perldoc -f sort

> arrays such as these?
>
> a[0][0]= ANA a[0][1]= 1
> a[1][0]= MFI a[1][1]= 12
> a[2][0]= ABW a[2][1]= 1
> a[3][0]= LTL a[3][1]= 2
> a[4][0]= APD a[4][1]= 2

What language is this?

> I would like to sort the first column

How are you defining 'column'?

> after sorting the second column numerically.
> So the sort of the above data should give back.
>
> ABW 1
> ANA 1
> APD 2
> LTL 2
> MFI 12
>

#!/usr/bin/perl
use strict;
use warnings;
my @data = (
['ANA', 1],
['MFI', 12],
['ABW', 1],
['LTL', 2],
['APD', 2],);

print "$_->[0] $_->[1]\n" for sort {$a->[1] <=> $b->[1] or $a->[0] cmp
$b->[0]} @data;

__END__
ABW 1
ANA 1
APD 2
LTL 2
MFI 12



Paul Lalli



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

Date: Sat, 19 Feb 2005 13:07:14 -0700
From: YYusenet <yyusenet@yahoo.com>
Subject: Not printing before ftp command
Message-Id: <cv869a$erv$1@news.xmission.com>

Hello,

I was wondering why the print command will not print to the screen 
before the process is finished.
For example, when I run the following code (part of a larger piece of 
code that will follow):
--------
[snip]
print "Connecting to server...";
$ftp=Net::FTP->new($host, hash => 1);
die "ERROR: $@" if $@;
print "Connected to server.\nAttempting login...";
$ftp->login($user,$pw) or die "could not login";
die "ERROR: $@" if $@;
print "Logged in.\nChanging dir...";
[snip]
--------
It waits for the server to connect and then it prints "Connecting to 
server...Connected to server."  Then it waits until the loggin has 
completed then it will print "Attempting login...Logged in."

Is there some way to change this?

The full code follows:
--------
#!/usr/bin/Perl

use warnings;
use strict;

#Net::FTP can be found at http://tinyurl.com/5m8l6
use Net::FTP;

my $host = "HOST";
my $path = "mail";
my $user = "USERNAME";
my $pw = "PASSWORD";

my $ftp;

print "Connecting to server...";
$ftp=Net::FTP->new($host, hash => 1);
die "ERROR: $@" if $@;
print "Connected to server.\nAttempting login...";
$ftp->login($user,$pw) or die "could not login";
die "ERROR: $@" if $@;
print "Logged in.\nChanging dir...";
$ftp->cwd($path) or die "could not cwd $path";
die "ERROR: $@" if $@;
print "Directory changed.\nRetrieving file 'Storage Folder'...";
my ($sec,$min,$hour,$mday,$mon,$year) = localtime();
#Format Time
$year += 1900; $mon += 1; $mon = sprintf("%02d",$mon);
	$mday = sprintf("%02d",$mday); $hour = sprintf("%02d",$hour);
	$min = sprintf("%02d",$min); $sec = sprintf("%02d",$sec);
my $time = $year . $mon . $mday . $hour . $min . $sec;
$ftp->get("Storage Folder","Storage Folder_" . $time);
die "ERROR: $@" if $@;
print "File 'Storage Folder' has been retrieved.\nCleaning folder...";
$ftp->put("Blank Folder","Storage Folder");
die "ERROR: $@" if $@;
print "Folder cleaned.\nClosing connection...";
$ftp->quit();
die "ERROR: $@" if $@;
print "Connection closed.\n";
-------

Any help will be appreciated.

Thanks,

-- 
k g a b e r t (at) x m i s s i o n (dot) c o m

*Support Mozilla Firefox*!
http://www.spreadfirefox.com/?q=user/register&r=71209


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

Date: Sat, 19 Feb 2005 13:47:13 -0700
From: YYusenet <yyusenet@yahoo.com>
Subject: Re: Not printing before ftp command
Message-Id: <cv88k8$gki$1@news.xmission.com>

J=FCrgen Exner wrote:
> YYusenet wrote:
>=20
>>I was wondering why the print command will not print to the screen
>>before the process is finished.
>>--------
>>[snip]
>>print "Connecting to server...";
>=20
>=20
> perldoc -q buffer: "How do I flush/unbuffer an output filehandle?  Why =
must=20
> I do this?"
>=20
> jue
>=20
>=20
Thank you!
That worked.

--=20
k g a b e r t (at) x m i s s i o n (dot) c o m

*Support Mozilla Firefox*!
http://www.spreadfirefox.com/?q=3Duser/register&r=3D71209


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

Date: Sat, 19 Feb 2005 20:20:06 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Not printing before ftp command
Message-Id: <WbNRd.43020$uc.2095@trnddc04>

YYusenet wrote:
> I was wondering why the print command will not print to the screen
> before the process is finished.
> --------
> [snip]
> print "Connecting to server...";

perldoc -q buffer: "How do I flush/unbuffer an output filehandle?  Why must 
I do this?"

jue




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

Date: Sat, 19 Feb 2005 16:14:08 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Perl script timeout problem
Message-Id: <kBJRd.42357$uc.7092@trnddc04>

sipitai wrote:
> For anyone who isn't sure of the exact cause of the problem, but would
> like to suggest an alternative method of achieving the same result,
> the following is a description of what im trying to do.
>
> The script is part of a shopping cart designed specifically for
[...]
> So if you can think of a better way of implementing it, by all means
> let me know. Your input would be greatly appreciated!

Do you have a Perl question, too?
Otherwise I would suggest you head over to the CGI NGs because your question 
has _very_little_ to do with Perl but a _whole_lot_ with CGI and web 
authoring.

jue 




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

Date: Sat, 19 Feb 2005 16:33:29 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Perl script timeout problem
Message-Id: <cv7pen$1j4$1@sun3.bham.ac.uk>



sipitai wrote:

> Brian McCauley wrote...
> 
> 
>>
>>if ( key_has_expired ) {
>>   display_error_page;
>>} else {
>>   perform_internal_redirect; # Client never sees the real URL
>>}
> 
> 
> Although now im not entirely sure what you mean by performing an
> internal redirect to the file.

You put the file in a directory that where it would be directly 
accessible by a URL but don't tell anyone the directory.

Your CGI script then sends a CGI  response to the web server that tells 
it to  genereate an HTTP response as if it had gotten a simple GET 
request for the file.

You may even be able to configure your web server so that requests to 
the secret directory that do not come via an internal redirect are 
declined. This way wouldn't need to keep it secret.

(Nore of this, of course, has the slightest thing to do with Perl).

 > If you could explain this in a bit more detail,

One way for a Perl script to send an internal redirect CGI response 
would be:

print "Location: /some/non/published/path/$file\n\n";

Note that an internal redirect does have the 
'http://someserver.example.com/' prefix but starts at the '/' that is 
the root of the current (virtual) server.

You could possibly use the redirect() method from CGI.pm rather than a 
raw print() but this also generates a "Status:" header and I suspect 
this may confuse some web servers into generating an external redirect.

You need to ensure that you web server software is configured not to 
include 'helpful' Content-location headers that contain the true URL of 
HTTP entities that resolve via internal redirects.

> ...or point me in the direction of a website that covers this
> subject, I would be greatly appreciative.

Any website containing CGI reference or tutorial documentation should 
cover this.



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

Date: Sat, 19 Feb 2005 11:14:27 -0600
From: Alan Mead <amead@comcast.net>
Subject: Re: Perl scripting course
Message-Id: <pan.2005.02.19.17.14.26.314382@comcast.net>

On Fri, 18 Feb 2005 12:44:17 -0800, joutlaw wrote:

> I live in the Northern VA/DC metro region, and I am an Oracle DBA
> looking to pick up on Perl scripting. I was wondering if anyone could
> recommend a learning center (i.e. Learning Tree). Also, would be better
> suited for Unix Shell Scripting as opposed to Perl? Thanks in advance!

I suspect that most people learn Perl through a combination of reading
books and using on-line materials like various articles and other people's
sources.  There is a book about using Perl for system administration, for
example.  

The nice thing about existing code is that it meets your immediate needs,
as well as being educational.

Not having done much shell scripting, I think the main advantages of Perl
for that purpose are: (1) better data structures and (2) a better
framework.  For example, if you start making complex scripts, you can use
OOP in Perl.  You can also leverage the vast mountain of code modules
already written for Perl.  For example, you could access your Oracle
databases using Perl.  Perl is also considered "a natural" by many people
when it comes to manipulating data, especially text data.  Many people use
Perl as "glue" between otherwise unconnected processes.  (XML is supposed
to fill that role in many instances).

-Alan

-- 
Help out our research and get a free 
personality profile:
http://www.web-data-collection.org



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

Date: Fri, 18 Feb 2005 21:26:19 +0100
From: "lyx" <ekeith@free.fr>
Subject: prob send and NET::SMTP
Message-Id: <42164f6b$0$12440$626a14ce@news.free.fr>

Hi
I need some help
i'm scripting in PERL on WinXP ( activeperl)
I try to do à little mailing script that takes email addresses in a txt file
and then send the same mail  one per one to each recipients
all is ok but if in the txt file one email is wrong (syntaxe ok but not 
existing)
the script dies
error output : "SMTP RCPT command failed: <azertazef@qsdfqsdf.dd>: Recipient 
address rejected: Domain not found"

and the next reciptients won't be emailed.

how could I test an email ( syntaxe test has been done) ?

here is an extract from the script

use MIME::Lite;
use Net::SMTP;
my $msg = MIME::Lite-> new (
            From    =>$exp,
            To      =>$dest,
            Subject =>$subj,
            Type    =>'multipart/mixed') ;
$msg -> attach (
            Type =>'text/HTML',
            Data =>$message_html)  ;
MIME::Lite->send('smtp',$my_smtp,Timeout=>60);
$msg->send;

thanks a lot for the futur help

Lyx




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

Date: Fri, 18 Feb 2005 20:13:58 +0100
From: "Tassilo v. Parseval" <tassilo.von.parseval@rwth-aachen.de>
Subject: Re: variation on 'calling subroutine via reference'?
Message-Id: <slrnd1cfjm.13a.tassilo.von.parseval@localhost.localdomain>

Also sprach Alison Bowes:

> I posted this on comp.lang.perl then ran across another post saying that 
> that newsgroup is "defunct" and posts should be made here instead.  Sorry if 
> you're seeing this twice!
>
> I know that if $subname contains the name of the subroutine I want to call, 
> I can call that subroutine via
>
> &$subname;
>
> However, my subroutine names are in an array, so if I want to call 
> $subname[3] I've tried
>
> &$subname[3];
>
> But, that doesn't work, and I'm not having much luck finding such an
> example.  If I'm doing something truly numbskulled, I do apologize!

You have to bear in mind that the &$REF syntax is really a short-cut.
An explicit dereference will put the reference into curlies:

    ${ $REF }
    %{ $REF }
    ...
    
> I do realize I could go this route:
> $this_sub = $subname[3];
> &$this_sub;
>
> But, that just seems so clunky and unnecessary, no?

It does. Adding curlies as mentioned above makes this intermediate step
unnecessary:

    &{ $subname[3] };

Tassilo
-- 
use bigint;
$n=71423350343770280161397026330337371139054411854220053437565440;
$m=-8,;;$_=$n&(0xff)<<$m,,$_>>=$m,,print+chr,,while(($m+=8)<=200);


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

Date: Fri, 18 Feb 2005 20:32:02 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: variation on 'calling subroutine via reference'?
Message-Id: <37mu3mF5dir64U1@individual.net>

Alison Bowes wrote:
> I know that if $subname contains the name of the subroutine I want to call, 
> I can call that subroutine via
> 
> &$subname;

Really? On my computer, this code:

     use strict;
     sub myfunction { print "Hello\n" }
     my $subname = 'myfunction';
     &$subname;

outputs:
Can't use string ("myfunction") as a subroutine ref while "strict refs" 
in use

But this works fine:

     my $subref = \&myfunction;
     &$subref;

> However, my subroutine names are in an array, so if I want to call 
> $subname[3] I've tried
> 
> &$subname[3];

If the fourth element contains a *code reference* to the subroutine, this:

     &{ $subname[3] };

or this:

     $subname[3]->();

should work.

Please study the posting guidelines for this group:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html

Among other useful things, they emphasize the importance of using strict 
and warnings when developing Perl code.

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


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

Date: Fri, 18 Feb 2005 20:09:42 +0100
From: "Tassilo v. Parseval" <tassilo.von.parseval@rwth-aachen.de>
Subject: Re: Why aren't 'warnings' on by default?
Message-Id: <slrnd1cfbm.13a.tassilo.von.parseval@localhost.localdomain>

Also sprach Anno Siegel:

> Tassilo v. Parseval <tassilo.von.parseval@rwth-aachen.de> wrote in comp.lang.perl.misc:

>> There is a problem with warnings on a larger scale, namely in the
>> context of published code, most notably modules. It's most annoying and
>> fairly useless to read things such as 
>> 
>>     Use of uninitialized value in string eq at
>>     /opt/perl5.8.6-db/lib/5.8.6/Foo/Bar/Baz.pm line 4242
>
> Okay, but that happens only with global -w, not with lexical "use warnings".

h2xs puts 'use warnings' into the created module skeleton. Those modules
will emit warnings even if -w or warnings are turned off in the program
using this module.

>> Does it mean there's a bug in the module,
>
> Yes.  See below.
>
>> or maybe in my program using
>> this module? Or maybe it's a potential bug that could occur under
>> certain rare circumstances. It could just as easily mean nothing of that
>> kind and only expose the module's author's sloppyness.
>
> If a module issues warnings the author didn't intend the user to see,
> that's a bug.  Most of the time it is trivially fixed.

Ah, but there the warning itself becomes the bug. The trivial fix would
be getting rid of 'use warnings' within the module. No warning, hence no
bug. ;-)

There is obviously something very contorted in this logic just outlined.
But it is the direct implication of your assertion that a warning
produced by a module is a bug.

> If the module author has "use warnings" early in each file as a matter of
> course, these problems are caught during development.  Unfortunately, h2xs
> issues a module template without warnings.  That may be a reason why the
> practice isn't more common.

I just checked it (again). h2xs puts them in, unless a version older
than 5.6 is specified using -b or --skip-warnings is mentioned
explicitly.

Interestingly enough, I just noticed that I preach things differently
from how I do them in the modules I have released. Most of my modules
have warnings on in fact. I even go through painful procedures to
temporarily switch them off in XS code where necessary and turning them
on again afterwards. Hmmh.

>> If warnings in module context really and rightly suggest there's a bug,
>> then the bug itself will sooner or later manifest in some other way,
>> wont it? Otherwise it wouldn't be one.
>
> What about silently delivering wrong results?

It's not at all clear to me how wrong results correlate with the amount
of warnings emitted. I will admit that the likelihood of warnings is
probably higher when a wrong result is being computed (and vice versa).
However, there will still be many cases where those two things will be
entirely uncorrelated. If anything, warnings from a module will give me
doubts about the quality of the module in question.

>> The point being that warnings
>> rarely provide information useful to people not in charge of the code.
>
> Really?  I'd understand "(not) useful to the people running the program",
> but as a developer I'm just as interested in warnings as I am in errors.

I see myself as a plain user when it comes to external modules and
libraries. It is true that in some cases I might lay hands on their code
but in most cases I will start looking for less noisy alternatives. It's
not always practical (let alone easy) to dive into other people's code
and fix things. 

Tassilo
-- 
use bigint;
$n=71423350343770280161397026330337371139054411854220053437565440;
$m=-8,;;$_=$n&(0xff)<<$m,,$_>>=$m,,print+chr,,while(($m+=8)<=200);


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

Date: Fri, 18 Feb 2005 20:22:21 +0100
From: phaylon <phaylon@dunkelheit.at>
Subject: Re: Why aren't 'warnings' on by default?
Message-Id: <pan.2005.02.18.19.22.21.722624@dunkelheit.at>

Tassilo v. Parseval wrote:

> Ah, but there the warning itself becomes the bug.

I think the bug is "letting the warning happen."

btw: This kind of discussion is one reason why I like this group :D

-- 
http://www.dunkelheit.at/

The first rule of project mayhem is: you do not ask questions.
                              -- Fight Club



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

Date: 19 Feb 2005 14:11:24 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Why aren't 'warnings' on by default?
Message-Id: <cv7hec$2dc$1@mamenchi.zrz.TU-Berlin.DE>

Tassilo v. Parseval <tassilo.von.parseval@rwth-aachen.de> wrote in comp.lang.perl.misc:
> Also sprach Anno Siegel:
> > Tassilo v. Parseval <tassilo.von.parseval@rwth-aachen.de> wrote in
> comp.lang.perl.misc:

[unplanned warnings from a module]

> >> Does it mean there's a bug in the module,
> >
> > Yes.  See below.
> >
> >> or maybe in my program using
> >> this module? Or maybe it's a potential bug that could occur under
> >> certain rare circumstances. It could just as easily mean nothing of that
> >> kind and only expose the module's author's sloppyness.
> >
> > If a module issues warnings the author didn't intend the user to see,
> > that's a bug.  Most of the time it is trivially fixed.
> 
> Ah, but there the warning itself becomes the bug. The trivial fix would
> be getting rid of 'use warnings' within the module. No warning, hence no
> bug. ;-)

Taking out "use warnings" doesn't fix the bug -- the user can make it
reappear through -w.  You need "no warnings ..." in the right scope.
That scope would rarely be the entire module, but rather the smallest
possible scope that does the job.  Or you change the logic so that
the warning doesn't happen in the first place.

> There is obviously something very contorted in this logic just outlined.
> But it is the direct implication of your assertion that a warning
> produced by a module is a bug.

It's less contorted when the fix is as outlined above.

> > If the module author has "use warnings" early in each file as a matter of
> > course, these problems are caught during development.  Unfortunately, h2xs
> > issues a module template without warnings.  That may be a reason why the
> > practice isn't more common.
> 
> I just checked it (again). h2xs puts them in, unless a version older
> than 5.6 is specified using -b or --skip-warnings is mentioned
> explicitly.

You are right.  Apparently it has done so since at least 5.6.1.  I don't
know what made me think otherwise.

[...]

> >> If warnings in module context really and rightly suggest there's a bug,
> >> then the bug itself will sooner or later manifest in some other way,
> >> wont it? Otherwise it wouldn't be one.
> >
> > What about silently delivering wrong results?
> 
> It's not at all clear to me how wrong results correlate with the amount
> of warnings emitted. I will admit that the likelihood of warnings is
> probably higher when a wrong result is being computed (and vice versa).
> However, there will still be many cases where those two things will be
> entirely uncorrelated. If anything, warnings from a module will give me
> doubts about the quality of the module in question.

The warning indicates a case the author hasn't thought of and hasn't
tested.  If the results are correct in such cases that's coincidence.

> >> The point being that warnings
> >> rarely provide information useful to people not in charge of the code.
                                                 ^^^
> >
> > Really?  I'd understand "(not) useful to the people running the program",
> > but as a developer I'm just as interested in warnings as I am in errors.
> 
> I see myself as a plain user when it comes to external modules and...

Sorry.  I consistently overlooked a "not" in your sentence.  My objection
makes no sense.

Anno


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

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


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