[24471] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6654 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Jun 5 00:06:12 2004

Date: Fri, 4 Jun 2004 21:05:05 -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           Fri, 4 Jun 2004     Volume: 10 Number: 6654

Today's topics:
    Re: a windows registry monitor <lv@aol.com>
        Advice: hiding sensitive info used in devel <socyl@987jk.com>
    Re: Advice: hiding sensitive info used in devel <usenet@morrow.me.uk>
    Re: Advice: hiding sensitive info used in devel <nospam@bigpond.com>
    Re: Can one set perlvars on command line? <gnari@simnet.is>
    Re: Can one set perlvars on command line? (Malcolm Dew-Jones)
    Re: Can one set perlvars on command line? <usenet@morrow.me.uk>
    Re: Delete a line out of a flat file database (Kevin Collins)
    Re: Delete a line out of a flat file database <ittyspam@yahoo.com>
    Re: Delete a line out of a flat file database (Jim Gibson)
    Re: Delete a line out of a flat file database (Kevin Collins)
        How to get Win32 mouse pointer style (Tom)
        HTML::ParseTree delete/modify child text <rbell01824@earthlink.net>
    Re: LWP::UserAgent problem - 500 error <matthew.garrish@sympatico.ca>
    Re: perl style and returning from function? <uri.guttman@fmr.com>
    Re: perl style and returning from function? <ittyspam@Yahoo.com>
    Re: perl style and returning from function? (Anno Siegel)
    Re: perl style and returning from function? <uri@stemsystems.com>
        Using LWP to get last modified date of web page <apollock11@hotmail.com>
    Re: why can't I hang a "shift" on the front of this sta (Anno Siegel)
    Re: Why is this upload script not working <krahnj@acm.org>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 04 Jun 2004 21:50:08 -0500
From: l v <lv@aol.com>
Subject: Re: a windows registry monitor
Message-Id: <40c1354b_5@corp.newsgroups.com>

justme wrote:
> hi
> 
> i am trying to code a small perl program to monitor the windows
> registry. The idea is to create a baseline on some keys like
> LOCAL_MACHINE or USERS, ( the whole registry would be too big ), where
> the RUN and RUNONCE keys are located.
> Then i would poll these registry locations and see if there are
> suspicious keys added by comparing it against the baseline. The script
> will be scheduled to check every once in a while. I have checked CPAN
> for Win32::Registry. I wonder if it is the right tool to help me in
> this purpose...?
> thanks

Although I have not used it, Win32::TieRegistry may be a better module 
to use as the tied hashes might prove to be a good method to compare 
against your baseline.

Len


-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 100,000 Newsgroups - 19 Different Servers! =-----


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

Date: Sat, 5 Jun 2004 01:01:54 +0000 (UTC)
From: kj <socyl@987jk.com>
Subject: Advice: hiding sensitive info used in devel
Message-Id: <c9r622$sbt$1@reader2.panix.com>




I'm writing a library that is supposed to be customized with
potentially sensitive info (passwords, etc.).  All these variables
are defined in a file MyModule/Config.pm:

  package MyModule::Config;

  our %Config = (
    user     => 'yours_truly',
    password => 'topsecret',
  # etc., etc.
  );

During development, my working copy of MyModule/Config.pm holds
real values for various variables, which obviously I don't want to
publicize.  This means that, in order to build the distribution
package for release, one of the things I must do is change all the
values of these variables.  Conversely, if I want to test a released
version of our software, as stored in our CVS repository, I first
must change the values of these variables back to those that make
sense for our system.  There is always a mismatch between what we
release and what we use locally , and at least one of these must
necessarily be different from what is stored in our CVS repository.
Hence, there's a major conflict between the desire to make our CVS
repository world-accessible, and the the developers' wish to be
able to commit to the repository files that have sensitive information.

Some possible ways to solve or mitigate this problem (e.g.
/usr/bin/make) have nothing to do with Perl, but I was wondering
if there are Perl techniques to architect such software that would
facilitate implementing a solution to this problem.

Thank you very much for your thoughts,

kj
-- 
NOTE: In my address everything before the period is backwards.


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

