[16245] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3657 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jul 13 18:15:54 2000

Date: Thu, 13 Jul 2000 15:15:33 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <963526533-v9-i3657@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 13 Jul 2000     Volume: 9 Number: 3657

Today's topics:
        Newbie question: file existence (Alan Page)
    Re: Newbie question: file existence <care227@attglobal.net>
    Re: parsing CSV file <nswerdlo@bluemartini.com>
        perl -lpi.bak -e "s/old/new/g" *.* broken on NT? atramos_us@my-deja.com
    Re: perl beautifier? <DNess@Home.Com>
    Re: perl beautifier? (Mads Orbesen Troest)
        Perl CGI and browser timeout <jsmoriss@jsm-mv.dyndns.org>
    Re: perl-5.6.0: Bug with "not" operator? ()
        Prepared statement SQL brainmuffin@excite.com
    Re: PRINTing " "" " <uri@sysarch.com>
        programing perl third edition <sumengen@hotelspectra.com>
    Re: programing perl third edition <rc@telus.net>
    Re: programing perl third edition <sumengen@hotelspectra.com>
        Random number between 1 and x <raphaelp@nr1webresource.com>
    Re: Random number between 1 and x (Craig Berry)
    Re: Random number between 1 and x <raphaelp@nr1webresource.com>
    Re: Random number between 1 and x <raphaelp@nr1webresource.com>
    Re: Random number between 1 and x <marc.schaefer@warwick.ac.uk>
    Re: Random number between 1 and x (Craig Berry)
    Re: reg expression not working. WHY??? <lr@hpl.hp.com>
    Re: reg expression not working. WHY??? <care227@attglobal.net>
        Request for Reaming (Will England)
    Re: searching multiple sites (Clinton A. Pierce)
    Re: Shortcut for non-defined variables (Tad McClellan)
    Re: Shortcut for non-defined variables (Craig Berry)
    Re: Shortcut for non-defined variables <lr@hpl.hp.com>
    Re: Shortcut for non-defined variables <mjcarman@home.com>
    Re: Shorten this code, can u ? (Craig Berry)
    Re: Shorten this code, can u ? <bart.lateur@skynet.be>
    Re: Shorten this code, can u ? <bart.lateur@skynet.be>
    Re: Shorten this code, can u ? <marc.schaefer@warwick.ac.uk>
    Re: Shorten this code, can u ? <marc.schaefer@warwick.ac.uk>
    Re: String length? <o1technospam@skyenet.nospam.net>
    Re: Symbolic References for Form parsing? <tony@pyxis.blackstar.co.uk>
        Using ASP objects with Perl modules <samara_biz@hotmail.com>
        Using variables in regexps nelsonmuntz4925@my-deja.com
    Re: Using variables in regexps (Mads Orbesen Troest)
    Re: Using variables in regexps <godzilla@stomp.stomp.tokyo>
    Re: Using variables in regexps (Cameron Kennedy)
    Re: Using variables in regexps <tina@streetmail.com>
    Re: Using variables in regexps (Tad McClellan)
    Re: Using variables in regexps <marc.schaefer@warwick.ac.uk>
        w32 module <sergios@vitesse.com>
        Windmail/NT CGI script not sending mail <dwoods@ucalgary.ca>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: 13 Jul 2000 18:23:27 GMT
From: alandpage@aol.comnospam (Alan Page)
Subject: Newbie question: file existence
Message-Id: <20000713142327.29965.00000075@ng-md1.aol.com>

Hello,

I know just enough about Perl to be dangerous (bought the llama book, hacked a
few scripts for my sites, and attempted to read the online documentation at
perl.org and cpan.org), and therefore am completely stumped by a simple syntax
problem.

I am trying to check for the existence of a file in my directory structure, and
then redirect a WWW visitor to that file. I'm getting an error about premature
end of script headers, even though I'm not using headers. Here's the code:

$mydir   = "sf/pages/";
$failurl  = "/sf/nophoto.htm";
$batch = $input{'batch'};
$photo  = $input{'photo'};
$page  = "/" . $mydir . $batch . $photo  . ".htm";

#The offending line is next; the conditional if always returns false
if (-e $page) {
  print qq|Location: $page|;
} else {
  print qq|Location: $failurl|;
}

exit(0);

Any help would be most appreciated!
Alan


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

Date: Thu, 13 Jul 2000 14:27:36 -0400
From: Drew Simonis <care227@attglobal.net>
Subject: Re: Newbie question: file existence
Message-Id: <396E0A18.844BF35@attglobal.net>

Alan Page wrote:
> 
> Any help would be most appreciated!
> Alan

responded via e-mail as answer would have been off topic.


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

Date: Thu, 13 Jul 2000 14:00:14 -0700
From: Nick Swerdlow <nswerdlo@bluemartini.com>
Subject: Re: parsing CSV file
Message-Id: <396E2DDE.6C13901A@rocketmail.com>

