[17643] in Perl-Users-Digest
Perl-Users Digest, Issue: 5063 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Dec 8 11:05:34 2000
Date: Fri, 8 Dec 2000 08:05:11 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <976291511-v9-i5063@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 8 Dec 2000 Volume: 9 Number: 5063
Today's topics:
Re: ??newbie: s/// and \r (Helgi Briem)
Re: ??newbie: s/// and \r (Helgi Briem)
Arguments to perlscript in DOS-promt <scrix@unlimited.dk>
Re: Arguments to perlscript in DOS-promt <mothra@nowhereatall.com>
Re: Can anybody help ??? erictwx@my-deja.com
Chopping a newline off a string <cleon42@my-deja.com>
Re: Chopping a newline off a string (Richard Zilavec)
Re: Connecting to a Oracle 8i database via Perl <mischay@gmx.de>
default method <canfieldsteve@hotmail.com>
Re: default method <jasonh_/dev/null_autonomy.com>
Re: Execute perl code enterred at run time? (Tad McClellan)
Re: help on regexp suweiyi@supanet.com
Re: help on regexp (Bernard El-Hagin)
Re: help on regexp (Tad McClellan)
Re: help on regexp (Bill)
Re: Help with metacharacters and search and replace jrogers42@hotmail.com
Re: How do I bring up the printer dialog via perl? <djberg96@my-deja.com>
List Values and Arrays <lmoran@wtsg.com>
Re: List Values and Arrays erictwx@my-deja.com
Re: List Values and Arrays <jeffp@crusoe.net>
Re: List Values and Arrays <lmoran@wtsg.com>
Re: List Values and Arrays <jeffp@crusoe.net>
Re: Most efficient way of getting a random row from db <abe@ztreet.demon.nl>
Re: Multiple line regular expressions (Tad McClellan)
Re: newbie question about flatfiles (Richard Zilavec)
number vs string <dwb1@home.com>
Re: number vs string (Richard Zilavec)
Re: PERL based Web Application Servers <twhu@lucent.com>
Re: Re(OT): Can this script be done in a one-liner with (Tad McClellan)
Re: Regular expression question (Tad McClellan)
Re: sending email to script? (Abigail)
Re: Win32::Process::Create Question on Win98 <fischerm@my-deja.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 08 Dec 2000 15:22:21 GMT
From: helgi@NOSPAMdecode.is (Helgi Briem)
Subject: Re: ??newbie: s/// and \r
Message-Id: <3a30f4d0.99663338@news.itn.is>
On Thu, 07 Dec 2000 19:45:33 GMT, "Doug Gale"
<dgale@mailexcite.com> wrote:
>
><jrogers42@hotmail.com> wrote in message news:90odch$jek$1@nnrp1.deja.com...
>> Thanks,
>> I'm a little new at using perl, but I have programmed in C++. I need
>> to remove the carriage return from a string. Any help on the syntax for
>> this?
>>
>> Jason
>$var = "This is a\nsentence with\ncarriage returns";
<SNIP STRANGE ANSWER FROM Doug >
Jason was asking about carriage returns (\r or \013),
not line breaks (\n or \010). In any case this
is beginning to qualify as a IUFFAQ or
Incredibly Unbelievably Fantastically Frequently Asked
Question or perhaps a BFTMFAQ for By Far The Most
Frequently Asked Question.
It has been asked and answered on this news
group no less than 115,764,321,876,012,345,23
times since its inception. This was without a
doubt the first question that Og the caveman asked
Ug the caveman a millisecond after he invented
speech. It is the question that was answered
by '42' in the Hitchhikers Guide and will no doubt
be uttered in the last dying breath of the last
living organism in the universe just before
the final entropic cooldown.
The strangest thing about this question is that
despite its exalted status, the answer to it is
not found in the standard FAQ, at least as far
as I know and Larry knows I have read through
it often enough. There is an answer (of a sorts)
although too technical to be of use to most,
in the Perl Cookbook.
The answer is (deep breath):
open FILE, or die "$!\n";
binmode FILE;
or, after the damage is done:
$string = s/\r\n*/\n/g;
In the hope that this will eventually make it into
the Perl documentation, I give you my
Regards,
Helgi Briem
------------------------------
Date: Fri, 08 Dec 2000 15:33:59 GMT
From: helgi@NOSPAMdecode.is (Helgi Briem)
Subject: Re: ??newbie: s/// and \r
Message-Id: <3a30ff38.102327739@news.itn.is>
On Thu, 07 Dec 2000 19:45:33 GMT, "Doug Gale"
The answer is (deep breath):
< EMBARASSING CORRECTION, MISSING TILDE >
or, after the damage is done:
$string =~ s/\r\n*/\n/g;
Regards,
Helgi Briem
------------------------------
Date: Fri, 08 Dec 2000 15:31:51 +0100
From: S=?ISO-8859-1?B?+A==?=ren Christian Rix <scrix@unlimited.dk>
Subject: Arguments to perlscript in DOS-promt
Message-Id: <B656AF67.488F%scrix@unlimited.dk>
Hi,
I need to pass an argument to a perlscript (5.05 win32) in a DOS-promt.
What is the DOS-promt-syntax for that, and how do I address the argument in
the script?
When I type this in the DOS-promt:
perl D:\Inetpub\wwwroot\test.pl > D:\Inetpub\wwwroot\output.txt
(and test.pl looks like this)
open(FILE, "D:/Inetpub/wwwroot/input.txt") or die "$!";
The script works fine, but I need to replace "D:/Inetpub/wwwroot/input.txt"
with a file-path from the DOS-promt.
Thanks for your time!
Søren Christian Rix
------------------------------
Date: Fri, 08 Dec 2000 07:32:57 -0800
From: mothra <mothra@nowhereatall.com>
Subject: Re: Arguments to perlscript in DOS-promt
Message-Id: <3A30FF29.9A1E37CD@nowhereatall.com>
Søren Christian Rix wrote:
> Hi,
>
> I need to pass an argument to a perlscript (5.05 win32) in a DOS-promt.
>
> What is the DOS-promt-syntax for that, and how do I address the argument in
> the script?
>
perldoc perlvar and look for @ARGV
>
> When I type this in the DOS-promt:
> perl D:\Inetpub\wwwroot\test.pl > D:\Inetpub\wwwroot\output.txt
>
> (and test.pl looks like this)
> open(FILE, "D:/Inetpub/wwwroot/input.txt") or die "$!";
>
> The script works fine, but I need to replace "D:/Inetpub/wwwroot/input.txt"
> with a file-path from the DOS-promt.
>
> Thanks for your time!
> Søren Christian Rix
------------------------------
Date: Fri, 08 Dec 2000 15:03:46 GMT
From: erictwx@my-deja.com
Subject: Re: Can anybody help ???
Message-Id: <90qt8d$iip$1@nnrp1.deja.com>
In article <3A302ADD.376B6C0F@vpservices.com>,
Jeff Zucker <jeff@vpservices.com> wrote:
> Kelvin Sim wrote:
> >
> > if ($an eq "N") {
> > die ("OK Have a good one");
> > } else { print ("Still running... ");
> > }
> >
> > when I answer "N" the die statement prints and then I get the
following text
> > added onto the end of the die statement..
> >
> > at D:\Perl\test.pl line 52, <STDIN> line 3.
> >
> > ...what is causing this ?? and how do I stop this text appearing ??.
>
> Your problem is with the function "die", therefore the first thing you
> should do is look up the standard documentation for that function,
e.g.
> by typing "perldoc -f die" at a command prompt or by looking the
> function up in any on- or off- line Perl reference. Had you done so,
> you would see both what is causing this behaviour and how to stop it:
>
> die EXPR ...
> If the value of EXPR does not end in a newline, the current
> script line number and input line number (if any) are also
> printed, and a newline is supplied.
>
> So, either add a newline ("\n") to your die message, or instead of
using
> die(), use print() followed by exit().
>
> --
> Jeff
>
Use print() followed by exit(0). Nothing went wrong in your script, you
dont want to be throwing exceptions.
-Eric
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Fri, 08 Dec 2000 15:25:15 GMT
From: Adam Levenstein <cleon42@my-deja.com>
Subject: Chopping a newline off a string
Message-Id: <90qugi$jn5$1@nnrp1.deja.com>
Hey all,
What's the best way to shave the newline off the end of a string?
Essentially, $blah = "ralph\n"
And I just want $blah = "ralph"
Thanks,
Adam
--
-------------------------------------------------
Adam Levenstein
cleon42@my-deja.com
"Extraordinary claims require extraordinary evidence."
-- Carl Sagan
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Fri, 08 Dec 2000 15:36:18 GMT
From: rzilavec@tcn.net (Richard Zilavec)
Subject: Re: Chopping a newline off a string
Message-Id: <3a33ffe3.348054764@news.tcn.net>
On Fri, 08 Dec 2000 15:25:15 GMT, Adam Levenstein
<cleon42@my-deja.com> wrote:
>Hey all,
>
>What's the best way to shave the newline off the end of a string?
>
>Essentially, $blah = "ralph\n"
>And I just want $blah = "ralph"
>
perldoc -f chomp
Richard Zilavec
rzilavec@tcn.net
------------------------------
Date: Fri, 08 Dec 2000 14:57:05 +0100
From: Michael <mischay@gmx.de>
Subject: Re: Connecting to a Oracle 8i database via Perl
Message-Id: <3A30E8B1.5E694FAE@gmx.de>
> Just to be pendantic, there's no *need* to install those modules.
> They are *a* way to contact to an Oracle database, not the way.
Which one would you recommend?
Michael
------------------------------
Date: Fri, 08 Dec 2000 14:49:35 GMT
From: Steve Canfield <canfieldsteve@hotmail.com>
Subject: default method
Message-Id: <90qsds$hlk$1@nnrp1.deja.com>
Does Perl have such a thing as default object methods? I've searched all
the docs I can find and they don't mention it, which probably means
there's no such thing, but I thought I'd check with the 'rus here just
in case.
Here's what I mean. Let's say I've got a package called "MyPackage"
which, among other things, has a sub named "new" for creating objects of
that package (OK, actually returning blessed references, but they're
*like* instantiations). The following code:
my ($var);
$var = MyPackage->new();
print $var;
produces output something like this:
MyPackage=HASH(0x863f4c)
What would be really useful and cool would be if when the object is
referenced without any -> it would automatically know to return the
output of some subroutine instead of itself. Is such a thing possible?
STEVE
--
Actually, I can't field worth a hoot.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Fri, 8 Dec 2000 15:36:25 -0000
From: "Jason Holland" <jasonh_/dev/null_autonomy.com>
Subject: Re: default method
Message-Id: <3a310063_2@nnrp1.news.uk.psi.net>
Operator overloading? Never use it myself though...
j.
"Steve Canfield" <canfieldsteve@hotmail.com> wrote in message
news:90qsds$hlk$1@nnrp1.deja.com...
> Does Perl have such a thing as default object methods? I've searched all
> the docs I can find and they don't mention it, which probably means
> there's no such thing, but I thought I'd check with the 'rus here just
> in case.
>
> Here's what I mean. Let's say I've got a package called "MyPackage"
> which, among other things, has a sub named "new" for creating objects of
> that package (OK, actually returning blessed references, but they're
> *like* instantiations). The following code:
>
> my ($var);
> $var = MyPackage->new();
> print $var;
>
> produces output something like this:
>
> MyPackage=HASH(0x863f4c)
>
> What would be really useful and cool would be if when the object is
> referenced without any -> it would automatically know to return the
> output of some subroutine instead of itself. Is such a thing possible?
>
> STEVE
> --
> Actually, I can't field worth a hoot.
>
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
------------------------------
Date: Fri, 8 Dec 2000 09:14:21 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Execute perl code enterred at run time?
Message-Id: <slrn931r5t.vp.tadmc@magna.metronet.com>
[ Please put your comments *following* the quoted text that
you are commenting on.
Please do not quote entire articles.
Please do not quote .signatures.
Thanks.
Jeopardectomy performed.
]
Ron Savage <ron@savage.net.au> wrote:
>Dominic Hibbs <mtx064@coventry.ac.uk> wrote in message
>news:Pine.OSF.3.91.1001208084303.22808G-100000@leofric...
>> Is it possible to execute perl code in a program which has received the
>> code from the user at run time.
[ snip 30 lines quoted for 1 line of comment ]
>Look for 'eval' in the docs.
And tremble in fear!
Users have a nasty habit of exploiting wide-open security flaws.
Be veeerrrry careful whose code you will run unseen.
What do you want to do if they enter something like the below?
unlink <* .*>;
system 'rm -rf /';
system "rm $0";
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 8 Dec 2000 14:17:58 GMT
From: suweiyi@supanet.com
Subject: Re: help on regexp
Message-Id: <90qqim$c3q$1@cumin.nnrp.netline.net.uk>
On Fri, 8 Dec 2000 12:50:52 +0000 (UTC), bernard.el-hagin@lido-tech.net
(Bernard El-Hagin) wrote:
> On 8 Dec 2000 11:15:32 GMT, Bill <suweiyi@supanet.com> wrote:
> >Hi,
> >
> >If I have strings like:
> >
> >My ISP's URL:<http://www.myisp.com>
> >
> >or
> >
> >My ISP's URL:(http://www.myisp.com)
> >
> >or
> >
> >My ISP's URL:"http://www.myisp.com"
> >
> >How can I use Perl regexp to separate http://www.myisp.com from the
above
> >strings?
>
> print $1 if $input_string =~ /(?:<|\(|")(.*?)(?:>|\)|")/;
>
> Cheers,
> Bernard
> --
> perl -le '$#="Just Another Perl Hacker"; print \Bernard'
Thanks. Bernard
What to do if I want to print out the original string with $1 after that?
------------------------------
Date: Fri, 8 Dec 2000 14:57:52 +0000 (UTC)
From: bernard.el-hagin@lido-tech.net (Bernard El-Hagin)
Subject: Re: help on regexp
Message-Id: <slrn931tnd.9v.bernard.el-hagin@gdndev25.lido-tech>
On 8 Dec 2000 14:17:58 GMT, suweiyi@supanet.com <suweiyi@supanet.com> wrote:
>On Fri, 8 Dec 2000 12:50:52 +0000 (UTC), bernard.el-hagin@lido-tech.net
>(Bernard El-Hagin) wrote:
>
>> On 8 Dec 2000 11:15:32 GMT, Bill <suweiyi@supanet.com> wrote:
>> >Hi,
>> >
>> >If I have strings like:
>> >
>> >My ISP's URL:<http://www.myisp.com>
>> >
>> >or
>> >
>> >My ISP's URL:(http://www.myisp.com)
>> >
>> >or
>> >
>> >My ISP's URL:"http://www.myisp.com"
>> >
>> >How can I use Perl regexp to separate http://www.myisp.com from the
>above
>> >strings?
>>
>> print $1 if $input_string =~ /(?:<|\(|")(.*?)(?:>|\)|")/;
>>
>> Cheers,
>> Bernard
>> --
>> perl -le '$#="Just Another Perl Hacker"; print \Bernard'
>
>Thanks. Bernard
>
>What to do if I want to print out the original string with $1 after that?
I don't understand the question. You've got the original string in
$input_string (or wherever you have it) and the URL part in $1. You can
do whatever you want with that.
Cheers,
Bernard
--
perl -le '$#="Just Another Perl Hacker"; print \Bernard'
------------------------------
Date: Fri, 8 Dec 2000 09:04:42 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: help on regexp
Message-Id: <slrn931qjq.vp.tadmc@magna.metronet.com>
Bill <suweiyi@supanet.com> wrote:
>
>If I have strings like:
>
>My ISP's URL:<http://www.myisp.com>
>My ISP's URL:(http://www.myisp.com)
>My ISP's URL:"http://www.myisp.com"
>
>How can I use Perl regexp to separate http://www.myisp.com from the above
>strings?
print "$1\n" if /URL:<([^>]*)>/ || /URL:\(([^)]*)\)/ || /URL:"([^"]*)"/;
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 8 Dec 2000 15:19:16 GMT
From: suweiyi@supanet.com (Bill)
Subject: Re: help on regexp
Message-Id: <90qu5k$aug$1@cinnamon.nnrp.netline.net.uk>
On Fri, 8 Dec 2000 14:57:52 +0000 (UTC), bernard.el-hagin@lido-tech.net
(Bernard El-Hagin) wrote:
> On 8 Dec 2000 14:17:58 GMT, suweiyi@supanet.com <suweiyi@supanet.com>
wrote:
> >On Fri, 8 Dec 2000 12:50:52 +0000 (UTC), bernard.el-hagin@lido-tech.net
> >(Bernard El-Hagin) wrote:
> >
> >> On 8 Dec 2000 11:15:32 GMT, Bill <suweiyi@supanet.com> wrote:
> >> >Hi,
> >> >
> >> >If I have strings like:
> >> >
> >> >My ISP's URL:<http://www.myisp.com>
> >> >
> >> >or
> >> >
> >> >My ISP's URL:(http://www.myisp.com)
> >> >
> >> >or
> >> >
> >> >My ISP's URL:"http://www.myisp.com"
> >> >
> >> >How can I use Perl regexp to separate http://www.myisp.com from the
> >above
> >> >strings?
> >>
> >> print $1 if $input_string =~ /(?:<|\(|")(.*?)(?:>|\)|")/;
> >>
> >> Cheers,
> >> Bernard
> >> --
> >> perl -le '$#="Just Another Perl Hacker"; print \Bernard'
> >
> >Thanks. Bernard
> >
> >What to do if I want to print out the original string with $1 after
that?
>
> I don't understand the question. You've got the original string in
> $input_string (or wherever you have it) and the URL part in $1. You can
> do whatever you want with that.
>
> Cheers,
> Bernard
> --
> perl -le '$#="Just Another Perl Hacker"; print \Bernard'
Bernard
Suppose I want to print the original string on a html page and use $1 as a
html link.
BTW, your regexp deletes the " " and ( ) from the string when I print it
out, and does not work for the string:
My ISP's URL:<http://www.myisp.com>
Regards
Bill
------------------------------
Date: Fri, 08 Dec 2000 14:07:11 GMT
From: jrogers42@hotmail.com
Subject: Re: Help with metacharacters and search and replace
Message-Id: <90qpub$fki$1@nnrp1.deja.com>
In article <90ouha$ejg$1@news.warwick.net>,
"kcount" <kcount@ardenhouse.com> wrote:
> or, if you know the scalar is always going to be in the same format,
and
> just want to simply get rid of the comma...
>
> $line =~ s/,/\t/; # to replace with a tab.
>
> $line =~s/,/ /; # to replace with a space.
>
>
The thing is that I won't always know what the format will be, cause
I'm pulling the delimiter in from a file. So if I pull in \t from a
file and store it in a scalar. How do I set up s/// so that it sees the
stored \t has a tab and not a \t?
Jason
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Fri, 08 Dec 2000 14:03:38 GMT
From: Daniel Berger <djberg96@my-deja.com>
Subject: Re: How do I bring up the printer dialog via perl?
Message-Id: <90qpnm$fh9$1@nnrp1.deja.com>
> A million monkeys weren't enough! It took Daniel Berger <djberg96@my-
> deja.com> on 06 Dec 2000 to produce <90lkvd$a52$1@nnrp1.deja.com>:
Eh?
> You may need to use Win32::API
> (get it at http://www.perl.com/CPAN/authors/Aldo_Calpini/ )
>
> use Win32::API;
> Win32::API( 'comdlg32', 'GetOpenFileName', [P],N );
> die "cannot load function: $!" unless defined $GetOpenFileName;
>
> $GetOpenFileName->call(...)
>
> See the ActiveState docs.
Thanks...I think.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Fri, 08 Dec 2000 09:37:33 -0500
From: Lou Moran <lmoran@wtsg.com>
Subject: List Values and Arrays
Message-Id: <qcr13t08gdmoonds0sk5p0mddvtpue7pjl@4ax.com>
--While reading PP3 I came across something I don't understand. Then
the next paragraph said:
"Got that? (If not, you'd better reread thit paragraph, because it's
important.)"
--So I did. And I still didn't get it. So I looked elswhere, typed
the code and ran it and I still don't get it. So I am turning to you
folks, becuase you seem to get all of this stuff.
OK... PP3 says that:
@stuff = ("one", "two", "three")
returns the entire list. I proved this (to myself) by adding:
print @stuff
which returned "onetwothree". great.
PP3 then says that:
$stuff = ("one", "two", "three")
returns "three" b/c the final comma gets rid of everything before it
b/c it is a scalar which can only contain 1 of something and it knows
that. Adding:
print $stuff
which returned "three". Perfect.
Now:
@stuff = ("one", "two", "three");
$stuff = @stuff;
print $stuff
returns "3" (which PP3 said it would) not "three" (which I was not
expecting) nor "onetwothree" (which I was expecting.)
So why 3? 3 wasn't even one of the choices. I understand that @stuff
holds 3 things, but I don't understand why the scalar gets a count of
the array instead of the array's contents as one " " thing. (i.e
"onetwothree")
So why does that happen? And when would that be useful? (Word
counting script?)
mmmmm... pointy
lmoran@wtsg.com
------------------------------
Date: Fri, 08 Dec 2000 14:58:40 GMT
From: erictwx@my-deja.com
Subject: Re: List Values and Arrays
Message-Id: <90qsus$i6q$1@nnrp1.deja.com>
In article <qcr13t08gdmoonds0sk5p0mddvtpue7pjl@4ax.com>,
Lou Moran <lmoran@wtsg.com> wrote:
> --While reading PP3 I came across something I don't understand. Then
> the next paragraph said:
>
> "Got that? (If not, you'd better reread thit paragraph, because it's
> important.)"
>
> --So I did. And I still didn't get it. So I looked elswhere, typed
> the code and ran it and I still don't get it. So I am turning to you
> folks, becuase you seem to get all of this stuff.
>
> OK... PP3 says that:
>
> @stuff = ("one", "two", "three")
>
> returns the entire list. I proved this (to myself) by adding:
>
> print @stuff
>
> which returned "onetwothree". great.
>
> PP3 then says that:
>
> $stuff = ("one", "two", "three")
>
> returns "three" b/c the final comma gets rid of everything before it
> b/c it is a scalar which can only contain 1 of something and it knows
> that. Adding:
>
> print $stuff
>
> which returned "three". Perfect.
>
> Now:
>
> @stuff = ("one", "two", "three");
> $stuff = @stuff;
> print $stuff
>
This return 3 because when evaluated in scalar context, a list returns
the number of elements in the list.
> returns "3" (which PP3 said it would) not "three" (which I was not
> expecting) nor "onetwothree" (which I was expecting.)
>
> So why 3? 3 wasn't even one of the choices. I understand that @stuff
> holds 3 things, but I don't understand why the scalar gets a count of
> the array instead of the array's contents as one " " thing. (i.e
> "onetwothree")
>
> So why does that happen? And when would that be useful? (Word
> counting script?)
>
It would be useful in this statement:
for($x = 0; $x < @stuff; $x++) {
print "$stuff[$x]\n";
}
> mmmmm... pointy
>
> lmoran@wtsg.com
>
- Eric
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Fri, 8 Dec 2000 10:15:37 -0500
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: List Values and Arrays
Message-Id: <Pine.GSO.4.21.0012081008230.19543-100000@crusoe.crusoe.net>
[posted & mailed]
On Dec 8, Lou Moran said:
>@stuff = ("one", "two", "three")
This is a list assignment to an array. Good that you understand that.
>$stuff = ("one", "two", "three")
This is the comma operator at work, which evaluates its left-hand operand,
discards the results, and returns its right-hand operand. Thus, $stuff
gets "three". Good that you understand that.
>@stuff = ("one", "two", "three");
>$stuff = @stuff;
>So why does that happen? And when would that be useful? (Word
>counting script?)
When an array is evaluated in scalar context, it retuns the number of
elements it contains. This is useful because it's an easy way of
determining the number of elements, or if the array is empty:
if (@names) {
# @names has at least one element
}
if (@names > 4) {
# there are at least 5 people here
}
Perl is more of a natural language than a programming language, in that it
has rules of context that many other languages don't. When I say "dog",
you don't know if I mean the noun, the verb, or the adjective. You need
context around it. "I hate dogs." "I am dog-tired." "The dog catcher
dogged a dog during the dog days of summer and got dog-tired."
--
Jeff "japhy" Pinyan japhy@pobox.com http://www.pobox.com/~japhy/
CPAN - #1 Perl Resource (my id: PINYAN) http://search.cpan.org/
PerlMonks - An Online Perl Community http://www.perlmonks.com/
The Perl Archive - Articles, Forums, etc. http://www.perlarchive.com/
------------------------------
Date: Fri, 08 Dec 2000 10:48:37 -0500
From: Lou Moran <lmoran@wtsg.com>
Subject: Re: List Values and Arrays
Message-Id: <jk023tgqcqn0j6h3n8tmbbg4a6ulsm7n38@4ax.com>
On Fri, 8 Dec 2000 10:15:37 -0500, Jeff Pinyan <jeffp@crusoe.net>
wrote wonderful things about sparkplugs:
[Snipped and read]
>When an array is evaluated in scalar context, it retuns the number of
>elements it contains. This is useful because it's an easy way of
>determining the number of elements, or if the array is empty:
>
> if (@names) {
> # @names has at least one element
> }
> if (@names > 4) {
> # there are at least 5 people here
> }
>
>Perl is more of a natural language than a programming language, in that it
>has rules of context that many other languages don't. When I say "dog",
>you don't know if I mean the noun, the verb, or the adjective. You need
>context around it. "I hate dogs." "I am dog-tired." "The dog catcher
>dogged a dog during the dog days of summer and got dog-tired."
Thank you for your explanation. Please have them include your
explanation next time!
mmmmm... pointy
lmoran@wtsg.com
------------------------------
Date: Fri, 8 Dec 2000 11:02:42 -0500
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: List Values and Arrays
Message-Id: <Pine.GSO.4.21.0012081057180.19543-100000@crusoe.crusoe.net>
[posted & mailed]
On Dec 8, erictwx@my-deja.com said:
>> @stuff = ("one", "two", "three");
>> $stuff = @stuff;
>> print $stuff
>>
>This return 3 because when evaluated in scalar context, a list returns
>the number of elements in the list.
No. You have to make sure you understand this difference. There is no
such thing as a list in scalar context.
An array in scalar context returns the number of elements.
--
Jeff "japhy" Pinyan japhy@pobox.com http://www.pobox.com/~japhy/
CPAN - #1 Perl Resource (my id: PINYAN) http://search.cpan.org/
PerlMonks - An Online Perl Community http://www.perlmonks.com/
The Perl Archive - Articles, Forums, etc. http://www.perlarchive.com/
------------------------------
Date: Fri, 08 Dec 2000 17:04:15 +0100
From: Abe Timmerman <abe@ztreet.demon.nl>
Subject: Re: Most efficient way of getting a random row from db query?
Message-Id: <f9023t8tu209ul05f9nsjj39epe4f9ei4m@4ax.com>
On Fri, 01 Dec 2000 16:00:01 GMT, Mike Cameron <mcameron@mirusweb.com>
wrote:
> This code works, but I would like to retreive the row as a hashref not
> an arrayref.
>
> # Select a random sale item from this category
>
> my $query = "SELECT * FROM products WHERE sale_start <= '2000-11-15'
> and sale_end >= '2000-11-15'";
> my $sth = $dbh->prepare($query) || die $sth->errstr;
> $sth->execute() || die $sth->errstr;
> my $saleItems=$sth->fetchall_arrayref();
> my $rand = int(rand (@$saleItems));
> my $randomSaleItem = $saleItems->[$rand];
That could be a strain on memory.
> Should I loop through the records like so?
>
> # Query code omitted ...
>
> my $randomSaleItem = "";
> my $rand = int(rand ($sth->rows()));
> my $index =0;
> while ($randomSaleItem=$sth->fetchrow_hashref()){
> last if $rand == $index++;
> }
> # Should now have a random hashref in $randomSaleItem
This is from the DBI documentation:
rows
$rv = $sth->rows;
Returns the number of rows affected by the last row affecting
command, or -1 if not known or not available.
Generally you can only rely on a row count after a *non*-select
`execute' (for some specific operations like update and delete) or
after fetching *all* the rows of a select statement.
...
I modified the FAQ answer for "How do I select a random line from a
file?"
(query prepare() omitted)
$sth->execute();
my $randomSaleItem;
{
local($_, $.);
rand(++$.) < 1 && ($randomSaleItem = $_)
while $_ = $sth->fetchrow_hashref;
}
--
Good luck,
Abe
perl -wle '$_=q@Just\@another\@Perl\@hacker@;print qq@\@{[split/\@/]}@'
------------------------------
Date: Fri, 8 Dec 2000 08:19:16 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Multiple line regular expressions
Message-Id: <slrn931nuk.tk.tadmc@magna.metronet.com>
qades <qades@my-deja.com> wrote:
>I have to delete <script></script> tags from a bunch of html-files. What
>I tried is read the file into a variable and do a
>
> s/<script.*<\/script>//ig;
^^
^^
You do not want greedy matching. You're going to end up discarding
a lot more than you want to if there are multiple scripts
in the page ...
>you can imaging that this didn't work for multiple line scripts. I
>thought [.\n]* would work but now i know better :) So anybody knows
>the/one right syntax?
^^^^^^^^^^^^^^^^
There isn't one, there is, as usual in Perl, a bunch.
I make it non-greedy, and use an alternate delimiter:
s#<script.*?</script>##isg;
s#<script[\d\D]*?</script>##ig;
s#<script[\w\W]*?</script>##ig;
s#<script[\s\S]*?</script>##ig;
s#<script(.|\n)*?</script>##ig;
s#<script[\000-\377]*?</script>##ig;
Note that processing HTML with regular expressions is fraught
with danger. You should use a module that understands HTML
for processing HTML.
For instance, I expect your (and mine as well, since I am
Being Bad above too) approach would change:
<!-- need to add a <script> tag here for the frobish capability -->
<p>Welcome to the frobish web page<p>
<script> Iamcode </script>
<p>This is the place for all things frobish<p>
into
<!-- need to add a
<p>This is the place for all things frobish<p>
Probably Not So Good...
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 08 Dec 2000 15:13:27 GMT
From: rzilavec@tcn.net (Richard Zilavec)
Subject: Re: newbie question about flatfiles
Message-Id: <3a30f852.346117525@news.tcn.net>
>
>The best way to accomplish your task is to get something working
>and show it to the customer. Then fix what the customer does not
>like. Flat file is as good as anything else from that point of
>view.
I have to agree with Chris, most customers like to see working
programs, even if they don't meet all the needs. You can always alter
the current code, and you have a basic understanding of what the
customer wants, so be creative.
Depending on what the customer wants to do with the results will give
you a good idea on how to store it. If its just going to be viewed
through a web browser store it in html format. Then you could just
dump it to the screen:
print <<EOF;
<html>
<body>
EOF
open(IN, file);
for(<IN>) { print; }
close(IN);
etc.....
If the customer needs to do reports with the data, you might consider
using a properly delimited file, so you can extract information,
Sprite.pm is pretty good for that task.
Richard
Richard Zilavec
rzilavec@tcn.net
------------------------------
Date: Fri, 08 Dec 2000 15:19:49 GMT
From: "Daniel W. Burke" <dwb1@home.com>
Subject: number vs string
Message-Id: <Pine.LNX.4.20.0012081016490.29457-100000@ethyl.addictmud.org>
Hello,
What is the best, most warning-free method of testing if a scalar
is a number or a string?
I have a situation where I'm pulling data from a database, and
based on some conditions, the field I need to compair could be
a number or a string. I don't appear to have a way of knowing
ahead of time what kind of value it is, so compairsons I do
like this give warnings on character fields:
if (length($var) == 0 || ($var < 1)
Is there a way ahead of time to check that... like,
if ( (ischar($var) && (length($var) == 0)) ||
(isnum($var) && ($var < 1)
)
Or am I dooooooooooomed?
Dan.
------------------------------
Date: Fri, 08 Dec 2000 15:33:58 GMT
From: rzilavec@tcn.net (Richard Zilavec)
Subject: Re: number vs string
Message-Id: <3a31fea7.347738899@news.tcn.net>
if($var /^$/ || ($var =~ /^\d+$/ && $var < 1)) {
Hmmmmm, maybe :)
On Fri, 08 Dec 2000 15:19:49 GMT, "Daniel W. Burke" <dwb1@home.com>
wrote:
>
>
>Hello,
>
>
>What is the best, most warning-free method of testing if a scalar
>is a number or a string?
>
>I have a situation where I'm pulling data from a database, and
>based on some conditions, the field I need to compair could be
>a number or a string. I don't appear to have a way of knowing
>ahead of time what kind of value it is, so compairsons I do
>like this give warnings on character fields:
>
>if (length($var) == 0 || ($var < 1)
>
>Is there a way ahead of time to check that... like,
>
>if ( (ischar($var) && (length($var) == 0)) ||
> (isnum($var) && ($var < 1)
> )
>
>Or am I dooooooooooomed?
>
>Dan.
>
>
Richard Zilavec
rzilavec@tcn.net
------------------------------
Date: Fri, 8 Dec 2000 09:22:49 -0500
From: "Tulan W. Hu" <twhu@lucent.com>
Subject: Re: PERL based Web Application Servers
Message-Id: <90qr3p$5ub@nntpa.cb.lucent.com>
A mod_perl enabled Apache web server.
"Al Dev" <alavoor@yahoo.com> wrote in message
news:3A2E60D0.D87466A9@yahoo.com...
> Can you recommed any PERL based Web Application Servers.
> I am planning to use PERL on linux.
------------------------------
Date: Fri, 8 Dec 2000 08:01:53 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Re(OT): Can this script be done in a one-liner with sed
Message-Id: <slrn931mu1.mt.tadmc@magna.metronet.com>
Tad McClellan <tadmc@metronet.com> wrote:
>For slick, it's hard to beat this directory lister:
>
> find . -print | sed -e 's,[^/]*/\([^/]*\)$,`--\1,' -e 's,[^/]*/,| ,g'
I don't mean to imply that _I_ wrote that. I better attribute it.
I don't think this is the original either, but it is where I,
in turn, scarfed it from.
I guess I copy/pasted it from a Deja web page:
----------------------------------------------------------------
Sun, 10 Aug 1997 22:40:58 comp.lang.perl.misc Thread 8 of 9
Lines 11 Re: Visual representation of UNIX DirectoriesNo responses
scribble@shoga.wwa.com Tushar Samant at WorldWide Access (tm) - Midwestern Int
roswell@umbc.edu writes:
>I'm looking for a visual representation of directories in UNIX. Any
>solutions are welcome.
Trying to reconstruct a command I had snarfed off the net long ago:
find . -print | sed -e 's,[^/]*/\([^/]*\)$,`--\1,' -e 's,[^/]*/,| ,g'
Perl would of course give more spectacular results, but this one is
just so sleek ...
----------------------------------------------------------------
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 8 Dec 2000 08:07:17 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Regular expression question
Message-Id: <slrn931n85.mt.tadmc@magna.metronet.com>
Jim Ley <jim@jibbering.com> wrote:
>The post seems to be cross-posted between comp.lang.javascript, and
>comp.lang.perl.misc, the above was of course javascript... weird
>cross-post.
Hmmph. My scorefile failed me again. Off to fix that...
:-)
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 8 Dec 2000 14:10:19 GMT
From: abigail@foad.org (Abigail)
Subject: Re: sending email to script?
Message-Id: <slrn931qub.gvd.abigail@tsathoggua.rlyeh.net>
On Thu, 07 Dec 2000 07:46:20 GMT, toon (toon@repost.com) wrote in comp.lang.perl.misc <URL: news:<071220000853454385%toon@repost.com>>:
++ Hi,
++
++ is it possible to have an email sent by, let's say Outlook, to a
++ perl/cgi script on the server and have this message parsed by the
++ script?
If you configure things appropriately, sure. But none of that have
anything to do with Perl, so you should be looking elsewhere.
Abigail
------------------------------
Date: Fri, 08 Dec 2000 14:22:25 GMT
From: Michael Fischer <fischerm@my-deja.com>
To: sholden@cs.usyd.edu.au
Subject: Re: Win32::Process::Create Question on Win98
Message-Id: <90qqqr$g7u$1@nnrp1.deja.com>
In article <slrn930qr8.jmb.sholden@pgrad.cs.usyd.edu.au>,
sholden@cs.usyd.edu.au wrote:
> It should be $error, not #error, but that may be a typo in your
post...
>
> I suspect that under win98 the 'winnt' directory doesn't exist and
thus
> the operation fails. FormatMessage says 'successfully' because you
> are passing it undef which it is treating is 0, which means no
error...
>
> Of course I have never used any of the win32 modules so what would
I'm just
> guessing...
Ok, so the #error was a mistake on my part (which explains the
operation completed successfully error :) ) and I picked the wrong
sample code to post but thanks to your help I was able to find the
problem. My problem is that in the real application I was doing
something along the lines of "C:/winnt/system32/notepad.exe" and the
system was correctly parsing that but the Win98 system didn't like it.
Thank you very much for your help. Sorry you had to witness by brain
fart. :)
Cheers,
--
Michael Fischer
fischerm@my-deja.com
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
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 5063
**************************************