Date: Sat, 5 Jun 2004 01:22:55 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Advice: hiding sensitive info used in devel
Message-Id: <c9r79f$41k$1@wisteria.csv.warwick.ac.uk>


Quoth kj <socyl@987jk.com>:
> 
> I'm writing a library that is supposed to be customized with
> potentially sensitive info (passwords, etc.).  All these variables
> are defined in a file MyModule/Config.pm:
> 
>   package MyModule::Config;
> 
>   our %Config = (
>     user     => 'yours_truly',
>     password => 'topsecret',
>   # etc., etc.
>   );
> 
> During development, my working copy of MyModule/Config.pm holds
> real values for various variables, which obviously I don't want to
> publicize.

> Hence, there's a major conflict between the desire to make our CVS
> repository world-accessible, and the the developers' wish to be
> able to commit to the repository files that have sensitive information.

You could perhaps always keep the fake data in your dev tree (and in
CVS), and then have a separate directory /path/to/private with a
different MyModule/Config.pm in containing sensitive data. If you add
this /path/to/private to $PERL5LIB in your working environment, perl
will find and use the real data while you are testing, but the real data
never comes near the dev tree so definitely won't get shipped or checked
into CVS.

Ben

-- 
  Joy and Woe are woven fine,
  A Clothing for the Soul divine       William Blake
  Under every grief and pine          'Auguries of Innocence'
  Runs a joy with silken twine.                                ben@morrow.me.uk


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

Date: Sat, 05 Jun 2004 11:57:45 +1000
From: Gregory Toomey <nospam@bigpond.com>
Subject: Re: Advice: hiding sensitive info used in devel
Message-Id: <1781586.AIF8NXZM83@GMT-hosting-and-pickle-farming>

kj wrote:

> 
> I'm writing a library that is supposed to be customized with
> potentially sensitive info (passwords, etc.).

Maybe try a symmetric encryption algorithm eg DES
This will at least hide the values to a casual observer.

gtoomey


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

Date: Fri, 4 Jun 2004 18:37:04 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: Can one set perlvars on command line?
Message-Id: <c9qfd3$2m2$1@news.simnet.is>

"J Krugman" <jkrugman345@yahbitoo.com> wrote in message
news:c9qd18$jcs$1@reader2.panix.com...
>
> Is there any trick to set a Perl variable (or any global variable,
> for that matter) on the command line, as in, for example:
>
>   % perl {{{set $| to 1}}} somescript.pl --opt --flag arg
>
> so that myscript.pl started out with $| having value 1?

is it cheating to use
    perl -Mcheat somescript.pl --opt --flag arg
where you have put cheat.pm somewhere in @INC ?

use of -Mmodule=arg,arg might help do this in a
general way:
    perl -Msetvar=OUTPUT_AUTOFLUSH,1 somescript.pl


what about (untested):
    perl -e'$|=1;require "somescript.pl"' --opt --flag arg


gnari






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

Date: 4 Jun 2004 12:05:38 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: Can one set perlvars on command line?
Message-Id: <40c0c802@news.victoria.tc.ca>

J Krugman (jkrugman345@yahbitoo.com) wrote:


: Is there any trick to set a Perl variable (or any global variable,
: for that matter) on the command line, as in, for example:

:   % perl {{{set $| to 1}}} somescript.pl --opt --flag arg

: so that myscript.pl started out with $| having value 1?


put your defaults in a .pm file (e.g. mystuff.pm) in the @INC path, and 
then try

	perl -Mmystuff

