[22191] in Perl-Users-Digest
Perl-Users Digest, Issue: 4412 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jan 16 03:06:06 2003
Date: Thu, 16 Jan 2003 00:05:08 -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 Thu, 16 Jan 2003 Volume: 10 Number: 4412
Today's topics:
$x =~ s!(\d+)%!$1/100!e; <istink@real.bad.com>
Re: $x =~ s!(\d+)%!$1/100!e; <bernard.el-hagin@DODGE_THISlido-tech.net>
Re: $x =~ s!(\d+)%!$1/100!e; <mgjv@tradingpost.com.au>
Re: $x =~ s!(\d+)%!$1/100!e; <jurgenex@hotmail.com>
Re: A Regular Problem <Jodyman@hotmail.com>
Re: A Regular Problem (Damian James)
Re: ActivePerl and file upload problem (Jay Tilton)
Another HTML parsing question (VisionHolderTech)
Re: Creating PDF files that include images (VisionHolderTech)
Re: DBI question with MySQL (Triniman)
find2perl on windows doesn't work correctly <yxiao@panix.com>
Re: find2perl on windows doesn't work correctly <yxiao@panix.com>
Re: Forced switch from PERL to ASP/VBSCRIPT. Where do I <flavell@mail.cern.ch>
Re: Matching entries in lists <krahnj@acm.org>
Outputting a binary file to the browser (AG)
Re: return value of backticks under DOS <koos_pol@NO.nl.JUNK.compuware.MAIL.com>
Suggestion: sub mysort(&?@) or (& @) <occitan@esperanto.org>
Re: sysopen problem (Ben Morrow)
Re: sysopen problem <goldbb2@earthlink.net>
use constant? <ie_qjzhu@yahoo.ie>
Re: use constant? <goldbb2@earthlink.net>
Re: Variable naming convention (Andrew Allaire)
Re: Variable naming convention <jurgenex@hotmail.com>
Re: Variable naming convention <uri@stemsystems.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 16 Jan 2003 01:40:58 -0500
From: istink <istink@real.bad.com>
Subject: $x =~ s!(\d+)%!$1/100!e;
Message-Id: <3E2653FA.DA68DAF@real.bad.com>
$x =~ s!(\d+)%!$1/100!e;
I'm trying to convert a string of characters into ASCII.
and then, change ASCII into convert.
-----------== Posted via Newsfeed.Com - Uncensored Usenet News ==----------
http://www.newsfeed.com The #1 Newsgroup Service in the World!
-----= Over 100,000 Newsgroups - Unlimited Fast Downloads - 19 Servers =-----
------------------------------
Date: Thu, 16 Jan 2003 06:48:06 +0000 (UTC)
From: Bernard El-Hagin <bernard.el-hagin@DODGE_THISlido-tech.net>
Subject: Re: $x =~ s!(\d+)%!$1/100!e;
Message-Id: <b05kj6$8bo$1@korweta.task.gda.pl>
In article <3E2653FA.DA68DAF@real.bad.com>, istink wrote:
> $x =~ s!(\d+)%!$1/100!e;
>
> I'm trying to convert a string of characters into ASCII.
> and then, change ASCII into convert.
<scratches head perlpexed>
Cheers,
Bernard
--
echo 42|perl -pe '$#="Just another Perl hacker,"'
------------------------------
Date: Thu, 16 Jan 2003 06:57:48 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: $x =~ s!(\d+)%!$1/100!e;
Message-Id: <slrnb2clvc.oq9.mgjv@verbruggen.comdyn.com.au>
On Thu, 16 Jan 2003 01:40:58 -0500,
istink <istink@real.bad.com> wrote:
^^^^^^^^^^^^^^^^^^^
Hmmm..
> $x =~ s!(\d+)%!$1/100!e;
>
> I'm trying to convert a string of characters into ASCII.
> and then, change ASCII into convert.
Could you please try to explain a bit more precisely what it is you're
trying to do? I'm afraid that what you are saying doesn't make much
sense.
What does "changing into convert" mean? And when you say "convert into
ASCII" do you mean the sort of thing that ord() and asc() do (see the
perlfunc documentation)? And why are you dividing by 100? Or are you
simply trying to find all numbvers that look like percentages in a
text and change them to fractions (which is what the code seems to be
doing)? If the latter, can you tell us why your code doesn't work the
way you want it to? Did you mean to add a /g flag as well?
$x =~ s!(\d+)%!$1/100!eg;
Martien
--
|
Martien Verbruggen | Unix is user friendly. It's just selective
Trading Post Australia | about its friends.
|
------------------------------
Date: Thu, 16 Jan 2003 07:18:53 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: $x =~ s!(\d+)%!$1/100!e;
Message-Id: <x1tV9.6211$_T6.4492@nwrddc01.gnilink.net>
istink wrote:
> $x =~ s!(\d+)%!$1/100!e;
>
> I'm trying to convert a string of characters into ASCII.
What is the format (= standard) of the original characters? EBCDIC? UTF-16?
Shift-JIS? Without some more information it is difficult to help, but maybe
Text::Iconv can solve your problem.
Or are the characters additionally encoded, like e.g. in Base-64? There are
modules on CPAN which can handle those conversions, too.
> and then, change ASCII into convert.
Personally I've never heard of a code page/charset/encoding/... standard
named convert.
jue
------------------------------
Date: Thu, 16 Jan 2003 04:11:03 GMT
From: "Jodyman" <Jodyman@hotmail.com>
Subject: Re: A Regular Problem
Message-Id: <rhqV9.12480$Dq.1247112@newsread2.prod.itd.earthlink.net>
"Abigail" <abigail@abigail.nl> wrote in message
[snip]
>
> Abigail
Long time no see! Welcome back.
Jody
------------------------------
Date: 16 Jan 2003 06:12:08 GMT
From: damian@qimr.edu.au (Damian James)
Subject: Re: A Regular Problem
Message-Id: <slrnb2cj9o.qgp.damian@puma.qimr.edu.au>
On 15 Jan 2003 22:56:01 GMT, Abigail said:
>Stephen Adam (00056312@brookes.ac.uk) wrote on MMMCDXXIV September
>MCMXCIII in <URL:news:945bf980.0301141921.61f2384c@posting.google.com>:
>?? $position = (@array =~ m/<P class=g>/);
>??
>?? Were $position does NOT hold a boolean value of if the string exists
>?? in the array but instead holds the value of its position.
>
>my $N = 1; # Indicates _second_ instance.
>my $RE = qr /<P class=g>/;
>
>my $i;
>my $p = (map {$_ -> [1]} grep {$$_ [0] =~ /$RE/} map {[$_, $i ++]} @array) [$N];
>
>$p now contains the require index, or undef if none is found.
Shirley, you mean:
my $p = ( grep $array[$_] =~ /$RE/, 0..$#array )[$N];
:)
--damian
------------------------------
Date: Thu, 16 Jan 2003 02:48:57 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: ActivePerl and file upload problem
Message-Id: <3e261cda.76947977@news.erols.com>
"George Jewell" <gjewell@usdatalink.com> wrote:
: Our production web server (Win2K) has ActivePerl 5.8 installed - I have a
: page which allows a user to upload a file to a folder. All works fine.
: However, on my in-house test server (configured the same way), when trying
: to upload the file, I get the following error message:
:
: Couldn't open d:\inetpub\users\upload/cgi-lib.[xxxx].1 ( The xxxx is
: usually a different 3 - 5 digit number.)
That's only half of a well formed error message. The other half would
tell why it failed. Fix it to get a better picture.
WAG: not a Perl problem, but one of permissions
------------------------------
Date: 15 Jan 2003 18:13:46 -0800
From: zkent@adelphia.net (VisionHolderTech)
Subject: Another HTML parsing question
Message-Id: <a2beb42f.0301151813.7a23af20@posting.google.com>
I have been reading the docs for HTML::Parser and ALL related modules
and am still just as confused. I have tried searching the usenet but
everyone seems to be wanting to REMOVE HTML tags -- I want EXTRACT and
PROCESS the stuff between them.
Scenario:
I am trying to extract data from tables on in HTML documents and
format them for input into a database. Each HTML file contains
several similar tables such as the one below. I want to:
1) open the file.
2) get the first table.
3) extract the data in the cells and process them.
4) format the data for database (CSV most likely).
5) get next table until eof.
Any advice? I know that HTML::Parser is probably the best tool but I
cannot figure out how to do the above task.
------------- the table (several in each file) --------------
<table>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td colspan="2"><b>Cosy Picci Duck</b></td>
</tr>
<tr>
<td><img src="image.gif" border="0"></td>
<td> <form action="" method=post>
<strong>Product Number: STFF027</strong><br>
<em><strong>Cosy Picci Duck (woven fur, with squeaker) (13 cm)
</strong></em><br>
Manufacturer's Item Number: EAN 091162<br>
<strong>Price: $40.00</strong><br>
Quantity:
<input type="text" name="quantity" size="3">
<br>
<input name=Submit type=submit value="Add to Cart">
</form></td>
</tr>
</table>
------------------------------
Date: 15 Jan 2003 18:32:19 -0800
From: zkent@adelphia.net (VisionHolderTech)
Subject: Re: Creating PDF files that include images
Message-Id: <a2beb42f.0301151832.58853263@posting.google.com>
(Mike Solomon) wrote in message
> I nead to create PDF files using Perl
>
> I have tried PDF::create which works but I can't include images using it.
>
> Does anyone know how to do this
>
Since the images are encoded in a PDF as ASCII codes (insert technical
jargon here), what if you made a PDF (manually) that included the
images and then cut the encoded parts out and stored it in an ASCII
file or database. You could then retrieve the encoded image and and
insert it into the PDF when needed. I have wanted to do this for a
year now on a project, but have not gotten to it yet. But that is my
idea on how to do it. Let me know if it works.
------------------------------
Date: 15 Jan 2003 16:23:17 -0800
From: jason.alphonse@alum.dartmouth.org (Triniman)
Subject: Re: DBI question with MySQL
Message-Id: <3b7960ec.0301151623.492c3c3c@posting.google.com>
You can use
my $row = $database_read->selectrow_hashref("SELECT COUNT(*) as c FROM
Requests WHERE uniqueid=99");
my $count = $row->{c};
You can get all the various methods by doing 'perldoc DBI' at the
command line.
off the top of my head:
$dbh->selectrow_hashref($sql); # gets one row, does the prepare and
execute automatically.
$dbh->selectrow_arrayref($sql);
$dbh->selectrow_array($sql);
$dbh->selectcol_arrayref($sql);
$dbh->selectall_hashref($sql);
$dbh->selectall_arrayref($sql);
"Christian Caron" <nospam@nospam.org> wrote in message news:<b04d9d$bj64@nrn2.NRCan.gc.ca>...
> Hi all,
>
> I'm executing this select statement:
>
> my $query = $database_read->prepare("SELECT COUNT(*) FROM Requests WHERE
> uniqueid=?");
> $query->execute($username) or die "$query->errstr\n";
> my $data = $query->fetchall_arrayref or die "$query->errstr\n";
> $query->finish;
> print "data = $data->[0][0]\n";
>
> Everything works fine, but isn't there a better way to get my result (count)
> than "$data->[0][0]"? If I print $data, I get a strange string (I guess it's
> a array reference as I requested it by "fetchall_arrayref"). Instead of
> using "fetchall_arrayref", could I use something else as I definitely know
> it will return only one result, the count?
>
> I read a bit the cpan.org documentation page about DBI, but I can't find a
> place where they would list all the possible commands.
>
> Thanks!
>
> Christian
------------------------------
Date: Thu, 16 Jan 2003 00:15:53 -0500
From: "Yang Xiao" <yxiao@panix.com>
Subject: find2perl on windows doesn't work correctly
Message-Id: <b05faf$f75$1@reader1.panix.com>
Hi all,
I'm trying to use find2perl to do the following
find2perl c:\ -size +10000 -exec dir {} \; >find.pl
#find.pl
#! C:\Perl\bin\perl.exe -w
eval 'exec C:\Perl\bin\perl.exe -S $0 ${1+"$@"}'
if 0; #$running_under_some_shell
use strict;
use File::Find ();
# Set the variable $File::Find::dont_use_nlink if you're using AFS,
# since AFS cheats.
# for the convenience of &wanted calls, including -eval statements:
use vars qw/*name *dir *prune/;
*name = *File::Find::name;
*dir = *File::Find::dir;
*prune = *File::Find::prune;
sub wanted;
sub doexec ($@);
# Traverse desired filesystems
File::Find::find({wanted => \&wanted}, 'c:\\');
exit;
sub wanted {
my ($dev,$ino,$mode,$nlink,$uid,$gid);
(($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) &&
(int(((-s _) + 511) / 512) > 1000) &&
doexec(0, 'dir','{}','\;');
}
use Cwd ();
my $cwd = Cwd::cwd();
sub doexec ($@) {
my $ok = shift;
my @command = @_; # copy so we don't try to s/// aliases to constants
for my $word (@command)
{ $word =~ s#{}#$name#g }
if ($ok) {
my $old = select(STDOUT);
$| = 1;
print "@command";
select($old);
return 0 unless <STDIN> =~ /^y/;
}
chdir $cwd; #sigh
system @command;
chdir $File::Find::dir;
return !$?;
}
but that doesn't work because it complains about this line "system
@command;"
seems to me the file name passwd to dir is incorrect, any ideas would be
approciated.
Thanks
Yang
------------------------------
Date: Thu, 16 Jan 2003 00:19:07 -0500
From: "Yang Xiao" <yxiao@panix.com>
Subject: Re: find2perl on windows doesn't work correctly
Message-Id: <b05fgh$f8u$1@reader1.panix.com>
"Yang Xiao" <yxiao@panix.com> wrote in message
news:b05faf$f75$1@reader1.panix.com...
> Hi all,
> I'm trying to use find2perl to do the following
> find2perl c:\ -size +10000 -exec dir {} \; >find.pl
>
> #find.pl
> #! C:\Perl\bin\perl.exe -w
> eval 'exec C:\Perl\bin\perl.exe -S $0 ${1+"$@"}'
> if 0; #$running_under_some_shell
>
> use strict;
> use File::Find ();
>
> # Set the variable $File::Find::dont_use_nlink if you're using AFS,
> # since AFS cheats.
>
> # for the convenience of &wanted calls, including -eval statements:
> use vars qw/*name *dir *prune/;
> *name = *File::Find::name;
> *dir = *File::Find::dir;
> *prune = *File::Find::prune;
>
> sub wanted;
> sub doexec ($@);
>
>
>
> # Traverse desired filesystems
> File::Find::find({wanted => \&wanted}, 'c:\\');
> exit;
>
>
> sub wanted {
> my ($dev,$ino,$mode,$nlink,$uid,$gid);
>
> (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) &&
> (int(((-s _) + 511) / 512) > 1000) &&
> doexec(0, 'dir','{}','\;');
> }
>
>
> use Cwd ();
> my $cwd = Cwd::cwd();
>
> sub doexec ($@) {
> my $ok = shift;
> my @command = @_; # copy so we don't try to s/// aliases to constants
> for my $word (@command)
> { $word =~ s#{}#$name#g }
> if ($ok) {
> my $old = select(STDOUT);
> $| = 1;
> print "@command";
> select($old);
> return 0 unless <STDIN> =~ /^y/;
> }
> chdir $cwd; #sigh
> system @command;
> chdir $File::Find::dir;
> return !$?;
> }
>
>
> but that doesn't work because it complains about this line "system
> @command;"
> seems to me the file name passwd to dir is incorrect, any ideas would be
> approciated.
>
> Thanks
> Yang
>
>
Hi,
The actual dir command is being mangled as
dirc:\/WINNT/ShellIconCache\
Yang
------------------------------
Date: Wed, 15 Jan 2003 18:28:25 CST
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Forced switch from PERL to ASP/VBSCRIPT. Where do I begin?
Message-Id: <Pine.LNX.4.40.0301152124230.22975-100000@lxplus067.cern.ch>
On Jan 15, Dan inscribed on the eternal scroll:
> Due to a merger of university departments, I am potentially being forced
> to change the way I do web development. I've always used PERL for my CGI
> development. I'm now being told by the new derpartment head that "he
> doesn't want PERL running on any of his servers; it's too CPU-intensive"
This is pure dogma, is it? Or is there an actual overloaded server
that you haven't mentioned yet?
> so I must now do all coding in VBScript/ASP. Where do I start?
Clearly you are (to put a positive spin on the situation) positioned
for broadening your expertise... but if it's done in such a completely
pointy-head-driven way it's hard to be enthusiastic about it.
My attitude to the individual languages would be irrelevant here. If
you had told me that the existing CGI scripts were written in COBOL
and you were being asked to translate them into Perl I would have said
much the same: "if it's not broken, don't fix it". Computing power is
still expanding at a considerable rate in terms of bangs per buck, and
if you have a working application that's getting just a bit too much
for existing hardware it should be much more cost-effective to throw
more-powerful hardware at it, than to completely redevelop it in a
different language.
If that isn't considered to be the right answer, then look at the
recognised techniques for speeding-up Perl CGI scripts - which
concentrate more on getting rid of the CGI startup overhead than on
rewriting the whole goddamned application.
Oh, I have this gut feeling you're about to tell us that you'll also
have to migrate from Apache to something proprietary from the Empire,
which will turn out to have significant non-compliances with even the
CGI specification, and no opportunity to apply any of the available
solutions (which are both portable and performant) that come free with
Apache and Apache-derived servers...
> Not only do I have to learn the language(s)/techniques, but I then have
> to recode all existing applications. Yay.
That's absurd.
I could cope with the idea of implementing new applications in a
different language; even with taking the opportunity to migrate to
a different language when a major overhaul is needed to some existing
software. But recoding for the sake of recoding, based on dogma (if
I'm reading your report right) sounds like madness to me.
> I'm doing a bit of a panic/scramble dance here...
It's not your fault. Take it calmly, don't do anything hasty.
good luck
--
PLEASE NOTE: comp.infosystems.www.authoring.cgi is a
SELF-MODERATED newsgroup. aa.net and boutell.com are
NOT the originators of the articles and are NOT responsible
for their content.
HOW TO POST to comp.infosystems.www.authoring.cgi:
http://www.thinkspot.net/ciwac/howtopost.html
------------------------------
Date: Thu, 16 Jan 2003 00:29:58 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Matching entries in lists
Message-Id: <3E25FC54.5026EA5C@acm.org>
Bernd Schandl wrote:
>
> schandl@gmx.net (Bernd Schandl) wrote in message news:<7b52b64e.0301100655.1a7035c3@posting.google.com>...
> > I have the following problem: I have a list where each entry is a telephone
> > number, a name and a category. In a second list, I have telephone numbers
> > (in the same format) and I want to check whether they appear in the first
> > list and if yes, what the corresponding name and category is. As an
> > additional difficulty, the numbers in the first list are not necessarily
> > complete numbers but rather the beginning of a telephone number (think area
> > code or company). So for the entry 12345678 in the second list, I want to be
> > able to find the entry (123,"Some company","work") in the first list. I only
> > need to find the first match.
> >
> > So my questions are:
> > - What is the best data structure for the first list? Some kind of array?
> > Two hashes?
> > - What is a good/efficient/elegant way to find an entry in the first list
> > matching a number from the second?
>
> Thanks a lot for the lively discussions. After considering what I read here
> and in a German newsgroup and thinking a bit by myself (!), I settled on the
> following solution. Assuming I have the first list in a hash %numcat,
> I wrote the following routine, which gets a number from the second list as
> an argument and returns a hash key (or undef if no fitting entry is found):
>
> sub findkey {
> my ( $number ) = @_;
> for ( keys( %numcat ) ) { if ( $number =~ /^$_/ ) { return $_ } }
If $number is the partial phone number you are searching for and the
keys from %numcat are the full phone numbers then this won't work.
for ( keys( %numcat ) ) { if ( "123" =~ /^1234567/ ) { return
"1234567" } }
/^$number/ and return $_ for keys %numcat;
Or you could use index:
index( $_, $number ) == 0 and return $_ for keys %numcat;
Or substr:
$number eq substr( $_, 0, length $number ) and return $_ for keys
%numcat;
> return undef;
> }
>
> This way I only do one comparison per hash entry. I did not bother to
> implement something like binary search through the hash because both of my
> lists have only something like 50 entries.
John
--
use Perl;
program
fulfillment
------------------------------
Date: 15 Jan 2003 23:19:12 -0800
From: ag269@columbia.edu (AG)
Subject: Outputting a binary file to the browser
Message-Id: <6c4429bb.0301152319.6d5a2b7d@posting.google.com>
In my PHP script, the readfile() function does the job
after appropriate headers, no matter what the format of the file is.
However, my perl script refuses to output zip and rar files. I wonder if anyone
can tell me the appropriate way to output these files.
Below is the snippet of my cgi code:
binmode(FILE);
binmode(STDOUT);
print STDOUT while(<FILE>);
close(FILE);
------------------------------
Date: Thu, 16 Jan 2003 08:08:45 +0100
From: Koos Pol <koos_pol@NO.nl.JUNK.compuware.MAIL.com>
Subject: Re: return value of backticks under DOS
Message-Id: <newscache$l6ps8h$ata$1@news.emea.compuware.com>
Bill Smith wrote (Wednesday 15 January 2003 05:32):
> "Koos Pol" <koos_pol@NO.nl.JUNK.compuware.MAIL.com> wrote in message
> news:newscache$36qp8h$fx9$1@news.emea.compuware.com...
>> backticks should not be used to catch returned values.
> Without context, 'returned values' sounds like the 'exit status' of the
> command. Backticks do not provide this. However, the OP makes it clear
> that he wants the STDOUT. This is the intended use of backticks.
>
> Bill
I hope you're satisfied with my response to Tad's in this same thread. It
has your name in it :-)
--
KP
------------------------------
Date: Thu, 16 Jan 2003 08:50:55 +0100
From: Daniel Pfeiffer <occitan@esperanto.org>
Subject: Suggestion: sub mysort(&?@) or (& @)
Message-Id: <20030116085055.3451b6ff.occitan@esperanto.org>
Hi,
it is inconsistent that functions like sort can have an optional first code
block, while if I declare mysort(&@) it becomes mandatory. Having to pass
undef as first argument, when you don't want it, is ugly. And having to put
a comma, beacause it's not a code block is also inconsistent with sort.
Now, if we could have a prototype like above (I don't care how, ? is as in
regexps, ' ' is because, if it's there, it has to be followed by a space, not
a comma, then this function would work like the original:
@list = mysort { ... } @list;
@list = mysort $subref @list;
@list = mysort @list;
The parser can already handle it, and it wouldn't break any compatibility.
coralament / best Grötens / liebe Grüße / best regards / elkorajn salutojn
Daniel Pfeiffer
-- GPL 3: take the wind out of Palladium's sails! --
------
-- My other stuff here too, sawfish, make.pl...: --
------
-- http://dapfy.bei.t-online.de/ --
------------------------------
Date: Thu, 16 Jan 2003 02:06:43 +0000 (UTC)
From: mauzo@mimosa.csv.warwick.ac.uk (Ben Morrow)
Subject: Re: sysopen problem
Message-Id: <b0543j$n7f$1@wisteria.csv.warwick.ac.uk>
"Neil Trenholm" <neil@alaweb.com> wrote:
>Now for embarrassing part - how would a person fully qualify these constant
>names, so as to avoid "no strict 'subs" ?
perldoc -f Fcntl
This may not work if you OS doesn't support the constants you need, in which
case there's nothing you can do (the functionality isn't there at all). The
ones you were using, however (I believe it was O_CREAT and O_EXCL?) should be
supported by any sensible OS.
Ben
------------------------------
Date: Wed, 15 Jan 2003 23:47:06 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: sysopen problem
Message-Id: <3E26394A.46846135@earthlink.net>
Neil Trenholm wrote:
[snip]
> Now for embarrassing part - how would a person fully qualify these
> constant names, so as to avoid "no strict 'subs" ?
Add parens:
O_RDWR()|O_CREAT()
--
$..='(?:(?{local$^C=$^C|'.(1<<$_).'})|)'for+a..4;
$..='(?{print+substr"\n !,$^C,1 if $^C<26})(?!)';
$.=~s'!'haktrsreltanPJ,r coeueh"';BEGIN{${"\cH"}
|=(1<<21)}""=~$.;qw(Just another Perl hacker,\n);
------------------------------
Date: Wed, 15 Jan 2003 22:45:08 -0800
From: "qjzhu" <ie_qjzhu@yahoo.ie>
Subject: use constant?
Message-Id: <b056bq$317u$1@mail.cn99.com>
Hi folks,
Please kindly point out what's wrong.
Header.pm:
our $va = 1;
use constant CONS => 1;
test.pl:
use warnings;
require Header;
if ($va == CONS) {
print "good\n";
} else {
print "bad\n";
}
the result is: (perl 5.8)
Argument "CONS" isn't numeric in numeric eq (==) at test.pl line 5.
bad
------------------------------
Date: Wed, 15 Jan 2003 23:50:43 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: use constant?
Message-Id: <3E263A23.18D02E70@earthlink.net>
qjzhu wrote:
>
> Hi folks,
>
> Please kindly point out what's wrong.
>
> Header.pm:
>
> our $va = 1;
> use constant CONS => 1;
>
> test.pl:
>
> use warnings;
> require Header;
use Header;
> if ($va == CONS) {
> print "good\n";
> } else {
> print "bad\n";
> }
>
> the result is: (perl 5.8)
>
> Argument "CONS" isn't numeric in numeric eq (==) at test.pl line 5.
> bad
--
$..='(?:(?{local$^C=$^C|'.(1<<$_).'})|)'for+a..4;
$..='(?{print+substr"\n !,$^C,1 if $^C<26})(?!)';
$.=~s'!'haktrsreltanPJ,r coeueh"';BEGIN{${"\cH"}
|=(1<<21)}""=~$.;qw(Just another Perl hacker,\n);
------------------------------
Date: 15 Jan 2003 17:08:57 -0800
From: Andrew.Allaire@na.teleatlas.com (Andrew Allaire)
Subject: Re: Variable naming convention
Message-Id: <6bdb91de.0301151708.5d0fdd6d@posting.google.com>
Uri Guttman <uri@stemsystems.com> wrote in message news:<x78yxmjj62.fsf@mail.sysarch.com>...
> >>>>> "AA" == Andrew Allaire <Andrew.Allaire@na.teleatlas.com> writes:
>
> AA> "J rgen Exner" <jurgenex@hotmail.com> wrote in message news:<Hx3V9.29498$%V.28678@nwrddc02.gnilink.net>...
> >> Andrew Allaire wrote:
> >> > falconflyr@snet.net (Pete) wrote in message
> >> > news:<4ca21189.0301140802.153b57a3@posting.google.com>...
> >> >> Is there a way to dynamically define a set of variable names such
> >> >> that the name itself consists of alpha and numeric characters, but
> [...]
> >> > I think you are going against camel hair here. Why not use an array?
> >> > But just for the sake of an obscure exercise you could handle it like
> >> > this:
> >> >
> >> > for (1..10) {
> >> > ${'name' . $_} = $_ ;
> >> > }
> >> >
> >> > print ( "name1 is $name1\n") ;
> >> > print ("name2 is $name2\n") ;
> >>
> >> If you feel the need to show symbolic references to someone who apparently
> >> doesn't know how to handle them, then it is gross negligent to not mention
> >> the FAQ and not to warn him about the dangers involved.
> >> To the OP: _please_(!) consult the FAQ on symbolic references before using
> >> the code above.
> >>
> >> jue
>
> AA> Thank you for mentioning the FAQ, but I have to take issue over it
> AA> being grossly negligent to give a snipet of code that does what the
> AA> person requested, when one proceeds it with warnings that it goes
> AA> agains camel hair, and is probably an obscure exercise, and that one
> AA> probably should be using an array. I was tempted to Not provide the
> AA> code, but then thought of the times I had requested some info from
> AA> people who lectured me about how I was doing it all wrong. Although I
> AA> can not think of a good reason for the request, I thought it better to
> AA> treat the person making it as an adult.
>
> that is not a good assumption to make. the OP is not the only reader of
> you post. showing a symref solution is bad form under ay circumstance
> even if it is requested. there is only one real reason to use symrefs
> and that is to access and modify the symbol table. using symrefs for
> general purpose data structures is evil. the symbol table is just a tree
> of hashes (and typeglobs) so there is no benefit to using it over a
> regular tree of hashes. and with the regular tree you gain many things
> including lexical scoping, OO, no action at a distance, no hard to find
> bugs, etc.
>
> so the camel hair comment was on target. there was no need to mung the
> real symbol table in the OP's problem so showing a symref solution was a
> poor answer. the OP may not know enough to realize that it is a bad
> solution.
>
> uri
Alright I give up, I proabably shouldn't of posted the silly code
snipet, but I still think "grossly negligent" maybe a bit strong. Just
to clarify to young impressionable perl users...don't do it that way,
use an array or a hash instead. Also remember to use strict, limit the
scope of variables with my or local, and brush your teeth before every
meal.
------------------------------
Date: Thu, 16 Jan 2003 03:44:07 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Variable naming convention
Message-Id: <bUpV9.3644$_T6.1942@nwrddc01.gnilink.net>
Andrew Allaire wrote:
>>> "J rgen Exner" <jurgenex@hotmail.com> wrote in message
>>> news:<Hx3V9.29498$%V.28678@nwrddc02.gnilink.net>...
>> >> If you feel the need to show symbolic references to someone who
>> apparently >> doesn't know how to handle them, then it is gross
>> negligent [...]
> snipet, but I still think "grossly negligent" maybe a bit strong. Just
Ok, maybe we can compromise on just plain "negligent"? ;-)
jue
------------------------------
Date: Thu, 16 Jan 2003 04:21:27 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Variable naming convention
Message-Id: <x7u1g9g1x4.fsf@mail.sysarch.com>
>>>>> "JE" == Jürgen Exner <jurgenex@hotmail.com> writes:
JE> Andrew Allaire wrote:
>>>> "J rgen Exner" <jurgenex@hotmail.com> wrote in message
>>>> news:<Hx3V9.29498$%V.28678@nwrddc02.gnilink.net>...
>>> >> If you feel the need to show symbolic references to someone who
>>> apparently >> doesn't know how to handle them, then it is gross
>>> negligent [...]
>> snipet, but I still think "grossly negligent" maybe a bit strong. Just
JE> Ok, maybe we can compromise on just plain "negligent"? ;-)
i prefer stupid, misguided, bad code, evil, misused, not strict,
felonious assault, syntactical rape, O.J. guilty, jaywalking or dumbass.
:-/
just remember, symrefs are ONLY for when you MUST deal with the symbol
table itself. any other use can be done better with regular perl data
structures.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
Damian Conway Perl Classes - January 2003 -- http://www.stemsystems.com/class
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 4412
***************************************