[31412] in Perl-Users-Digest
Perl-Users Digest, Issue: 2664 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Nov 3 21:09:48 2009
Date: Tue, 3 Nov 2009 18:09:14 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 3 Nov 2009 Volume: 11 Number: 2664
Today's topics:
Re: "un-meta" the control characters <derykus@gmail.com>
Re: "un-meta" the control characters <ben@morrow.me.uk>
Re: "un-meta" the control characters (Randal L. Schwartz)
Anything to be done about utf8 regexp performance? <OJZGSRPBZVCX@spammotel.com>
Re: FAQ 6.12 Can I use Perl regular expressions to matc <nospam-abuse@ilyaz.org>
Re: FAQ 6.12 Can I use Perl regular expressions to matc <ben@morrow.me.uk>
Re: FAQ 7.27 How can I comment out a large block of Per <justin.0908@purestblue.com>
Re: How to process duplicate entries in tab separated f <raksha34@gmail.com>
Re: How to process duplicate entries in tab separated f <jegan473@comcast.net>
Re: How to process duplicate entries in tab separated f <jegan473@comcast.net>
Re: How to process duplicate entries in tab separated f <ben@morrow.me.uk>
regexpressions question <robin1@cnsp.com>
Re: regexpressions question <ben@morrow.me.uk>
Re: regexpressions question <kbradnam@gmail.com>
Re: regexpressions question <brandon.metcalf@rackspace.com>
rendering images from a database <cartercc@gmail.com>
Re: rendering images from a database <spamtrap@shermpendley.com>
Re: rendering images from a database <ben@morrow.me.uk>
Re: unintialised warning <justin.0908@purestblue.com>
Re: unintialised warning sharma__r@hotmail.com
Re: unintialised warning <spamtrap@shermpendley.com>
Re: unintialised warning <jurgenex@hotmail.com>
Re: unintialised warning <spamtrap@shermpendley.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 3 Nov 2009 09:48:43 -0800 (PST)
From: "C.DeRykus" <derykus@gmail.com>
Subject: Re: "un-meta" the control characters
Message-Id: <d799944a-37cf-4f70-acf5-0c6037b04a3c@f18g2000prf.googlegroups.com>
On Nov 2, 11:07=A0am, Paul Lalli <mri...@gmail.com> wrote:
> A coworker just presented me with this task. =A0I came up with two
> solutions, but I don't like either of them. =A0He has a text document
> and wants to scan it for characters such as newline, tab, form feed,
> carriage return, vertical tab. =A0If found, he wants to replace them
> with their typical representation (ie, \n, \t, \f, \r, \v).
>
> I first gave him the obvious:
> $string =3D~ s/\n/\\n/;
> $string =3D~ s/\t/\\t/;
> $string =3D~ s/\f/\\f/;
> $string =3D~ s/\r/\\r/;
> $string =3D~ s/\v/\\v/;
>
> which I don't like because of how much copy/paste is involved. =A0Then I
> came up with:
>
> for (qw/n t f r v/) {
> =A0 =A0my $meta =3D eval("\\$_");
> =A0 =A0$string =3D~ s/$meta/\\$_/;
>
> }
> ...
Did that work? I don't understand why the eval is needed
at all:
my $string =3D "1\n 2\t 3\f 4\r 5\cK";
for (qw/n t f r cK/) {
my $meta =3D "\\$_";
$string =3D~ s/$meta/\\$_/;
}
print $string; # 1\n 2\t 3\f 4\r 5\cK
--
Charles DeRykus
------------------------------
Date: Tue, 3 Nov 2009 19:18:39 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: "un-meta" the control characters
Message-Id: <f9c6s6-6ka.ln1@osiris.mauzo.dyndns.org>
Quoth "C.DeRykus" <derykus@gmail.com>:
> On Nov 2, 11:07 am, Paul Lalli <mri...@gmail.com> wrote:
> >
> > for (qw/n t f r v/) {
> > my $meta = eval("\\$_");
> > $string =~ s/$meta/\\$_/;
> >
> > }
>
> Did that work? I don't understand why the eval is needed
> at all:
>
> my $string = "1\n 2\t 3\f 4\r 5\cK";
> for (qw/n t f r cK/) {
> my $meta = "\\$_";
> $string =~ s/$meta/\\$_/;
> }
> print $string; # 1\n 2\t 3\f 4\r 5\cK
That's... evil. It relies on the fact that regexes undergo two separate
expansion phases, and requires that variable expansion happens in the
first phase but other qqish escapes are expanded in the second. I'm not
entirely convinced that's documented behaviour: anyone care to dig out
perlre and prove it one way or the other?
For extra added evil:
my $bs = "\\";
$string =~ s/$bs$_/$bs$_/g for qw/n r t f/;
Ben
------------------------------
Date: Tue, 03 Nov 2009 12:00:26 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: "un-meta" the control characters
Message-Id: <86skcv2xb9.fsf@blue.stonehenge.com>
>>>>> "Ben" == Ben Morrow <ben@morrow.me.uk> writes:
Ben> For extra added evil:
Ben> my $bs = "\\";
Ben> $string =~ s/$bs$_/$bs$_/g for qw/n r t f/;
And I thought *I* was being bad.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
------------------------------
Date: Wed, 04 Nov 2009 00:23:20 +0100
From: "Jochen Lehmeier" <OJZGSRPBZVCX@spammotel.com>
Subject: Anything to be done about utf8 regexp performance?
Message-Id: <op.u2udw61kmk9oye@frodo>
Hello,
> perl -V|head
Summary of my perl5 (revision 5 version 8 subversion 8) configuration:
Platform:
osname=linux, osvers=2.6.22-3-k7, archname=i486-linux-gnu-thread-multi
uname='linux k 2.6.22-3-k7 #1 smp mon oct 22 22:51:54 utc 2007 i686
gnulinux
> cat test.pl
#!/usr/local/bin/perl
use strict;
use warnings;
my $a = "a".("x" x 1000);
my $b = "\x{1234}".("x" x 1000);
for (0..1000)
{
$a =~ s/r/xxx/;
$a =~ s/r/xxx/i;
$b =~ s/r/xxx/;
$b =~ s/r/xxx/i;
}
> perl -d:SmallProf test.pl
^L ================ SmallProf version 2.02 ================
Profile of test.pl
Page 94
=================================================================
count wall tm cpu time line
0 0.00000 0.00000 1:#!/usr/local/bin/perl
0 0.00000 0.00000 2:
0 0.00000 0.00000 3:use strict;
0 0.00000 0.00000 4:use warnings;
0 0.00000 0.00000 5:
1 0.00005 0.00000 6:my $a = "a".("x" x 1000);
1 0.00006 0.00000 7:my $b = "\x{1234}".("x" x 1000);
0 0.00000 0.00000 8:
1 0.00000 0.00000 9:for (0..1000)
0 0.00000 0.00000 10:{
1001 0.00596 0.07000 11: $a =~ s/r/xxx/;
1001 0.01276 0.03000 12: $a =~ s/r/xxx/i;
1001 0.04787 0.14000 13: $b =~ s/r/xxx/;
1004 2.05547 2.10000 14: $b =~ s/r/xxx/i;
0 0.00000 0.00000 15:}
I can live with line 13, but line 14 is not funny anymore. 344 times
slower than a latin1 regexp... or 161 times slower than a
latin1-case-insentitive one.
I understand that case calculations are much more complex in utf8 than
latin1. Is there anything that can be done, anyway?
------------------------------
Date: Tue, 3 Nov 2009 23:22:52 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: FAQ 6.12 Can I use Perl regular expressions to match balanced text?
Message-Id: <slrnhf1eqc.e4l.nospam-abuse@powdermilk.math.berkeley.edu>
On 2009-11-03, Ben Morrow <ben@morrow.me.uk> wrote:
> Using lexicals in (?{}) assertions is known to sometimes cause crashes
> and other weird behaviour (this is indeed a bug, but a known one that is
> difficult to fix
I think they are very easy to fix... (At the time I created this
feature, I have not yet fully understood how closures are implemented,
so missed one case.)
Hope this helps,
Ilya
------------------------------
Date: Wed, 4 Nov 2009 00:24:52 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: FAQ 6.12 Can I use Perl regular expressions to match balanced text?
Message-Id: <k7u6s6-kac.ln1@osiris.mauzo.dyndns.org>
Quoth Ilya Zakharevich <nospam-abuse@ilyaz.org>:
> On 2009-11-03, Ben Morrow <ben@morrow.me.uk> wrote:
> > Using lexicals in (?{}) assertions is known to sometimes cause crashes
> > and other weird behaviour (this is indeed a bug, but a known one that is
> > difficult to fix
>
> I think they are very easy to fix... (At the time I created this
> feature, I have not yet fully understood how closures are implemented,
> so missed one case.)
Then please post a patch to p5p demonstrating the fix, since everyone
there seems to think it's rather tricky.
Ben
------------------------------
Date: Tue, 03 Nov 2009 15:13:39 -0000
From: Justin C <justin.0908@purestblue.com>
Subject: Re: FAQ 7.27 How can I comment out a large block of Perl code?
Message-Id: <7b5.4af048a3.9663c@zem>
On 2009-10-31, ccc31807 <cartercc@gmail.com> wrote:
> On Oct 31, 11:00 am, PerlFAQ Server <br...@theperlreview.com> wrote:
>> 7.27: How can I comment out a large block of Perl code?
>
> This doesn't necessarily need to be a Perl issue. While it's true that
> Perl doesn't have multi-line comments like C or Java, you might be
> able to do the same thing with your editor using single line comments.
> The big advantage comes when you are testing a large block -- you
> don't have to keep moving the start of your multi-line comment and you
> can see exactly what code is running and what isn't.
>
> For example, in vi, to comment lines 231 through 317, do
>:231,317 s/^/#/
> which will replace the beginning of the line with #.
>
> To remove the comments from lines 245 through 277, do
>:245,277 s/#//
> which will replace # with nothing (therefore removing it).
>
> This is so useful that I find myself doing it while writing Java,
> instead of using the multi-line Java comments.
If we're giving editor tips, then to achieve the same in TextMate,
select the lines you want to comment and press
Command+/
Selecting the text and running the same command reverses the action too.
Justin.
--
Justin C, by the sea.
------------------------------
Date: Tue, 3 Nov 2009 08:31:40 -0800 (PST)
From: Viking <raksha34@gmail.com>
Subject: Re: How to process duplicate entries in tab separated file?
Message-Id: <4b04b48a-4bb7-4a40-8637-d67e0956f233@w37g2000prg.googlegroups.com>
On Nov 2, 6:30=A0am, James Egan <jegan...@comcast.net> wrote:
> In the __DATA__ below, there are two duplicate entries which occur twice,
> 07020000279 and 05020004293, which are customer numbers. =A0What I need t=
o
> do is find any duplicate customer numbers in a file, and print (write)
> them. =A0
>
> -Thanks
>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
>
> use vars qw(
> =A0 @file
> =A0 @fields
> =A0 $fields
> =A0 $line
> =A0 $ctr
> =A0 $custno
> =A0 @customers
> );
>
> =A0 while ( <DATA> ) {
> =A0 =A0 push(@file, $_);
> =A0 }
>
> my @matches =3D grep $line eq '07020000279', @file;
>
> foreach $line (@file) {
>
> print $line;
>
> }
>
> __DATA__
> 07020000279 =A0 =A0 Joe =A0 =A0 Smith =A0 54 Abbey Road
> 05020033486 =A0 =A0 John Jones =A0 =A0 =A098 New York Ave.
> 07020000279 =A0 =A0 George Washington =A0 =A0 =A0 234 Washington Ave.
> 06020004293 =A0 =A0 Fred Flintstone 123 Main St.
> 05020004293 =A0 =A0 Wilma Flintstone =A0 =A0 =A0 =A0Bedrock Road
> 0302004472 =A0 =A0 =A0Fred Jones =A0 =A0 =A098 New York Ave.
Don't use global variables when lexical variables would do.
#!/usr/bin/perl
use strict;
use warnings;
local $\ =3D qq{\n}; # auto-append newlines to every print
my %h;
while (<DATA>) {
chomp; next unless /\S/;
my $custno =3D (split)[0];
print $custno if exists $h{$custno};
$h{$custno}++;
}
------------------------------
Date: Wed, 04 Nov 2009 00:01:16 GMT
From: James Egan <jegan473@comcast.net>
Subject: Re: How to process duplicate entries in tab separated file?
Message-Id: <gv3Im.110148$Ca6.88087@en-nntp-03.dc1.easynews.com>
On Tue, 03 Nov 2009 08:31:40 -0800, Viking wrote:
Using your solution below, the only thing that is output is:
07020000279
What I'm trying to do is print each record, BUT if there are two or three
records with the same customer number, print those out consecutively.
#!/usr/bin/perl
use strict;
use warnings;
use vars qw(
@file
@fields
$fields
$line
$ctr
$custno
@customers
);
local $\ = qq{\n};
my %h;
while (<DATA>) {
chomp; next unless /\S/;
my $custno = (split)[0];
print $custno if exists $h{$custno};
$h{$custno}++;
}
__DATA__
07020000279 Joe Smith 54 Abbey Road
05020033486 John Jones 98 New York Ave.
07020000279 George Washington 234 Washington Ave.
06020004293 Fred Flintstone 123 Main St.
05020004293 Wilma Flintstone Bedrock Road
0302004472 Fred Jones 98 New York Ave.
------------------------------
Date: Wed, 04 Nov 2009 00:08:48 GMT
From: James Egan <jegan473@comcast.net>
Subject: Re: How to process duplicate entries in tab separated file?
Message-Id: <kC3Im.110442$Ca6.39009@en-nntp-03.dc1.easynews.com>
On Mon, 02 Nov 2009 05:10:18 -0800, ccc31807 wrote:
> On Nov 1, 8:30Â pm, James Egan <jegan...@comcast.net> wrote:
>> In the __DATA__ below, there are two duplicate entries which occur
>> twice, 07020000279 and 05020004293, which are customer numbers. Â What I
>> need to do is find any duplicate customer numbers in a file, and print
>> (write) them.
>
> Use a hash to store your data, with the customer number as the key to
> the hash. The keys of a hash are guaranteed to be unique, therefore you
> will never have a duplicate entry.
>
> Then, when you are initializing the hash from the data, test each hash
> key to see if it has already been initialized, and if it has, write the
> record to an error file. Something like this (untested)
>
> while (<DATA>)
> {
> chomp;
> my ($id, $fn, $ln, $addy) = split;
> print "$id is duplicate: $fn $ln, $addy\n" if $customers{$id};
> $customers{$id} = "$fn, $ln, $addy" unless $customer{$key};
> }
What I'm trying to do is IF there are duplicate customer numbers, then
print them consecutively. So the __DATA__ below printed out would look
like this, with duplicate customers printed together, and unique
customers printed as they are like:
07020000279 Joe Smith 54 Abbey Road
07020000279 George Washington 234 Washington Ave.
05020033486 John Jones 98 New York Ave.
06020004293 Fred Flintstone 123 Main St.
05020004293 Wilma Flintstone Bedrock Road
03020004472 Fred Jones 98 New York Ave.
__DATA__
07020000279 Joe Smith 54 Abbey Road
05020033486 John Jones 98 New York Ave.
07020000279 George Washington 234 Washington Ave.
06020004293 Fred Flintstone 123 Main St.
05020004293 Wilma Flintstone Bedrock Road
03020004472 Fred Jones 98 New York Ave.
------------------------------
Date: Wed, 4 Nov 2009 00:28:45 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: How to process duplicate entries in tab separated file?
Message-Id: <teu6s6-kac.ln1@osiris.mauzo.dyndns.org>
Quoth James Egan <jegan473@comcast.net>:
> On Mon, 02 Nov 2009 05:10:18 -0800, ccc31807 wrote:
>
> > On Nov 1, 8:30Â pm, James Egan <jegan...@comcast.net> wrote:
> >> In the __DATA__ below, there are two duplicate entries which occur
> >> twice, 07020000279 and 05020004293, which are customer numbers. Â What I
> >> need to do is find any duplicate customer numbers in a file, and print
> >> (write) them.
> >
> > Use a hash to store your data, with the customer number as the key to
> > the hash. The keys of a hash are guaranteed to be unique, therefore you
> > will never have a duplicate entry.
> >
> > Then, when you are initializing the hash from the data, test each hash
> > key to see if it has already been initialized, and if it has, write the
> > record to an error file. Something like this (untested)
> >
> > while (<DATA>)
> > {
> > chomp;
> > my ($id, $fn, $ln, $addy) = split;
> > print "$id is duplicate: $fn $ln, $addy\n" if $customers{$id};
> > $customers{$id} = "$fn, $ln, $addy" unless $customer{$key};
> > }
>
>
> What I'm trying to do is IF there are duplicate customer numbers, then
> print them consecutively. So the __DATA__ below printed out would look
> like this, with duplicate customers printed together, and unique
> customers printed as they are like:
So, what does your code currently look like, and where are you having
difficulties?
Ben
------------------------------
Date: Tue, 3 Nov 2009 13:53:07 -0700
From: "Robin" <robin1@cnsp.com>
Subject: regexpressions question
Message-Id: <hcq56v$28j2$1@adenine.netfront.net>
How can I place everything the =~ operator has matched into an arrayy?
Thank you in advance.
peace,
--
Robin
--
robin1@cnsp.com
------------------------------
Date: Tue, 3 Nov 2009 21:42:32 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: regexpressions question
Message-Id: <8nk6s6-1fb.ln1@osiris.mauzo.dyndns.org>
Quoth "Robin" <robin1@cnsp.com>:
> How can I place everything the =~ operator has matched into an arrayy?
You will need to be more specific about what you want. You might want
my @array = $string =~ /pattern/g;
but it's hard to be sure.
Ben
------------------------------
Date: Tue, 3 Nov 2009 13:49:42 -0800 (PST)
From: Keith Bradnam <kbradnam@gmail.com>
Subject: Re: regexpressions question
Message-Id: <8d04ca8f-13a3-40d5-b4be-e978e77611ef@a37g2000prf.googlegroups.com>
On Nov 3, 12:53=A0pm, "Robin" <rob...@cnsp.com> wrote:
> How can I place everything the =3D~ operator has matched into an arrayy?
>
> Thank you in advance.
Do you mean that you want everything that is matched to become the
first element of an array? If not, maybe it would help to illustrate
the type of data that you are working with?
K.
------------------------------
Date: Tue, 03 Nov 2009 16:17:02 -0600
From: Brandon Metcalf <brandon.metcalf@rackspace.com>
Subject: Re: regexpressions question
Message-Id: <slrnhf17vk.5ru.brandon.metcalf@office101-110.rackspace.com>
On 2009-11-03, Robin <robin1@cnsp.com> wrote:
> How can I place everything the =~ operator has matched into an arrayy?
$ cat jj
#!/usr/bin/perl -l
use strict;
use warnings;
my $string = '123aaa';
my ($p1,$p2) = ($string =~ /(\d+)(\w+)/);
print $p1;
print $p2;
$ ./jj
123
aaa
--
Brandon
------------------------------
Date: Tue, 3 Nov 2009 10:09:48 -0800 (PST)
From: ccc31807 <cartercc@gmail.com>
Subject: rendering images from a database
Message-Id: <e58a406c-2bbf-4c7e-af09-58df70fd82ce@v25g2000yqk.googlegroups.com>
If you have a table in a database with an ID field (int), name
(varchar), a content-type field (varchar) and a data field (blob), and
you have binary data in the data field (like GIFs, JPEGs, PDFs, etc.),
you can display these directly in a new HTML page. A query from the
the database returns this:
id =3D> 666
name =3D> greg.jpg
content-type =3D> image/jpeg
data =3D> =05&w`l *=EF=BF=BD m :=EF=BF=BD=EF=BF=BDm=01F=EF=BF=BD=CE=84=14=
=EF=BF=BDA=EF=BF=BD4d=EF=BF=BD=EF=BF=BD
How would you embed this data in an HTML page with a Content-Type of
text/html? The <img> element needs a src attribute, which I don't
have, and the <object> element likewise needs a URI for the data
attribute.
I can certainly display the "data" from the database, but it's
character based data (clubs, diamonds, hearts, and spades) rather than
the nice, pretty picture that's really there. Is there a PM that can
take a binary and turn it into something that will look like an image
in a browser?
Thanks, CC.
------------------------------
Date: Tue, 03 Nov 2009 13:16:27 -0500
From: Sherm Pendley <spamtrap@shermpendley.com>
Subject: Re: rendering images from a database
Message-Id: <m2fx8va2ys.fsf@shermpendley.com>
ccc31807 <cartercc@gmail.com> writes:
> If you have a table in a database with an ID field (int), name
> (varchar), a content-type field (varchar) and a data field (blob), and
> you have binary data in the data field (like GIFs, JPEGs, PDFs, etc.),
> you can display these directly in a new HTML page. A query from the
> the database returns this:
> id => 666
> name => greg.jpg
> content-type => image/jpeg
> data => &w`l *� m :��mF�΄�A�4d��
>
> How would you embed this data in an HTML page with a Content-Type of
> text/html? The <img> element needs a src attribute
The src attribute can refer to a script, i.e. "src='image.pl?id=666'".
Then in image.pl, you'd fetch the image data and send it.
sherm--
------------------------------
Date: Tue, 3 Nov 2009 19:22:18 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: rendering images from a database
Message-Id: <agc6s6-6ka.ln1@osiris.mauzo.dyndns.org>
Quoth Sherm Pendley <spamtrap@shermpendley.com>:
> ccc31807 <cartercc@gmail.com> writes:
>
> > If you have a table in a database with an ID field (int), name
> > (varchar), a content-type field (varchar) and a data field (blob), and
> > you have binary data in the data field (like GIFs, JPEGs, PDFs, etc.),
> > you can display these directly in a new HTML page. A query from the
> > the database returns this:
> > id => 666
> > name => greg.jpg
> > content-type => image/jpeg
> > data => &w`l *� m :��mF�΄�A�4d��
> >
> > How would you embed this data in an HTML page with a Content-Type of
> > text/html? The <img> element needs a src attribute
>
> The src attribute can refer to a script, i.e. "src='image.pl?id=666'".
> Then in image.pl, you'd fetch the image data and send it.
This is the correct approach :). An alternative would be to construct a
data: url and supply that as the value of the src attribute. URI knows
how to correctly construct data: urls from arbitrary data; whether
browsers are willing to accept the very long urls necessary is another
matter entirely.
Ben
------------------------------
Date: Tue, 03 Nov 2009 15:32:07 -0000
From: Justin C <justin.0908@purestblue.com>
Subject: Re: unintialised warning
Message-Id: <880.4af04cf7.4c95f@zem>
On 2009-11-01, Andrew DeFaria <Andrew@DeFaria.com> wrote:
><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
> my $value ||= $PAR{$name}<br>
Why do you find it necessary to post over 100 lines of html just to
reply with one line? We understand your meaning by reading the text
that you post, not the code that your software generates. Please do
not post html here, plain-text only in this newsgroup.
Justin.
--
Justin C, by the sea.
------------------------------
Date: Tue, 3 Nov 2009 08:05:05 -0800 (PST)
From: sharma__r@hotmail.com
Subject: Re: unintialised warning
Message-Id: <5a4c9209-c1ad-4062-8015-34afaaeb2968@h14g2000pri.googlegroups.com>
On Nov 1, 8:32=A0pm, "John" <john1...@yahoo.com> wrote:
> Hi
>
> The following can cause a warning =A0if undefined
>
> my $value=3D$PAR{$name};
>
> What the best solution?
>
> my $value=3D$PAR{$name }or $value=3D'';
> or
> my $value=3D''; if (defined $PAR{$name}) {$value=3D$PAR{$name}}
> or
> is there a cleaner solution?
>
Not sure if it's a cleaner solution, but you could do this way:
##1
my $EMPTY_STR =3D q{};
my $value =3D ( !defined $name ) ? $EMPTY_STR # assign an empty
incase scalar $name not defined
: ( !exists $PAR{$name} ) ? $EMPTY_STR # assign an empty
incase key $name not found
: ( !defined $PAR{$name} ) ? $EMPTY_STR # assign an empty
incase key $name =3D> value undef
: $PAR{$name}# lastly get the
defined value against the key $name
;
##2
my $value =3D q{} if !defined $name or !exists $PAR{$name} or !defined
$PAR{$name};
$value ||=3D $PAR{$name};
--Rakesh
------------------------------
Date: Tue, 03 Nov 2009 11:16:09 -0500
From: Sherm Pendley <spamtrap@shermpendley.com>
Subject: Re: unintialised warning
Message-Id: <m2fx8vshx2.fsf@shermpendley.com>
Justin C <justin.0908@purestblue.com> writes:
> On 2009-11-01, Andrew DeFaria <Andrew@DeFaria.com> wrote:
>><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
>> my $value ||= $PAR{$name}<br>
>
> Why do you find it necessary to post over 100 lines of html just to
> reply with one line?
He knows he's being rude - he's been told that a thousand times. He
just doesn't care. My advice is, just killfile the a**hole and move on.
sherm--
------------------------------
Date: Tue, 03 Nov 2009 08:31:09 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: unintialised warning
Message-Id: <8im0f55sp0gcqkqk16c5nc053pv83kv5cb@4ax.com>
Justin C <justin.0908@purestblue.com> wrote:
>On 2009-11-01, Andrew DeFaria <Andrew@DeFaria.com> wrote:
>><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
>> my $value ||= $PAR{$name}<br>
>
>Why do you find it necessary to post over 100 lines of html just to
>reply with one line? We understand your meaning by reading the text
>that you post, not the code that your software generates. Please do
>not post html here, plain-text only in this newsgroup.
This has been discussed ad nauseum a while ago. Mr. DeFaria is resistant
to any attempt of reasoning and therefore ended up in most peoples
filters.
You must have missed that thread.
jue
------------------------------
Date: Tue, 03 Nov 2009 13:44:16 -0500
From: Sherm Pendley <spamtrap@shermpendley.com>
Subject: Re: unintialised warning
Message-Id: <m24opb78jj.fsf@shermpendley.com>
Jürgen Exner <jurgenex@hotmail.com> writes:
> This has been discussed ad nauseum a while ago. Mr. DeFaria is resistant
> to any attempt of reasoning and therefore ended up in most peoples
> filters.
Some *providers* even filter him, although I doubt it's personal; they
are probably just filtering broken HTML-only articles that lack the
correct MIME type header.
I use x-privat.org, for example, and I didn't even know he was still
posting here until now. Ignorance is indeed bliss in this case. :-)
sherm--
------------------------------
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:
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests.
#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 V11 Issue 2664
***************************************