(I've never -M used for this, but can't see why it wouldn't work).

Certain command line switches (e.g. -0 ) work for a few variables.



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

Date: Fri, 4 Jun 2004 19:45:24 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Can one set perlvars on command line?
Message-Id: <c9qjgk$jmh$1@wisteria.csv.warwick.ac.uk>


Quoth J Krugman <jkrugman345@yahbitoo.com>:
> 
> Is there any trick to set a Perl variable (or any global variable,
> for that matter) on the command line, as in, for example:
> 
>   % perl {{{set $| to 1}}} somescript.pl --opt --flag arg
> 
> so that myscript.pl started out with $| having value 1?

perl -e'$| = 1; do shift' somescript.pl --opt --flag arg
perl -Mvars::i='$|,1' somescript.pl --opt --flag arg

(These both assume sh-like shells: with other shells you may have a much harder
time.)

Get vars::i from CPAN.

Ben

-- 
  Joy and Woe are woven fine,
  A Clothing for the Soul divine       William Blake
  Under every grief and pine          'Auguries of Innocence'
  Runs a joy with silken twine.                                ben@morrow.me.uk


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

Date: Fri, 04 Jun 2004 18:38:34 GMT
From: spamtotrash@toomuchfiction.com (Kevin Collins)
Subject: Re: Delete a line out of a flat file database
Message-Id: <slrncc1gd9.o3l.spamtotrash@doom.unix-guy.com>

In article <c9q3p1$9cb$1@wisteria.csv.warwick.ac.uk>, Ben Morrow wrote:
> 
> Quoth constants@mix-net.net (Mark Constant):
>> I have pre-made code that deletes a line from a flat file database. I
>> am trying to pass an argument through a link to give the name of the
>> line to delete.
>> 
>> Here is my database.txt 
>> image020.jpg | 6/4/2004 | 10:19:59 |  | rena
>> 
>> Here is how I use the link 
>> delete.cgi?filedelete=$filename
>> 
>> Now here is what prints out
>> image020.jpg
>> File image020.jpg not found!
>> 
>> It is obvious that it is grabbing the argument because it prints out
>> image020.jpg. The thing I don't understand is why it is not matching
>> with the image020.jpg in the database.txt.
>> 
>> Here is my code
>> #!c:/perl/bin/perl
>> 
>> use strict;
>> use warnings;
>> use CGI;
>> use CGI::Carp qw(fatalsToBrowser);
>> my $q = new CGI;
>> print $q->header, $q->start_html('Delete File');
>> 
>> my $action = new CGI;
>> my @temp=split(/=/,$ENV{'QUERY_STRING'});
> 
> DON'T EVER DO THIS AGAIN. Use CGI.
> 
>> my $filedelete = $temp[1];
> 
> my $filedelete = $action->param('filedelete');
> 
>> my $file = 'C:/Program Files/Apache
>> Group/Apache2/htdocs/quickbooks/database.txt';
>> my $found = undef;
> 
> my $found;
> 
>> my (@ary);
> 
> my @ary;
> 
>> my $line;
>> 
>> open( OLD, $file ) or die "Couldn't open old file $file: $! \n";
> 
> Don't put "\n" on the end of die messages.

Why not? It isn't needed and I never do, but there isn't any reason not to.
Better would be to explain why it not needed than just "don't do this". In
fact, from my 5.8.0's 'perldoc -f die':

              Equivalent examples:

                  die "Can't cd to spool: $!\n" unless chdir '/usr/spool/news';
                  chdir '/usr/spool/news' or die "Can't cd to spool: $!\n"

> Use lexical filehandles.
> Specify the mode to open the file in, for safety.

In this case, I don't think it is necessary. The file name is known and
"normal". For dealing with unkowns, I would agree. According to the faq for
open:

              Use 3-argument form to open a file with arbitrary weird
              characters in it,

                  open(FOO, '<', $file);

> open my $OLD, '<', $file
>     or die "can't open $file: $!";
> 
>> print $temp[1];
>> foreach $line (@ary) {
> 
> for my $line (@ary) {
> 
> Create variables in the smallest possible scope.
> 
>> 	chomp($line);
>> 	(my $filename, my $filedate, my $filetime, my $notes, my $user) =
> 
> my ($filename, $filedate, $filetime, $notes, $user) =
> 
> But anyway, why do you need more than
> 
> my ($filename) = 
> 
> ?
> 
>> split(/\|/,$line);
> 
> You are splitting on /\|/. This will leave whitespace all round your
> filename. Try
> 
> ... = split /\s* \| \s*/x, $line;
> 
>> 	push( @ary, $line ) unless ( $filedelete eq $filename );
>> 	$found = 1 if ( $filedelete eq $filename );
> 
> None of those parens are necessary.

But they do add clarity and help make precedence more obvious.

> 
>> }
>> 
>> close OLD or die "Couldn't close old file $file: $! \n";
>> 
>> unless ($found) {
>> 	print $action->h2("File $filedelete not found!");
>> 	exit;
> 
> No. This will not correctly end the HTML.
> 
>> }
>> 
>> open( NEW, ">$file" ) or die "Couldn't open new file $file: $!\n";
>> foreach (@ary) {
>> 	print NEW $_, "\n" 
>> }
>> 
>> close NEW or "Couldn't close new file $file: $! \n";;
>> 
>> exit;
> 
> Nor will this.
> 
> if ($found) {
>     open my $NEW, '>', $file or die "couldn't create $file: $!";
>     print $NEW "$_\n" for @ary;
> }
> else {
>     print $action->h2("File $filedelete not found!");
> }
> 
>> print $q->end_html;
> 
> You *must* use locking in a situation like this, or you will end up with
> a corrupted database. Something like:
> 
> use Fcntl qw/:flock/;
> 
> {
>     open my $OLD, '<', ...;
>     flock $OLD, LOCK_SH or die "can't acquire read lock: $!";
>     # read stuff
> }
> # $OLD closes here, lock is released
> 
> if ($found) {
>     open my $NEW, '>', ...;
>     flock $NEW, LOCK_EX or die "can't acquire write lock: $!";
>     # write stuff
> }
> # ditto for $NEW
> 
> Alternatively, you could open the file '+<' and then lock it LOCK_EX,
> and truncate it rather than closing/reopening.
> 
> Ben
> 


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

Date: Fri, 4 Jun 2004 14:53:19 -0400
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: Delete a line out of a flat file database
Message-Id: <20040604145002.C8971@dishwasher.cs.rpi.edu>

On Fri, 4 Jun 2004, Kevin Collins wrote:
>
> In article <c9q3p1$9cb$1@wisteria.csv.warwick.ac.uk>, Ben Morrow wrote:
<snip>
> > Don't put "\n" on the end of die messages.
>
> Why not? It isn't needed and I never do, but there isn't any reason not to.
> Better would be to explain why it not needed than just "don't do this". In
> fact, from my 5.8.0's 'perldoc -f die':
>
>               Equivalent examples:
>
>                   die "Can't cd to spool: $!\n" unless chdir '/usr/spool/news';
>                   chdir '/usr/spool/news' or die "Can't cd to spool: $!\n"
>

Because putting "\n" suppresses useful information.  Without a "\n", the
die function will output not only its argument string, but also the file
and line number on which the die occurred.  Adding the "\n" in there makes
you lose this information.

<snip>
> >> 	push( @ary, $line ) unless ( $filedelete eq $filename );
> >> 	$found = 1 if ( $filedelete eq $filename );
> >
> > None of those parens are necessary.
>
> But they do add clarity

That's debatable.

> and help make precedence more obvious.

"Learn the language". :-)


Paul Lalli


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

Date: 4 Jun 2004 11:59:42 -0700
From: jgibson@mail.arc.nasa.gov (Jim Gibson)
Subject: Re: Delete a line out of a flat file database
Message-Id: <46f036d0.0406041059.6fd62e6b@posting.google.com>

constants@mix-net.net (Mark Constant) wrote in message news:<ce43fdea.0406040650.61f36da@posting.google.com>...
> I have pre-made code that deletes a line from a flat file database. I
> am trying to pass an argument through a link to give the name of the
> line to delete.
> 
> Here is my database.txt 
> image020.jpg | 6/4/2004 | 10:19:59 |  | rena
> 
> Here is how I use the link 
> delete.cgi?filedelete=$filename
> 
> Now here is what prints out
> image020.jpg
> File image020.jpg not found!
> 
> It is obvious that it is grabbing the argument because it prints out
> image020.jpg. The thing I don't understand is why it is not matching
> with the image020.jpg in the database.txt.
> 
> Here is my code
> #!c:/perl/bin/perl
> 

[variable initialzation snipped]

> 
> open( OLD, $file ) or die "Couldn't open old file $file: $! \n";
> print $temp[1];

The array @ary is empty. I think you are missing a line such as my @ary = <OLD>;

> foreach $line (@ary) {
> 	chomp($line);
> 	(my $filename, my $filedate, my $filetime, my $notes, my $user) =
> split(/\|/,$line);
> 	push( @ary, $line ) unless ( $filedelete eq $filename );
> 	$found = 1 if ( $filedelete eq $filename );
> }
> 
> close OLD or die "Couldn't close old file $file: $! \n";
> 
[rest of program snipped]

--
Jim Gibson


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

Date: Fri, 04 Jun 2004 21:14:08 GMT
From: spamtotrash@toomuchfiction.com (Kevin Collins)
Subject: Re: Delete a line out of a flat file database
Message-Id: <slrncc1pgv.o3l.spamtotrash@doom.unix-guy.com>

In article <20040604145002.C8971@dishwasher.cs.rpi.edu>, Paul Lalli wrote:
> On Fri, 4 Jun 2004, Kevin Collins wrote:
>>
>> In article <c9q3p1$9cb$1@wisteria.csv.warwick.ac.uk>, Ben Morrow wrote:
><snip>
>> > Don't put "\n" on the end of die messages.
>>
>> Why not? It isn't needed and I never do, but there isn't any reason not to.
>> Better would be to explain why it not needed than just "don't do this". In
>> fact, from my 5.8.0's 'perldoc -f die':
>>
>>               Equivalent examples:
>>
>>                   die "Can't cd to spool: $!\n" unless chdir '/usr/spool/news';
>>                   chdir '/usr/spool/news' or die "Can't cd to spool: $!\n"
>>
> 
> Because putting "\n" suppresses useful information.  Without a "\n", the
> die function will output not only its argument string, but also the file
> and line number on which the die occurred.  Adding the "\n" in there makes
> you lose this information.
> 
><snip>
>> >> 	push( @ary, $line ) unless ( $filedelete eq $filename );
>> >> 	$found = 1 if ( $filedelete eq $filename );
>> >
>> > None of those parens are necessary.
>>
>> But they do add clarity
> 
> That's debatable.

If you use parens, there can be no ambiguity...

>> and help make precedence more obvious.
> 
> "Learn the language". :-)