Thanks to all that have replied to my previous post. I used the
Text::ParseWords module. I appreciate all of your responses. Thank you.
-N.

Nickolay wrote:

> Hello all,
>
> I am trying to parse a CSV file on a line by line basis.
> In otherwords I want to parse a line, where each field is separated with
> a
> comma. I want to store all these fields in an array.
>
> Unfortunatelly splitting the line simply by commas does not work
> since some of the field values themselves contain commas.
>
> I am new to Perl so please bear with me.
>
> Does anyone have a good reg expression that they've already come up with
>
> for this sort of parsing?
>
> Thanks for your time.
>
> -N.



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

Date: Thu, 13 Jul 2000 20:30:01 GMT
From: atramos_us@my-deja.com
Subject: perl -lpi.bak -e "s/old/new/g" *.* broken on NT?
Message-Id: <8kl8rh$r6$1@nnrp1.deja.com>



My fovorite Perl one-liner (multi-file global search/replace)
fails on NT with an "Invalid Argument" error.

Is there something I need to reconfigure?


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Thu, 13 Jul 2000 19:09:52 GMT
From: David Ness <DNess@Home.Com>
Subject: Re: perl beautifier?
Message-Id: <396E1401.460F795E@Home.Com>

"Randal L. Schwartz" wrote:
> 
 ... [snip of my question about perl beautifiers]
> 
> Doesn't the FAQ say something like "Perl resists all attempts to be
> beautified..."?
> 
> If not, it should. :)
> 
> Having said that, I don't know of any standalone program, but Emacs
> has cperl-mode (written by the illustrious Ilya, author of most of the
> Perl regex code and much of the Perl debugger) that seems to do a
> decent job of indenting.
> 

Thanks for the quick response. I suppose `beautification' is one place where
the wonderful flexibility of perl makes things tough, not only technically
but because it allows such a wide range of styles to flourish.

I guess the reason for asking was that I sometimes learn useful things from the
way others look at them, and seeing my own code as someone else might see it
would sometimes teach me new things.

I'll track down your suggestions.


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

Date: Thu, 13 Jul 2000 19:45:37 GMT
From: mads@troest.NEVERMORE.dk (Mads Orbesen Troest)
Subject: Re: perl beautifier?
Message-Id: <k6fk2tedC4v7-pn2-CXv7CCO2vyuu@mads.lokal.net>

On Thu, 13 Jul 2000 17:02:33, David Ness <DNess@Home.Com> wrote:

>  `perl beautifiers',

Now, there's a contradiction in terms... ;-)

      ... /\/\\ads Orbesen Troest <mads@troest.NEVERMORE.dk>

(Please remove NEVERMORE from address when replying via email...)


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

Date: Thu, 13 Jul 2000 20:32:19 GMT
From: Jean-Sebastien Morisset <jsmoriss@jsm-mv.dyndns.org>
Subject: Perl CGI and browser timeout
Message-Id: <8kl90j$to$1@nnrp1.deja.com>

I've written a CGI perl script which does a system call to run an
executable. While this is running, the browser can time-out waiting for
the CGI to update the screen. Can anyone suggest a way to prevent this?

Thanks,
js.
--
Jean-Sebastien Morisset, Sr. UNIX Administrator
<http://www.jsmoriss.dyndns.org/>;
UNIX, the Internet, Homebrewing, Cigars, PCS, and other Fun Stuff...


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Thu, 13 Jul 2000 18:10:37 GMT
From: mike@excite.com ()
Subject: Re: perl-5.6.0: Bug with "not" operator?
Message-Id: <slrn8ms2bc.45a.mike@zorak.happyfish.org>

Earlier, Rafael Garcia-Suarez <rgarciasuarez@free.fr> wrote:
>I think this change was made to make constructs like
>      not($a) || $b
>more intuitive.

In that case, you should have used:
	! $a || $b
or
	(not $a) || $b

To me, that is the whole point of the "not" operator.  We already have
"!", and if you want the negation to happen before the ||, then use
the operator with the higher precedence(!).

Its just like "and" and "or".  The reason for the english word is for
lower precedence, not just because some people like to spell the word
out.

The more I think about it, the less I like this change.

Mike


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

Date: Thu, 13 Jul 2000 20:06:49 GMT
From: brainmuffin@excite.com
Subject: Prepared statement SQL
Message-Id: <8kl7gb$vqv$1@nnrp1.deja.com>

I am using mySQL as the database server.  I have a Perl script that
uses a prepared statement with variable substitution...that is, it
has ? is it.  Is there anyway to see the SQL statement it executes WITH
the variables substituted??



Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Thu, 13 Jul 2000 20:19:44 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: PRINTing " "" "
Message-Id: <x78zv5kckh.fsf@home.sysarch.com>

