[30488] in Perl-Users-Digest
Perl-Users Digest, Issue: 1731 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jul 18 14:09:46 2008
Date: Fri, 18 Jul 2008 11:09:09 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Fri, 18 Jul 2008 Volume: 11 Number: 1731
Today's topics:
Re: comma quoted lists question <cartercc@gmail.com>
Re: find which subgroups don't match in regex <sakradevanamindra@gmail.com>
Re: GromPerl persistent Perl interpreter <gromnospam@googlemail.com>
how to create a hash whose key is a reference <freesoft12@gmail.com>
Re: how to create a hash whose key is a reference <noreply@gunnar.cc>
Re: how to create a hash whose key is a reference <spamtrap@dot-app.org>
Re: how to create a hash whose key is a reference <jurgenex@hotmail.com>
Re: Need recommendations on parsing an instruction matr <tzz@lifelogs.com>
Re: Numerically sort a file on a given column where col <tzz@lifelogs.com>
proliferation of computer languages <xahlee@gmail.com>
Re: SOS...on system command <tzz@lifelogs.com>
Re: String comparison operator trouble <szrRE@szromanMO.comVE>
Re: understading double scalar variable $$ <ben@morrow.me.uk>
Re: understading double scalar variable $$ <slick.users@gmail.com>
Re: understading double scalar variable $$ <uri@stemsystems.com>
Re: understading double scalar variable $$ <mritty@gmail.com>
Re: understading double scalar variable $$ <uri@stemsystems.com>
Re: understading double scalar variable $$ <mritty@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 18 Jul 2008 05:29:06 -0700 (PDT)
From: cartercc <cartercc@gmail.com>
Subject: Re: comma quoted lists question
Message-Id: <eb789809-b0ea-4f06-b51d-d3349ea2eef6@z6g2000pre.googlegroups.com>
This is the result, a management decision that I was informed of and
had no opportunnity to influence or even comment on.
The decision was ... drum roll ... All files shall henceforth be
passed as .txt files.
This was the result of people from the business school getting the ear
of administration and convincing them, since Microsoft Office is THE
office suite and Microsoft Access is THE database, all users should
import into and export from as text files. (I work for a large state
university, and academics tend to have more influence than anyone
including, it seems, on technical issues.)
My reaction? Suits the heck out of me as it as it completely solves my
problem. Some people have real heartburn with the decision but not me.
Thanks for all input. I still will play with creating and reading
Excel files, since we do so much using Excel.
CC
------------------------------
Date: Fri, 18 Jul 2008 10:53:04 -0700 (PDT)
From: Shoryuken <sakradevanamindra@gmail.com>
Subject: Re: find which subgroups don't match in regex
Message-Id: <9bd20daa-3d56-4243-a2a1-6620611357d0@y21g2000hsf.googlegroups.com>
On Jul 17, 5:02 pm, Ben Morrow <b...@morrow.me.uk> wrote:
> Quoth Shoryuken <sakradevanamin...@gmail.com>:
>
> > Hello gents, here's the thing been confusing me for a while:
>
> > $regex="(\w+)\s([0-9]+)";
>
> > $a="Tom 1990"; # it's a match
> > $b="Jack xyz"; # not a match, because of $2 doesn't match ... but
> > here's my question, exactly how to inform the users of this unmatched
> > subgroup? (i.e. $2 is the problem, $1 is fine, etc.)
>
> > For a regex matching, is there a way to find which subgroups don't
> > match?
>
> You can use /gc and \G to match one piece at a time, without losing your
> place; something like
>
> my @matches = qw/ \w+ \s [0-9]+ /;
> my $string = 'Jack xyz';
>
> for my $match (@matches) {
> $string =~ /\G$match/gc
> or print "$match failed at position " . pos $string;
> }
>
> Ben
>
> --
> Outside of a dog, a book is a man's best friend.
> Inside of a dog, it's too dark to read.
> b...@morrow.me.uk Groucho Marx
This is a great idea, thanks!
And thanks the other guys for the good input, too!
------------------------------
Date: Fri, 18 Jul 2008 15:28:32 +0200
From: "Gvdc NET" <gromnospam@googlemail.com>
Subject: Re: GromPerl persistent Perl interpreter
Message-Id: <g5q5s4$df3$1@news.eunet.yu>
"Leon Timmermans" wrote in message
news:b6026$487d16cd$89e0e08f$3816@news1.tudelft.nl...
>> GromPerl persistent Perl interpreter
...
> not acceptable in the 21st century.
>
No, correct would be to say GromPerl is persistent Perl interpreter.
Execution of multiple scripts by a single process eliminates the penalty of
creating a new process for each execution and as a result it provides higher
performance.
Theory is not everything, I suppose by what you say you maybe do not have
very much practical experience.
Outputting CGI headers is not a requirement, it's an option which in some
cases is desired and for that one can either write custom routines which is
straightforward or use pre built modules such as CGI.pm.
regards,
------------------------------
Date: Fri, 18 Jul 2008 07:59:52 -0700 (PDT)
From: "freesoft12@gmail.com" <freesoft12@gmail.com>
Subject: how to create a hash whose key is a reference
Message-Id: <05fa8b16-0b81-40b8-bd52-18d73da0eb49@i20g2000prf.googlegroups.com>
Hi,
I am creating 2 hash tables. In the first hash table I have a string
as the key but in the second one I want the reference to that string
as the key, to save memory.
ie.
$hash_table_one[$string_key]
^
|
$hash_table_two[$string_key_ref] -> this key is a reference to the
first table's key
Regards
John
------------------------------
Date: Fri, 18 Jul 2008 17:10:35 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: how to create a hash whose key is a reference
Message-Id: <6ebpvjF61i8sU1@mid.individual.net>
freesoft12@gmail.com wrote:
> I am creating 2 hash tables. In the first hash table I have a string
> as the key but in the second one I want the reference to that string
> as the key,
Not possible. Hash keys are always strings.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Fri, 18 Jul 2008 11:15:44 -0400
From: Sherman Pendley <spamtrap@dot-app.org>
Subject: Re: how to create a hash whose key is a reference
Message-Id: <m11w1rcjfj.fsf@dot-app.org>
"freesoft12@gmail.com" <freesoft12@gmail.com> writes:
> I am creating 2 hash tables. In the first hash table I have a string
> as the key but in the second one I want the reference to that string
> as the key
Perldoc is your friend. From "perldoc -q reference":
Found in /System/Library/Perl/5.8.6/pods/perlfaq4.pod
How can I use a reference as a hash key?
You can't do this directly, but you could use the standard
Tie::RefHash module distributed with Perl.
sherm--
--
My blog: http://shermspace.blogspot.com
Cocoa programming in Perl: http://camelbones.sourceforge.net
------------------------------
Date: Fri, 18 Jul 2008 15:20:08 GMT
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: how to create a hash whose key is a reference
Message-Id: <ptc184l22f0iro6as53vfmhjv6lencmq3b@4ax.com>
"freesoft12@gmail.com" <freesoft12@gmail.com> wrote:
>I am creating 2 hash tables. In the first hash table I have a string
>as the key but in the second one I want the reference to that string
>as the key, to save memory.
>ie.
>$hash_table_one[$string_key]
> ^
> |
>$hash_table_two[$string_key_ref] -> this key is a reference to the
>first table's key
You don't. Hashes are mappings from _string_ to scalar. You cannot use a
reference as key.
I would probably just use a HoH instead, like
$hash{$hash_key}{Value1}
$hash($hash_key}{Value2}
And if either value doesn't exist then just don't create that hash
entry.
jue
------------------------------
Date: Fri, 18 Jul 2008 08:49:48 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Need recommendations on parsing an instruction matrix
Message-Id: <868wvzmhdv.fsf@lifelogs.com>
On Thu, 17 Jul 2008 20:59:39 GMT sln@netherlands.com wrote:
s> Below is a range (Find/Action) of parameters that can be passed to a parsing function.
s> I am going to parse this as a matrix. This is a serialized instruction matrix that can
s> have duplicates. Not only do I wan't to parse and validate it, but I wan't to put it into
s> a form where the sequence can be easily accesable and tracked during processing.
s> There will be duplicates, so it is passed and read as an array. On the user side, LINK
s> has no parameter. Otherwise its a square matrix.
Try Parse::RecDescent to build your grammar. No need for an instruction
matrix, and when it parses your input you can get a nice parse tree if
you use the <autotree> directive.
Ted
------------------------------
Date: Fri, 18 Jul 2008 08:48:04 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Numerically sort a file on a given column where column is a $var
Message-Id: <86d4lbmhgr.fsf@lifelogs.com>
On Thu, 17 Jul 2008 14:29:52 -0700 (PDT) joemacbusiness@yahoo.com wrote:
j> I want a subroutine that will sort a file on any given column.
j> So I have a file like this:
j> 300 400 500 600 700
j> 33 2337483 482 78374 4567
j> 10 20 30 40 50
j> 1000 1001 1002 1003 1004
j> 9 8 7 6 5
j> And I run my numericSortCol() routine on it sorting on
j> column 1 and should get this:
j> 9 8 7 6 5
j> 10 20 30 40 50
j> 300 400 500 600 700
j> 1000 1001 1002 1003 1004
j> 33 2337483 482 78374 4567
Use the standard Unix utility `sort':
sort -n +1 FILE
(use "-k 1" instead of +1 if GNU sort is installed)
e.g. sort /etc/passwd by user ID:
sort -t: -n +2 /etc/passwd
Read the docs for `sort' for further information.
You can use Perl for this (as others have shown), but if all you want is
to sort a file by a simple key, `sort' will do just fine. It's also
likely to be much faster in most circumstances.
Ted
------------------------------
Date: Fri, 18 Jul 2008 10:17:54 -0700 (PDT)
From: "xahlee@gmail.com" <xahlee@gmail.com>
Subject: proliferation of computer languages
Message-Id: <708b795b-70d6-4340-8717-94452acba31a@c2g2000pra.googlegroups.com>
Today, i took sometime to list some major or talked-about langs that
arose in recent years.
Here's the result:
http://xahlee.org/UnixResource_dir/writ/new_langs.html
Plain text version follows.
-------------------------------------
There is a proliferation of computer languages today like never
before. In this page, i list some of them.
In the following, i try to list some of the langs that are created
after 2000, or become very active after 2000.
* Erlang=E2=86=97. Functional, concurrent.
* Haskell=E2=86=97 Oldish, functional.
* Mercury=E2=86=97. Logic, functional.
* Q=E2=86=97. Functional lang, based on term rewriting. To be replaced =
by
=E2=80=9CPure=E2=80=9D http://pure-lang.sourceforge.net/.
ML Family:
* Oz=E2=86=97. Concurrent. Multiparadigm.
* Alice=E2=86=97. Concurrent, ML derivative. Saarland University, Germa=
ny.
* OCaml=E2=86=97
* F#=E2=86=97. Microsoft's functional lang.
Lisp family:
* Mathematica=E2=86=97
* NewLisp=E2=86=97
* Arc=E2=86=97. Paul Graham's selling his name.
* Qi=E2=86=97. Common Lisp added with modern functional lang features.
* Scheme=E2=86=97, notably PLT Scheme=E2=86=97.
* Dylan programming language=E2=86=97. Rather dead.
Proof systems:
* Coq=E2=86=97. For formal proofs.
* For much more, see Automated theorem proving=E2=86=97.
Perl Family or derivative:
* PHP=E2=86=97. Decendent of Perl for server side web apps.
* Ruby=E2=86=97. Perl with rectified syntax and semantics.
* Perl6=E2=86=97
* Sleep=E2=86=97. A scripting lang, perl syntax. On Java platform.
Java related:
* C#=E2=86=97. Microsoft's answer to Java.
* Scala=E2=86=97. A FP+OOP lang on Java platform as a Java alternative.
* Groovy=E2=86=97. Scritping lang on on Java platform.
2D graphics related.
* Scratch=E2=86=97
* Adobe Flash=E2=86=97's ActionScript=E2=86=97. 2D graphics.
* Processing=E2=86=97. 2D graphics on Java platform.
Misc:
* Linden_Scripting_Language=E2=86=97. Used in virtual world Second Life=
.
------------------------------
Following are some random comments on comp langs.
in the above, i tried to not list implementations. (e.g. huge number
of Scheme implemented in JVM with fluffs here and there; also e.g.
JPython, JRuby, and quite a lot more.) Also, i tried to avoid minor
derivatives or variations. Also, i tried to avoid langs that's one-
man's fancy with little followings.
For those of you developens in Java, Perl, Python for example, it
would be fruitful to spend a hour or 2 to look at the Wikipedia
articles about these, or their home pages. Wikipedia has several pages
that is a listing of comp langs, of which you can read about perhaps
over 2 hundreds of langs if you want.
The user base of the langs differ by some magnitude. Some, such as for
example PHP, C#, are within the top 10 most popular lang with active
users (which is perhaps in order of hundreds of millions). Some
others, are niche but still with huge users (order of tens or hundreds
of thousands), such as LSL, Erlang, Mathematica. Others are niche but
robust and industrial (counting academic use), such as Coq (a proof
system), Processing, PLT Scheme, AutoLisp. Few are mostly academic
followed with handful of experimenters, Qi, Arc, Mercury, Q,
Concurrent Clean are probably examples.
------------------
I was prompted to have a scan at these new lang because recently i
wrote a article titled =E2=80=9CThe Fundamental Problems of Lisp=E2=80=9D
( http://xahlee.org/UnixResource_dir/writ/lisp_problems.html (ranty)),
which mentioned my impression of a proliferation of languages (and all
sorts of computing tools and applications). Quote:
10 years ago, in the dot com days (~1998), where Java, Javascript,
Perl are screaming the rounds. It was my opinion, that lisp will
inevitably become popular in the future, simply due to its inherent
superior design, simplicity, flexibility, power, whatever its existing
problems may be. Now i don't think that'll ever happen as is. Because,
due to the tremendous technological advances, in particular in
communication (i.e. the internet and its consequences, e.g. Wikipedia,
youtube, youporn, social networks sites, blogs, Instant chat, etc)
computer languages are proliferating like never before. (e.g. erlang,
OCaml, Haskell, PHP, Ruby, c#, f#, perl6, arc, NewLisp, Scala, Groovy,
Goo, Nice, E, Q, Qz, Mercury, Scratch, Flash, Processing, ..., helped
by the abundance of tools, libraries, parsers, existance of
infrastructures) New langs, basically will have all the advantages of
lisps or lisp's fundamental concepts or principles. I see that,
perhaps in the next decade, as communication technologies further hurl
us forward, the proliferation of langs will reduce to a trend of
consolidation (e.g. fueled by virtual machines such as
Microsoft's .NET. (and, btw, the breaking of programer's social taboo
of cross communication of computing languages, led by Xah Lee)).
---------------------
in general, creating a lang is relatively easy to do in comparison to
programing tasks in the industry (such as, for example, writing robust
signal processing lib, a new feature in web server, video web server
framework, a game engine ...etc.). Computing tasks typically have a
goal, where all sorts of complexities and nit-gritty detail arise in
the solving process. Creating a lang often is simply based on a
individual's creativity that doesn't have much fixed constraints, much
as in painting or sculpting. Many langs that have become popular, in
fact arose this way. Popularly known examples includes perl6, Ruby,
Arc, Python. Creating a lang requires the skill of writing a compiler
though, which isn't trivial, but today with mega proliferation of
tools, even the need for compiler writing skill is reduced. (e.g. Arc.
(10 years ago, writing a parser is mostly not required due to existing
tools such as lex/yacc))
Some lang are created to solve a immediate problem or need.
Mathematica, Adobe Flash's ActionScript, Emacs Lisp, LSL would be good
examples. Some are created due to a new discoveries in computing
models. Lisp, Haskell, Qi, Prolog, SmallTalk, are of this type...
Some are created by corporations from scratch for one reasons or
another. e.g. Java, Javascript, AppleScript, Dylan, C#. The reason is
mostly to make money by creating a lang that solves perceived problems
or need, as innovation. The problem may or may not actually exist. (C#
is a lang created probably mostly just for legal reasons)
-------------------
Looking at some tens of langs, one might think that there might be
some unifying factor, some unifying theory or model, that limits their
type, class, or model. With influence from Stephen Wolfram book =E2=80=9CA =
New
Kind of Science=E2=80=9D, i'd think there's no such thing. That is to say,
different languages are potentionally endless, and each can become
quite useful or important or with large user bases. In other words, i
think there's no theoretical basis that would govern what languages
will be popular due to its technical/mathematical properties... (sorry
just writing out my thoughts here...) Perhaps another way to phrase
this imprecise thought is that, languages will keep proliferating, and
even if we don't consider langs that are one-man's fancy, there will
still probably be forever birth of languages, and they will all be
useful or solve some niche problem, because there is no theoretical or
techinacal reason that sometimes in the future there would be one lang
that can be fittingly used to solve all computing problems.
Also, the possibilities of lang's syntax are basically unlimited, even
considering that they be practical and human readible. So, any joe,
can potentionally create a new syntax. The syntaxes of existing langs,
when compared to the number of all potentionally possible (human
readible) syntaxes, are probably a very small fraction. That is to
say, even with so many existing langs today with their wildly
differing syntax, we probably haven't seen nothing yet.
Also note here all langs mentioned here are all plain-text linear
ones. Spread sheet and visual programing langs would be example of 2D
syntax... but i haven't thought about how they can be classified as
syntax. (nor do i fully understand the ontology of syntax)
(see e.g.
http://en.wikipedia.org/wiki/Syntax
http://en.wikipedia.org/wiki/Visual_programming_language
)
Just some extempore thoughts.
Xah
=E2=88=91 http://xahlee.org/
=E2=98=84
------------------------------
Date: Fri, 18 Jul 2008 08:52:53 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: SOS...on system command
Message-Id: <864p6nmh8q.fsf@lifelogs.com>
On Thu, 17 Jul 2008 15:45:38 -0500 "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid> wrote:
JG> cyrusgreats@gmail.com wrote:
>> next if ($el !=m~ ^\truncating\);
JG> ^^^^^^.. first, what do you expect that to do?
Obviously, it inverts a negative hopeful match in rleP :)
I do wish people would post more rleP code.
Ted
------------------------------
Date: Fri, 18 Jul 2008 11:07:21 -0700
From: "szr" <szrRE@szromanMO.comVE>
Subject: Re: String comparison operator trouble
Message-Id: <g5qm4q028rr@news4.newsguy.com>
Hans Mulder wrote:
> szr wrote:
>> Jürgen Exner wrote:
>>> Dave B <daveb@addr.invalid> wrote:
>
>>>> $item == undef
>
>> I get a different set of warnings (using both 5.10.0 and 5.8.8)
>>
>> $ perl5.8.8 -Mstrict -Mwarnings -we 'my $x = 1; print +($x ==
>> undef ? "[undef]" : "[$x]"), "\n";'
>> Warning: Use of "undef" without parentheses is ambiguous at -e
>> line 1. Search pattern not terminated or ternary operator parsed
>> as search pattern at -e line 1.
>>
>> I'm not sure where it's getting "Search pattern from, but I'm
>> guessing this has something to do with using (if ? then : else)
>> instead of if{}else{} ?
>
> The "undef" operator takes an argument if it can find one.
> If the first non-whitespace character after "undef" is a "?",
> then the parser assumes this is a ??-style pattern match.
>
> In this case, there is no closing "?". If there were one, then
> you'd get a message that "undef" wants an lvalue argument and
> pattern matches are not lvalues.
Ah I didn't realize that, thank you.
> As the other warning points out, you can avoid this kind of mis-
> parse by writing "undef()".
>
> In theory you can leave out the parentheses if the next character
> is a one that cannot be the first in an expression (such as ";").
> This only works if you know about obscure kinds of expressions
> (such as *globs and ??-patterns).
Seems being explicit is once again the safer way.
> For example, you might think that "undef * 5" looks like
> multiplication, but perl interprets this as undef(*5). As it
> happens, *5 is an lvalue, so this will "work" (for some definition of
> "work").
This is true. Many people seem to be confused as to just how to use
undef(), as some see it as a (none) value to be assigned to return a
scalar to an undefined state, rather than as a function and knowing
exactly what it does.
Thank you for taking the time to reply.
--
szr
------------------------------
Date: Fri, 18 Jul 2008 03:46:57 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: understading double scalar variable $$
Message-Id: <1qc5l5-fgv.ln1@osiris.mauzo.dyndns.org>
Quoth Joost Diepenmaat <joost@zeekat.nl>:
> Ben Morrow <ben@morrow.me.uk> writes:
>
> > Huh? The sub defaults to operating on $_ if no argument is supplied.
> > That's hardly an 'edge case'.
>
> What sub? Here's the original code:
>
> my($text) = @_;
> if ($text)
> {
> $$text =~ s/^\s+//;
> $$text =~ s/\s+$//;
> }
> else
> {
> s/^\s+//;
> s/\s+$//;
> }
>
> This means that if the first argument evaluates to "false" (which is
> not at all the same as "not supplying an argument"), the else clause is
> executed and $_ is modified. IMHO that seems like very sloppy and
> unusual coding.
Well, yes, the code posted is obviously incomplete. Bad OP, no cookie.
However, it is obviously expected that the argument will be a ref, which
is always true, so there's no need to check for anything more
complicated. Indeed, if the sub were prototyped (;\$) this would be
guaranteed: since explicitly passing a scalar ref to a function is
rather unusual (though not unknown), I would wager that is the case.
Ben
--
Musica Dei donum optimi, trahit homines, trahit deos. |
Musica truces mollit animos, tristesque mentes erigit. | ben@morrow.me.uk
Musica vel ipsas arbores et horridas movet feras. |
------------------------------
Date: Fri, 18 Jul 2008 08:23:29 -0700 (PDT)
From: Slickuser <slick.users@gmail.com>
Subject: Re: understading double scalar variable $$
Message-Id: <a6c48d22-6b8f-4af1-b6f1-20363e518155@i36g2000prf.googlegroups.com>
This is the original code.
Someone wrote it and I am trying to understand that's why.
sub parse_text()
{
my($text) = @_;
if ($text)
{
$$text =~ s/^\s+//;
$$text =~ s/\s+$//;
}
else
{
s/^\s+//;
s/\s+$//;
}
}
On Jul 17, 7:46 pm, Ben Morrow <b...@morrow.me.uk> wrote:
> Quoth Joost Diepenmaat <jo...@zeekat.nl>:
>
>
>
> > Ben Morrow <b...@morrow.me.uk> writes:
>
> > > Huh? The sub defaults to operating on $_ if no argument is supplied.
> > > That's hardly an 'edge case'.
>
> > What sub? Here's the original code:
>
> > my($text) = @_;
> > if ($text)
> > {
> > $$text =~ s/^\s+//;
> > $$text =~ s/\s+$//;
> > }
> > else
> > {
> > s/^\s+//;
> > s/\s+$//;
> > }
>
> > This means that if the first argument evaluates to "false" (which is
> > not at all the same as "not supplying an argument"), the else clause is
> > executed and $_ is modified. IMHO that seems like very sloppy and
> > unusual coding.
>
> Well, yes, the code posted is obviously incomplete. Bad OP, no cookie.
> However, it is obviously expected that the argument will be a ref, which
> is always true, so there's no need to check for anything more
> complicated. Indeed, if the sub were prototyped (;\$) this would be
> guaranteed: since explicitly passing a scalar ref to a function is
> rather unusual (though not unknown), I would wager that is the case.
>
> Ben
>
> --
> Musica Dei donum optimi, trahit homines, trahit deos. |
> Musica truces mollit animos, tristesque mentes erigit. | b...@morrow.me.uk
> Musica vel ipsas arbores et horridas movet feras. |
------------------------------
Date: Fri, 18 Jul 2008 16:11:06 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: understading double scalar variable $$
Message-Id: <x7tzencgva.fsf@mail.sysarch.com>
>>>>> "BM" == Ben Morrow <ben@morrow.me.uk> writes:
BM> guaranteed: since explicitly passing a scalar ref to a function is
BM> rather unusual (though not unknown), I would wager that is the case.
passing scalar refs is very useful and not just to modify things. if you
are passing around large strings/buffers, passing by ref is much more
efficient (assuming you copy args out of @_). you may not use scalar
refs as often a hash/array refs but they should be part of your
toolkit. you just need to be creative to find times where they help out.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Free Perl Training --- http://perlhunter.com/college.html ---------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
------------------------------
Date: Fri, 18 Jul 2008 09:52:07 -0700 (PDT)
From: Paul Lalli <mritty@gmail.com>
Subject: Re: understading double scalar variable $$
Message-Id: <6791c378-8d8d-4658-9e91-f759311bdeda@i76g2000hsf.googlegroups.com>
On Jul 18, 11:23=A0am, Slickuser <slick.us...@gmail.com> wrote:
> This is the original code.
> Someone wrote it and I am trying to understand that's why.
>
> sub parse_text()
^^
> {
> =A0 =A0 my($text) =3D @_;
^^
This is the *exact* code that someone wrote? Copy and pasted? Fire
that person. Or at the very least, don't use any more of his/her
code. He/She does't know what he/she's doing.
This code explicitly states that the subroutine does not take any
arguments.... and the very first thing it does is to retrieve the
argument. The only way this code works if the calls to the code use
the &-calling notation, which is evil for other reasons as well.
Paul Lalli
------------------------------
Date: Fri, 18 Jul 2008 16:59:40 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: understading double scalar variable $$
Message-Id: <x7bq0vb01v.fsf@mail.sysarch.com>
>>>>> "PL" == Paul Lalli <mritty@gmail.com> writes:
PL> On Jul 18, 11:23 am, Slickuser <slick.us...@gmail.com> wrote:
>> This is the original code.
>> Someone wrote it and I am trying to understand that's why.
>>
>> sub parse_text()
PL> ^^
>> {
>> my($text) = @_;
PL> ^^
PL> This is the *exact* code that someone wrote? Copy and pasted? Fire
PL> that person. Or at the very least, don't use any more of his/her
PL> code. He/She does't know what he/she's doing.
PL> This code explicitly states that the subroutine does not take any
PL> arguments.... and the very first thing it does is to retrieve the
PL> argument. The only way this code works if the calls to the code use
PL> the &-calling notation, which is evil for other reasons as well.
it still works if the prototype hasn't been seen at the time of the
call.
perl -le 'foo(2); sub foo(){print "@_"}'
2
perl -le 'sub foo(){print "@_"} foo(2)'
Too many arguments for main::foo at -e line 1, at end of line
Execution of -e aborted due to compilation errors.
and i bet the coder didn't export that sub but cut/pasted it. if it was
exported it would definitely fail at compile time if called with args.
but i agree, fire the coder.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Free Perl Training --- http://perlhunter.com/college.html ---------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
------------------------------
Date: Fri, 18 Jul 2008 10:51:59 -0700 (PDT)
From: Paul Lalli <mritty@gmail.com>
Subject: Re: understading double scalar variable $$
Message-Id: <a909f259-dd2f-4ef0-a9ed-7a8d243404aa@25g2000hsx.googlegroups.com>
On Jul 18, 12:59=A0pm, Uri Guttman <u...@stemsystems.com> wrote:
>
> =A0 >> sub parse_text()
> =A0 >> {
> =A0 >> =A0 =A0 my($text) =3D @_;
>
> it still works if the prototype hasn't been seen at the time of the
> call.
>
> perl -wle 'foo(2); sub foo(){print "@_"}'
> 2
Yes, but that implies that the coder is either not using or ignoring
warnings:
$ perl -wle 'foo(2); sub foo(){print "@_"}'
main::foo() called too early to check prototype at -e line 1.
2
which gives even more credence to...
> but i agree, fire the coder.
Paul Lalli
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V11 Issue 1731
***************************************