Well, then why bother with indenting, white-space, comments, etc? If you "know
the language", why use any of those constructs - they are mostly not required?

Kevin


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

Date: 4 Jun 2004 12:13:23 -0700
From: ziggy.971485@bloglines.com (Tom)
Subject: How to get Win32 mouse pointer style
Message-Id: <5b3d1dd2.0406041113.77805690@posting.google.com>

Does anyone know how to query the mouse pointer style (hourglass,
pointer, hand, etc) from a perl program on Win32?  I assume there's a
Win32 API function for this, but I can't find it.

Thanks,

Tom


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

Date: Fri, 04 Jun 2004 21:13:34 GMT
From: Richard Bell <rbell01824@earthlink.net>
Subject: HTML::ParseTree delete/modify child text
Message-Id: <2C5wc.8980$%F2.4368@attbi_s04>

Given an HTML::ParseTree node $n.  Given its content as returned by my 
@content = $n->content_list().  @content potentially consists of text or 
references to other nodes.  Regarding those elements of @content 
containing text:

How does one modify the content of a specific text child within the 
containing node?

How does one delete a specific text child within the containing node?

Consider the HTML fragment:

<div> String 1 <h3> String 2 </h3> String 3 <h3> String 4 </h3> String 5 
</div>

$n->content_list would contain ( 'String 1', ref to <h3> containing 
String 2, 'String 3', ref to <h3> containing String 4, 'String 5' )