>>>>> "JE" == Jürgen Exner <juex@deja.com> writes:

  JE> "Uri Guttman" <uri@sysarch.com> wrote in message

  >> are you saying that has to have internal double quotes?

  JE> Probably not. But for

  JE>     print "Der Befehl \"$cmd\" ist nicht erlaubt.\n"

  JE> you need double quotes because single quotes are used for nested
  JE> citations only (see Duden: Die deutsche Rechtschreibung, page 23,
  JE> rule 11) BTW: the leading double quotes should be aligned with the
  JE> bottom instead of with the top of the line, but we got used to
  JE> that Americanism already.

then use qq or here docs. there is still no need for escaped quote
chars. there is never a need for them and it is ugly to see.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


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

Date: Thu, 13 Jul 2000 12:06:19 -0700
From: "Baris" <sumengen@hotelspectra.com>
Subject: programing perl third edition
Message-Id: <396e1209_1@goliath.newsfeeds.com>

Hello,
Does anybody know the approximate release date for programming perl third
edition?
I have to decide to buy the second edition or not. (I lost it recently).
Thanks,
Baris.




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


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

Date: Thu, 13 Jul 2000 13:00:55 -0700
From: Rob Carraretto <rc@telus.net>
Subject: Re: programing perl third edition
Message-Id: <396E1FF7.A7835666@telus.net>

Baris wrote:
> 
> Hello,
> Does anybody know the approximate release date for programming perl third
> edition?
> I have to decide to buy the second edition or not. (I lost it recently).
> Thanks,
> Baris.
> 
> -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
> http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
> -----==  Over 80,000 Newsgroups - 16 Different Servers! =-----

According to Barnes & Noble online, it should be tomorrow!

http://shop.barnesandnoble.com/booksearch/isbnInquiry.asp?userid=2L842NYDJN&mscssid=J7Q33WPVB0S92JV100LHRV1AQ7JL5207&isbn=0596000278

Rob.


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

Date: Thu, 13 Jul 2000 13:07:56 -0700
From: "Baris" <sumengen@hotelspectra.com>
Subject: Re: programing perl third edition
Message-Id: <396e3252$1_1@goliath.newsfeeds.com>

Thanks a lot.

"Rob Carraretto" <rc@telus.net> wrote in message
news:396E1FF7.A7835666@telus.net...
> Baris wrote:
> >
> > Hello,
> > Does anybody know the approximate release date for programming perl
third
> > edition?
> > I have to decide to buy the second edition or not. (I lost it recently).
> > Thanks,
> > Baris.
> >
> > -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
> > http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
> > -----==  Over 80,000 Newsgroups - 16 Different Servers! =-----
>
> According to Barnes & Noble online, it should be tomorrow!
>
>
http://shop.barnesandnoble.com/booksearch/isbnInquiry.asp?userid=2L842NYDJN&
mscssid=J7Q33WPVB0S92JV100LHRV1AQ7JL5207&isbn=0596000278
>
> Rob.




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


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

Date: Thu, 13 Jul 2000 20:30:25 +0200
From: "Raphael Pirker" <raphaelp@nr1webresource.com>
Subject: Random number between 1 and x
Message-Id: <8kl2eo$q14$16$1@news.t-online.com>

Hi,

How do I calculate a random number between 1 and x? (where x is a variable
which can be defined)

Thanks!

Raphael




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

Date: Thu, 13 Jul 2000 19:01:11 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Random number between 1 and x
Message-Id: <sms4fn73nd6152@corp.supernews.com>

Raphael Pirker (raphaelp@nr1webresource.com) wrote:
: How do I calculate a random number between 1 and x? (where x is a variable
: which can be defined)

See the perldoc on rand().  If you want integers in this range, int()
might also be of use to you.  If these hints aren't enough to get you
there, post some code that almost works and we'll help you with the rest.
Good luck!

-- 
   |   Craig Berry - http://www.cinenet.net/users/cberry/home.html
 --*--  "Beauty and strength, leaping laughter and delicious
   |   languor, force and fire, are of us." - Liber AL II:20


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

Date: Thu, 13 Jul 2000 21:44:02 +0200
From: "Raphael Pirker" <raphaelp@nr1webresource.com>
Subject: Re: Random number between 1 and x
Message-Id: <8kl6lq$7h4$15$1@news.t-online.com>

Thanks. Ok, I've gotten this far:

$random = rand(10);

Which gives me something like "7.22503662109375" - how can I now round the
number to say only "7"?




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

Date: Thu, 13 Jul 2000 21:47:31 +0200
From: "Raphael Pirker" <raphaelp@nr1webresource.com>
Subject: Re: Random number between 1 and x
Message-Id: <8kl6ms$7h9$15$1@news.t-online.com>

just got the answer:

use POSIX;
$random = rand(10);
$random = ceil($random);





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

Date: 13 Jul 2000 21:22:37 +0200
From: "Marc Schaefer" <marc.schaefer@warwick.ac.uk>
Subject: Re: Random number between 1 and x
Message-Id: <m3lmz5kf7m.fsf@mapgw.csv.warwick.ac.uk>

Hi Raphael,

"Raphael Pirker" <raphaelp@nr1webresource.com> writes:

> Which gives me something like "7.22503662109375" - how can I now round the
> number to say only "7"?

You can _truncate_ the number by using int:

	$random = int rand 7;

gives you a random number between 0 (inclusive) and 6 (inclusive).

Best,

Marc


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

Date: Thu, 13 Jul 2000 21:15:08 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Random number between 1 and x
Message-Id: <smscask3nd669@corp.supernews.com>

Raphael Pirker (raphaelp@nr1webresource.com) wrote:
: just got the answer:
: 
: use POSIX;
: $random = rand(10);
: $random = ceil($random);

Not quite.  This has a vanishingly small but nonetheless real chance of
generating 0 in addition to 1..10.  You want

  $random = 1 + int rand(10);

(for generating integers 1-10.)

-- 
   |   Craig Berry - http://www.cinenet.net/users/cberry/home.html
 --*--  "Beauty and strength, leaping laughter and delicious
   |   languor, force and fire, are of us." - Liber AL II:20


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

Date: Thu, 13 Jul 2000 11:08:36 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: reg expression not working. WHY???
Message-Id: <MPG.13d7a57eb4a85e9b98abc7@nntp.hpl.hp.com>

In article <396DDDEA.1621E3D@attglobal.net> on Thu, 13 Jul 2000 11:19:06 
-0400, Drew Simonis <care227@attglobal.net> says...

 ...

> Have you tried changing the conditional to read:
> 
> if ("$address" eq "$cells[3]")
> 
> I seem to recall reading that double quotes will force stringification 
> of the terms, which may be helpfull since you are doing a string 
> comparision.  But then again, I may be wrong.  I don't see any mention
> in perlop of that behaviour.

The 'eq' operator forces stringification of each of its operands.  So 
your double-quotes just add superfluous noise.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Thu, 13 Jul 2000 14:31:06 -0400
From: Drew Simonis <care227@attglobal.net>
Subject: Re: reg expression not working. WHY???
Message-Id: <396E0AEA.909D6801@attglobal.net>

Larry Rosler wrote:
> 
> In article <396DDDEA.1621E3D@attglobal.net> on Thu, 13 Jul 2000 11:19:06
> -0400, Drew Simonis <care227@attglobal.net> says...
> 
> > I seem to recall reading that double quotes will force stringification
> > of the terms, which may be helpfull since you are doing a string
> > comparision.  But then again, I may be wrong.  I don't see any mention
> > in perlop of that behaviour.
> 
> The 'eq' operator forces stringification of each of its operands.  So
> your double-quotes just add superfluous noise.
> 

Ahh.  That clears it up nicely.  Thanks for taking the time to 
point out the correct answer.


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

Date: Thu, 13 Jul 2000 21:41:36 GMT
From: will@mylanders.com (Will England)
Subject: Request for Reaming
Message-Id: <slrn8msdv0.i6j.will@mylanders.com>

Greetings!

I've whupped up a bit of a perl script for low-security 
password management.  More or less, just a notepad with 
Twofish encryption of the systems passwords.

I'd appreciate it if any of y'all would take a look at 
the script and let me know what is wrong with it.  I know
the concept isn't the best, but it beats post-it-notes
under the keyboard.  

http://will.mylanders.com/develop/perl/passman/passman.txt

Thanks in advance for any tips, advice, etc.

Will

-- 
  "If Al Gore invented the Internet, then I invented spellcheck!"
      Dan Quayle, quoted at the National Press Club, 8/3/1999 
         pgpkey at http://will.mylanders.com/pub_pgp.asc 
  Recovery page: http://will.mylanders.com/    will@mylanders.com 


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

Date: Thu, 13 Jul 2000 21:19:25 GMT
From: clintp@geeksalad.org (Clinton A. Pierce)
Subject: Re: searching multiple sites
Message-Id: <xnqb5.35524$fR2.325812@news1.rdc1.mi.home.com>

[Posted and mailed]

In article <8kivo3$b2v$1@nnrp1.deja.com>,
	Nitin <muhala@my-deja.com> writes:
> I'm trying to write a script that will allow a user to enter a search
> term and have it searched over multiple web sites. The problem I am
> [...] How do I
> deal with sites that have set up their own authentication mechanism
> [...]

You manually set up a well-known ID at each one of the accounts.

Then you use LWP::UserAgent to fetch the pages using whatever 
authentication method these sites want.

followups adjusted.

-- 
    Clinton A. Pierce              Teach Yourself Perl in 24 Hours! 
  clintp@geeksalad.org         for details see http://www.geeksalad.org
"If you rush a Miracle Man, 
	you get rotten Miracles." --Miracle Max, The Princess Bride


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

Date: Thu, 13 Jul 2000 13:13:54 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Shortcut for non-defined variables
Message-Id: <slrn8mru6i.bar.tadmc@magna.metronet.com>

On Thu, 13 Jul 2000 16:28:40 GMT, James Weisberg <chadbour@wwa.com> wrote:

>   Is there a shorthand for
>the statement:
>
>   $val = (defined $val) ? $val : -1;

>   where $val is set to -1 if $val is not defined. 


   $val = -1 unless defined $val:


-- 
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Thu, 13 Jul 2000 18:37:11 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Shortcut for non-defined variables
Message-Id: <sms32nblnd6161@corp.supernews.com>

James Weisberg (chadbour@wwa.com) wrote:
:    Here's an extremely simple Perl question. Is there a shorthand for
: the statement:
: 
:    $val = (defined $val) ? $val : -1;
: 
:    To me, this looks ugly.

As to many of us.  Larry Rosler (among others) has been campaigning for a
?? operator (and, presumably, a ??= op-assignment) which would check the
defined-ness of its left arg, return that if it's defined, or its right
arg otherwise.  So your code would look like: 

  $val ??= -1;

Much nicer, we think.

-- 
   |   Craig Berry - http://www.cinenet.net/users/cberry/home.html
 --*--  "Beauty and strength, leaping laughter and delicious
   |   languor, force and fire, are of us." - Liber AL II:20


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

Date: Thu, 13 Jul 2000 11:33:58 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Shortcut for non-defined variables
Message-Id: <MPG.13d7ab7453e509c798abc8@nntp.hpl.hp.com>

In article <Y6mb5.1710$IZ1.13486@iad-read.news.verio.net> on Thu, 13 Jul 
2000 16:28:40 GMT, James Weisberg <chadbour@wwa.com> says...
>    Here's an extremely simple Perl question. Is there a shorthand for
> the statement:
> 
>    $val = (defined $val) ? $val : -1;
> 
>    To me, this looks ugly. The || operator is fine for making  
> statements like:
> 
>    $val ||= -1;
> 
>    but $val will be set to -1 if $val is 0, which is not what I want
> to do. Have I missed something? I'm surprised there is no way to do
> the equivalent of:
> 
>    $val def= -1;
> 
>    where $val is set to -1 if $val is not defined. 

<WARNING -- This doesn't work!  Some day it will, one hopes.>

<Campaign = ON>

     $val ??= -1;

<Campaign = OFF>

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Thu, 13 Jul 2000 14:13:29 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: Shortcut for non-defined variables
Message-Id: <396E14D9.F47DBB77@home.com>

James Weisberg wrote:
> 
>    Here's an extremely simple Perl question. Is there a shorthand for
> the statement:
> 
>    $val = (defined $val) ? $val : -1;
> 
> [...]
>
> I'm surprised there is no way to do the equivalent of:
> 
>    $val def= -1;
> 
>    where $val is set to -1 if $val is not defined.

No, there isn't such a beast. There has been a (recurring) holy war
about creating a '??' (hookhook) operator for just that purpose, but it
hasn't happened. For an in-depth analysis of *why* it hasn't been
adopted, read the following article by Tom Christiansen:

http://www.perl.com/tchrist/defop/defconfaq.html

-mjc


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

Date: Thu, 13 Jul 2000 18:32:27 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Shorten this code, can u ?
Message-Id: <sms2pr1qnd6104@corp.supernews.com>

Marc Schaefer (marc_schaefer@warwick.ac.uk) wrote:
: Unfortunately, this works only when called for the first time,
: as $i and @b are _global_ variables and thus still contain the
: remains from last time's match. Changing it to
: 
:     sub match{
:        my($a,$i,@b)=pop;for(@_){/$a/?push@b,$i++:$i++}@b?@b:-1
:     }

Here's a great example of where my proposed reuse of the deprecated $#
variable to hold the current loop index would shine:

  my($a,@b)=pop;for(@_){/$a/&&push@b,$#}@b?@b:-1;

-- 
   |   Craig Berry - http://www.cinenet.net/users/cberry/home.html
 --*--  "Beauty and strength, leaping laughter and delicious
   |   languor, force and fire, are of us." - Liber AL II:20


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

Date: Thu, 13 Jul 2000 23:09:58 +0200
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Shorten this code, can u ?
Message-Id: <4nbsms87tnpq264pakutvs92s4a7oqd9j9@4ax.com>

Marc Schaefer wrote:

>> This is the shortest we've managed to construct so far:
>> sub match{$a=pop;for(@_){/$a/?push@b,$i++:$i++}@b?@b:-1}
>
>Unfortunately, this works only when called for the first time,
>as $i and @b are _global_ variables and thus still contain the
>remains from last time's match.

I don't know about "short", but this will behave:

	sub match{my$r=pop;map{$_[$_]=~/$r/?$_:()}0..$#_}

except that it returns an empty list, and not (-1), when nothing found.
Hey, that is better. So let's change the specification... ;-) It's
shorter than yours, anyway, even if yours is shortened to the same new
spec.

-- 
	Bart.


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

Date: Thu, 13 Jul 2000 23:27:59 +0200
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Shorten this code, can u ?
Message-Id: <bjcsms8jb2qbm495vdnqvkqoiafg6a0vhu@4ax.com>

Bart Lateur (that's me) wrote:

>	sub match{my$r=pop;map{$_[$_]=~/$r/?$_:()}0..$#_}

Oh silly me, that's just an emulated grep.

	sub match{my$r=pop;grep{$_[$_]=~/$r/}0..$#_}

Which, adapted to your original specs, becomes:

	sub match{my$r=pop;my@b=grep{$_[$_]=~/$r/}0..$#_;@b?@b:-1}

Damned, two characters longer than yours, but clean and polite code.

Drop the my's, and we have a contender:

	sub match{$r=pop;(@b=grep{$_[$_]=~/$r/}0..$#_)?@b:-1}

3 characters shorter than yours.

-- 
	Bart.


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

Date: 13 Jul 2000 22:49:52 +0200
From: Marc Schaefer <marc.schaefer@warwick.ac.uk>
Subject: Re: Shorten this code, can u ?
Message-Id: <m3sntdrc0f.fsf@mapgw.csv.warwick.ac.uk>

Hi Bart,

Bart Lateur <bart.lateur@skynet.be> writes:

> 	sub match{my$r=pop;map{$_[$_]=~/$r/?$_:()}0..$#_}
> 
> except that it returns an empty list, and not (-1), when nothing found.
> Hey, that is better. So let's change the specification... ;-) 

Hey, that's cheating! :-)

But I'd prefer this way as well ...

> It's shorter than yours, anyway, even if yours is shortened to the
> same new spec.

sub match{grep$_[$_]=~/$_[-1]/,0..@_-2}

Best,

Marc


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

Date: 13 Jul 2000 22:54:21 +0200
From: Marc Schaefer <marc.schaefer@warwick.ac.uk>
Subject: Re: Shorten this code, can u ?
Message-Id: <m3puohrbsy.fsf@mapgw.csv.warwick.ac.uk>

Hi Bart,

Bart Lateur <bart.lateur@skynet.be> writes:

> Drop the my's, and we have a contender:
> 
> 	sub match{$r=pop;(@b=grep{$_[$_]=~/$r/}0..$#_)?@b:-1}

 ... which clobbers the global $r and @b. Ts, ts, ts ...

:-)

> 3 characters shorter than yours.

?

This was my first attempt:

        sub match{(@_=grep$_[$_]=~/$_[-1]/,0..@_-2)?@_:-1}

Best,

Marc



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

Date: Thu, 13 Jul 2000 16:43:12 -0500
From: "Jim Kauzlarich" <o1technospam@skyenet.nospam.net>
Subject: Re: String length?
Message-Id: <WCqb5.114$RX5.876@newsfeed.slurp.net>


"Craig Berry" <cberry@cinenet.net> wrote in message
news:sms11e6qnd629@corp.supernews.com...
> Jim Kauzlarich (o1technospam@skyenet.nospam.net) wrote:
> : So, with a little last minute re-vamping, here is my creation:  (though
> : without the do loop, and the extra if/then evaluation it feels un-Perl.
The
> : little bit I know.)
>
> Nicely horrid.  One tweak (unless the extra warning was intentional, of
> course):

Thank you!

> :     if ( @_[$count] ne "" ) {
>
>   s/\@/\$/

Regular expression I assume?  I haven't really delved into them yet.  Is
that a substitution?

I'm a bit surprised that no one snapped at my mis-attempt at using strict.
"use strict();"  I'd been up for about 20 hours, and when I attempted to add
strict. It came back with the following err that I'm still not sure what
means  (mee tawk gud englush, eh?)

Global symbol "x" requires explicit package name at count3.cgi line 22.

What is an "explicit package name"?

I figured that I'd added in strict incorrectly, and changed it.  I also
don't understand why I didn't get an error when I put "use strict()" at the
top of my program.


>
> --
>    |   Craig Berry - http://www.cinenet.net/users/cberry/home.html
>  --*--  "Beauty and strength, leaping laughter and delicious
>    |   languor, force and fire, are of us." - Liber AL II:20




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

Date: Thu, 13 Jul 2000 20:45:11 GMT
From: Tony Bowden <tony@pyxis.blackstar.co.uk>
Subject: Re: Symbolic References for Form parsing?
Message-Id: <rTpb5.1070$254.19925@news2-win.server.ntlworld.com>

Steven Smolinski <sjs@yorku.ca> wrote:
> To accomplish your purpose while using CGI.pm, I usually put my 
> parameters into a hash named params:
> my %params = map { $_ => param($_) } param();

Or, more simply,

  my %params = Vars;

(See "FETCHING THE PARAMETER LIST AS A HASH" in perldoc CGI)

Tony
-- 
-----------------------------------------------------------------------------
 Tony Bowden | Belfast, NI | tb@tmtm.com | www.tmtm.com | www.blackstar.co.uk
                                every tool is a weapon - if you hold it right
-----------------------------------------------------------------------------


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

Date: Thu, 13 Jul 2000 14:54:32 -0400
From: "Alex T." <samara_biz@hotmail.com>
Subject: Using ASP objects with Perl modules
Message-Id: <396E1068.A6E296A7@hotmail.com>


Hi,

I am writing a PerlScript for ASP on Windows NT with IIS 4.0
I've been working on this for a few hours already, but couldn't find a
solution yet. I would really appriciate any help!

Here's the simple script:

<%
use lib "C:/InetPub/Mymodules";
use example1;

example1::output("Hello from simple script!");
%>

Here's the module that this script uses:

package example1;

use strict;
use warnings;
use vars qw( $Response );

BEGIN {
 use Exporter ();
 my ($VERSION, @ISA, @EXPORT);

 $VERSION = 1.00;
 @ISA = qw(Exporter);
 @EXPORT = qw( &output );
}

sub output{
 my $to_print = $_[0];
 $Response->Write("<h3>".$to_print."</h3>");
}

END { }
1;

When I try to run my script I get the following error message:

Microsoft Active Server Pages error '80004005'
Can't call method "Write" on an undefined value at
C:/InetPub/Mymodules/example1.pm.
?

Can anyone help me?  How can I get this script to run?

Thanks!

Alex



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

Date: Thu, 13 Jul 2000 19:02:23 GMT
From: nelsonmuntz4925@my-deja.com
Subject: Using variables in regexps
Message-Id: <8kl3nh$sih$1@nnrp1.deja.com>

This is probably a simple one for you...

Why doesn't this work:

$charToStrip = '$';
$price='$59.95';

$price=~s/$charToStrip//;

I want $price to be 59.95 here but it is still $59.95

I tried ~s/$charToStrip//e as well.

Thanks!


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Thu, 13 Jul 2000 19:20:38 GMT
From: mads@troest.NEVERMORE.dk (Mads Orbesen Troest)
Subject: Re: Using variables in regexps
Message-Id: <k6fk2tedC4v7-pn2-xUwyptsRIOdO@mads.lokal.net>

On Thu, 13 Jul 2000 19:02:23, nelsonmuntz4925@my-deja.com wrote:

Heya!

> $charToStrip =3D '$';
> $price=3D'$59.95';
> $price=3D~s/$charToStrip//;

Try escaping the character: $charToStrip =3D '\$';
This will yield the correct result. :-)

The reason is that even though you gave the $-sign in single-quotes, 
that string will indicate a scalar variable to be interpolated inside 
the reguar expression unless you escape it. If you'd used another 
character, your code would work correctly:

 $charToStrip =3D '_';
 $price=3D'_59.95';
 $price=3D~s/$charToStrip//;

OK; it's the $ that's special. :-)

      ... /\/\\ads Orbesen Troest <mads@troest.NEVERMORE.dk>

(Please remove NEVERMORE from address when replying via email...)


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

Date: Thu, 13 Jul 2000 12:34:16 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Using variables in regexps
Message-Id: <396E19B8.461F3157@stomp.stomp.tokyo>

nelsonmuntz4925@my-deja.com wrote:

> Why doesn't this work:
 
> $charToStrip = '$';
> $price='$59.95';
> $price=~s/$charToStrip//;
 
> I want $price to be 59.95 here but it is still $59.95
 
> I tried ~s/$charToStrip//e as well.

 


TEST SCRIPT:
____________


#!/usr/local/bin/perl

print "Content-Type: text/plain\n\n";

$charToStrip = '\$';

$price = '$59.95';

$price =~ s/$charToStrip//;

print "     $price \n\n Godzilla!";

exit;


PRINTED RESULTS:
________________


     59.95 

 Godzilla!


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

Date: Thu, 13 Jul 2000 12:40:15 -0800
From: kenned57@pilot.msu.edu (Cameron Kennedy)
Subject: Re: Using variables in regexps
Message-Id: <kenned57-1307001240150001@alexthinkpad.salk.edu>


> nelsonmuntz4925@my-deja.com wrote:
> 
> > Why doesn't this work:
>  
> > $charToStrip = '$';
> > $price='$59.95';
> > $price=~s/$charToStrip//;
>  
> > I want $price to be 59.95 here but it is still $59.95
>  
> > I tried ~s/$charToStrip//e as well.
> 

'$' is a special character in a regex. 
either put it in a character class

$price=~s/[$char]//

or escape the '$' at step one
$char='\$';
$price=~s/$char//

Cameron


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

Date: 13 Jul 2000 19:47:48 GMT
From: Tina Mueller <tina@streetmail.com>
Subject: Re: Using variables in regexps
Message-Id: <8kl681$2ld9r$2@ID-24002.news.cis.dfn.de>

hi,
nelsonmuntz4925@my-deja.com wrote:

> $charToStrip = '$';
> $price='$59.95';

> $price=~s/$charToStrip//;

> I want $price to be 59.95 here but it is still $59.95
i
try:
my $charToStrip = quotemeta '$';
my $price='$59.95';

$price=~s/$charToStrip//;

perldoc perlre

tina

-- 
http://tinita.de    \  enter__| |__the___ _ _ ___
tina's moviedatabase \     / _` / _ \/ _ \ '_(_-< of
search & add comments \    \ _,_\ __/\ __/_| /__/ perception
"The Software required Win98 or better, so I installed Linux."


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

Date: Thu, 13 Jul 2000 15:07:45 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Using variables in regexps
Message-Id: <slrn8ms4s1.bnl.tadmc@magna.metronet.com>

On Thu, 13 Jul 2000 19:02:23 GMT, nelsonmuntz4925@my-deja.com <nelsonmuntz4925@my-deja.com> wrote:
>This is probably a simple one for you...
>
>Why doesn't this work:


It does work.

It replaces the end of string (that's what $ means in a regex)
with nothing.


>$charToStrip = '$';

   $charToStrip = '\$';
                   ^
                   ^ so regex engine will treat $ as a literal character

>$price='$59.95';
>
>$price=~s/$charToStrip//;

>I want $price to be 59.95 here but it is still $59.95
>
>I tried ~s/$charToStrip//e as well.
                          ^
                          ^

Well that isn't going to work, because the 'e' option only
applies to the replacement string, and your replacement
string is the empty string (which is very uninteresting Perl 
code to evaluate :-)


-- 
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: 13 Jul 2000 21:14:02 +0200
From: "Marc Schaefer" <marc.schaefer@warwick.ac.uk>
Subject: Re: Using variables in regexps
Message-Id: <m3og41kflx.fsf@mapgw.csv.warwick.ac.uk>

Hi Nelson,

nelsonmuntz4925@my-deja.com writes:

> $charToStrip = '$';
> $price='$59.95';
> 
> $price=~s/$charToStrip//;

Here s/// interprets the contents of $charToStrip as a regular
expression. The regexp '$' means 'match something with zero width at
the end of the line', so you replace something with zero width (i.e.
nothing) by ''.

The regexp you _want_ to match is '\$', i.e. a literal dollar sign.
You could either put the quoting in your variable

	$regexpToStrip = '\$';
	$price = '$59.95';

	$price =~ s/$regexpToStrip//;

or let perl do the quoting for you:

	$charToStrip = '$';
	$price = '$59.95';

	$price =~ s/\Q$charToStrip\E//;
		    ^^            ^^
Read about \Q and \E in perlop in the section "Quote and Quote-like
Operators".

(By the way, all the above substitutions only delete the first dollar
sign in $price, i.e. 'aaa$bbb$' => 'aaabbb$'. If you want to delete
them all, use the /g modifier)

However, if you only want to delete single characters, you should have
a look at tr/// (also in perlop):

	$charToStrip = '$';
	$price = '$59.95';

	$price =~ tr/$charToStrip//d;

Best,

Marc


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

Date: Thu, 13 Jul 2000 12:39:34 -0700
From: Sergio Sanchez <sergios@vitesse.com>
Subject: w32 module
Message-Id: <396E1AF6.D4F9059@vitesse.com>

I  am trying to install the AdminMisc extension for Win32 Perl and
according to the instruction s in the readme file it references a file i
dont have in the zip.

------------------------------------------------------
HOW TO INSTALL:
    - IF you are using the ActiveState version of Win32 Perl:
        a) Copy the ADMINMISC.PM file into the directory perl\lib\win32\
        b) Rename the file ADMINMISC_XXX.PLL to ADMINMISC.PLL  <--i dont
have it
        c) Make a directory: perl\lib\auto\win32\adminmisc\
        d) Copy the ADMINMISC.PLL file into the directory in step c

thanks in advance

surge


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

Date: Thu, 13 Jul 2000 14:38:57 -0600
From: Dan Woods <dwoods@ucalgary.ca>
Subject: Windmail/NT CGI script not sending mail
Message-Id: <396E28E1.B30633@ucalgary.ca>

I have written a Perl script to work on NT (I hate NT). It is
supposed to read a data file (list of articles) and create the
HTML page using a template. The user then selects a list of
articles they want to receive, and provide user info with
email address.  After submit, the script should send an email
to the user with the requested files *attached* to the email,
and the admin receives an email with the user info.

I am testing on my NT workstation with Apache and Windmail
3.05 eval, and the script works.  However, I then tried to
install it on a hosting site where they use IIS and Windmail.
I only modified the local path of the template/data file.
The list of articles is created, but after selection my script
reports success, meaning no error from 
open(MAIL, "|windmail -t") || &error("Could not open mail program");
but no email is ever sent.
Since this is on a hosting company, debugging is very difficult
and I am restricted on what we can use, so using blat.exe is not ok
(i also had blat working locally).

This has been frustrating me for two weeks now.
I am not likely to volunteer to do another NT script anytime soon,
however I still have to solve this problem :(

Thanks...Dan.


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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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 V9 Issue 3657
**************************************


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