I can delete the child nodes with $ref->delete.  But how do I mess with 
the strings?

Thanks.


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

Date: Fri, 4 Jun 2004 19:42:52 -0400
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: LWP::UserAgent problem - 500 error
Message-Id: <ZN7wc.132044$tb4.4773789@news20.bellglobal.com>


"RP" <izco@hotmail.com> wrote in message
news:9e7779b4.0406040624.47712f5f@posting.google.com...
> "Matt Garrish" <matthew.garrish@sympatico.ca> wrote in message
news:<4Mkvc.22195$Hn.798871@news20.bellglobal.com>...
> >
> > I get the yahoo page when I run it. Your host has either configured
their
> > server not to allow any outbound requests, or as I said in my previous
post,
> > they have a proxy you should be going through. No one here can help you
with
> > that, though. If you have a problem running your script once you have
the
> > details of how to connect out, you can always try back then.
> >
>
> Is it normal for a web host to be configured that way?  I've been
> considering switching hosts anyway, and this might be the last straw.
> I don't want to switch and then have this problem with my new host -
> it's a question I have to ask before I find hosting...  Thanks for all
> your help!

I couldn't say whether it is normal or not, as the majority of web work I do
is at work, where I can do pretty much anything I want... : )

Certainly something you might want to ask of a new host before laying your
money down.

Matt




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

Date: Fri, 04 Jun 2004 14:10:39 -0400
From: Uri Guttman <uri.guttman@fmr.com>
Subject: Re: perl style and returning from function?
Message-Id: <lik6yn2nz4.fsf@fmr.com>

>>>>> "AQ" == Ala Qumsieh <notvalid@email.com> writes:

  AQ> Uri Guttman wrote:
  >>>>>>> "BM" == Ben Morrow <usenet@morrow.me.uk> writes:

  BM> return $rc == 1 ? 1 : 0;
  >> why not just return $rc == 1? the OP didn't specify what the false
  >> value
  >> must be.

  AQ> In this case,

  AQ> 	return $rc;

  AQ> should suffice.

not necessarily. if $rc is 2 he still wants to return 1. the real
question is can he directly return the value $rc == 1? or must the false
value be 0 and not ''?

uri


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

Date: Fri, 4 Jun 2004 16:40:17 -0400
From: Paul Lalli <ittyspam@Yahoo.com>
Subject: Re: perl style and returning from function?
Message-Id: <20040604163907.W8971@dishwasher.cs.rpi.edu>

On Fri, 4 Jun 2004, Uri Guttman wrote:

> >>>>> "AQ" == Ala Qumsieh <notvalid@email.com> writes:
>
>   AQ> Uri Guttman wrote:
>   >>>>>>> "BM" == Ben Morrow <usenet@morrow.me.uk> writes:
>
>   BM> return $rc == 1 ? 1 : 0;
>   >> why not just return $rc == 1? the OP didn't specify what the false
>   >> value
>   >> must be.
>
>   AQ> In this case,
>
>   AQ> 	return $rc;
>
>   AQ> should suffice.
>
> not necessarily. if $rc is 2 he still wants to return 1. the real
> question is can he directly return the value $rc == 1? or must the false
> value be 0 and not ''?


The original code was
> > > return ($rc and $rc == 1) ? 1 : 0;

That implies that if $rc is 2, he wants to return 0, doesn't it?

Paul Lalli


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

Date: 4 Jun 2004 21:30:22 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: perl style and returning from function?
Message-Id: <c9qple$qv8$1@mamenchi.zrz.TU-Berlin.DE>

Ben Morrow  <usenet@morrow.me.uk> wrote in comp.lang.perl.misc:
> 
> Quoth wherrera@lynxview.com (Bill):
> > What do you think is better:
> > 
> > ...
> >     return ($rc and $rc == 1) ? 1 : 0;
> > }
> > 
> > or
> > 
> >     $rc and $rc == 1 and return 1;
> >     return 0;
> > }
> 
> return $rc == 1 ? 1 : 0;
> 
> Perl is not C. A value of undef will quite happily be != 0.

It will issue a warning.  "$rc and $rc == 1" is sound, but I'd just
return that.  It's a legitimate boolean value, after all.

> A better answer altogether might be
> 
> $rc == 1 and return 1;
> return;
> 
> which will always return false, even if called in list context.

I'm not sure about this rule in this case.  When a function is described
as returning a boolean value, it should return one, imho.  I'd like
"map boolfunc( $_), @list" to return as many "true"s and "false"s as
@list has elements, not an indefinite number of all "true"s.

The rule is well applied where the blank return indicates failure to
deliver the normal result, but not when a result is expected in any case.

Anno


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

Date: Sat, 05 Jun 2004 01:33:12 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: perl style and returning from function?
Message-Id: <x74qpqokko.fsf@mail.sysarch.com>

>>>>> "PL" == Paul Lalli <ittyspam@Yahoo.com> writes:

  PL> On Fri, 4 Jun 2004, Uri Guttman wrote:
  >> >>>>> "AQ" == Ala Qumsieh <notvalid@email.com> writes:
  >> 
  AQ> Uri Guttman wrote:
  >> >>>>>>> "BM" == Ben Morrow <usenet@morrow.me.uk> writes:
  >> 
  BM> return $rc == 1 ? 1 : 0;
  >> >> why not just return $rc == 1? the OP didn't specify what the false
  >> >> value
  >> >> must be.
  >> 
  AQ> In this case,
  >> 
  AQ> return $rc;
  >> 
  AQ> should suffice.
  >> 
  >> not necessarily. if $rc is 2 he still wants to return 1. the real
  >> question is can he directly return the value $rc == 1? or must the false
  >> value be 0 and not ''?


  PL> The original code was
  >> > > return ($rc and $rc == 1) ? 1 : 0;

  PL> That implies that if $rc is 2, he wants to return 0, doesn't it?

yes, but i would like a proper spec from the OP. assuming $rc is defined
then just return $rc == 1 is enough (and also assuming $rc is a number).

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: Fri, 04 Jun 2004 15:51:49 -0700
From: Arvin Portlock <apollock11@hotmail.com>
Subject: Using LWP to get last modified date of web page
Message-Id: <c9que8$t7n$1@agate.berkeley.edu>

I write the following program which works great:

use LWP::UserAgent;
my $agent = new LWP::UserAgent;
my $response = $agent->head('http://www.perl.org/about.html');
print $response->last_modified;

But most other URLs I try don't return a modified date.
Is this because most servers aren't accepting HEAD requests
anymore? There has to be a way to get the last modifed date
for a web page. We have crawlers and spiders that do it all
the time. Can anybody suggest a way to do this? I'm partic-
ularly concerned about not downloading entire pages but just
getting the sizes and I'm not sure how to do this with LWP.

Thanks for your help



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

Date: 4 Jun 2004 21:07:27 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: why can't I hang a "shift" on the front of this statement
Message-Id: <c9qoaf$pia$1@mamenchi.zrz.TU-Berlin.DE>

Paul Lalli  <ittyspam@yahoo.com> wrote in comp.lang.perl.misc:
> On Fri, 4 Jun 2004, Sara wrote:
> 
> > Perl is unhappy with this line:
> >
> >     shift my @id = split /ID\s+([^\n]+)\n/, $$_;

[...]

> (shift my @id) = split /ID\s+([^\n]+)\n/, $$_;
> whereas what you want is
> shift (my @id = split /ID\s+([^\n]+)\n/, $$_;)
> 
> HOWEVER, this will not work either.  Because now you're not giving shift
> an array, you're giving it a list assignment.  The first argument to shift
> must be a named array.  This is why the corresponding syntax for chomp
> would work, but shift does not.  (perldoc -f chomp shows that it takes a
> LIST, whereas shift takes an ARRAY).
> 
> I'm not especially sure you'll find any combination of parentheses that
> will do what you want in one line.

If the purpose is to isolate the first element, this would do

    my ( $first, @id) = split ...;

To ignore it, replace "$first" with "undef".

Anno


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

Date: Sat, 05 Jun 2004 00:38:41 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Why is this upload script not working
Message-Id: <40C11602.14FF20F1@acm.org>

Gunnar Hjalmarsson wrote:
> 
> Ben Morrow wrote:
> >
> > Quoth constants@mix-net.net (Mark Constant):
> >>
> >> my $q = new CGI;
> >> my $fh = $q->upload('upfile');
> >> $q->uploadInfo($fh)->{'Content-Disposition'} =~
> >>  /filename=".*?([-\w. ]+)"/;
> >> my $name = $1 or die "Couldn't grab filename $!";
> >
> > DON'T USE $1 UNLESS YOU KNOW THE MATCH SUCCEEDED.
> 
> Why are you shouting? ;-) Since I'm guilty of that detail, I must say
> that I don't understand the objection, Ben. If the match fails, $1
> will be undef and the program will die, so what's the problem?

Or $name could be equal to '0' and the program would die as well.


John
-- 
use Perl;
program
fulfillment


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

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


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