[18019] in Perl-Users-Digest
Perl-Users Digest, Issue: 179 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jan 30 21:05:45 2001
Date: Tue, 30 Jan 2001 18: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: <980906710-v10-i179@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 30 Jan 2001 Volume: 10 Number: 179
Today's topics:
Re: "how can I customize my installation of ActivePerl" <loy_x@yahoo.com>
Re: "how can I customize my installation of ActivePerl" <amonotod@netscape.net>
Re: calling variable subroutines <neil@alaweb.com>
Re: copying an array of hashes (Damian James)
Re: email address with receiver's name <johnlin@chttl.com.tw>
Re: GIF Generator (Martien Verbruggen)
Image::Magick <leekembel@hotmail.com>
Re: Image::Magick (Martien Verbruggen)
making a mail reciving script <bop@mypad.com>
Re: making a mail reciving script <tony_curtis32@yahoo.com>
Re: Newbie question <tlav1@earthlink.net>
Re: printf and leading zeros <johnlin@chttl.com.tw>
printing array of hashes <motivusNO@SPAMhotmail.com>
Re: printing array of hashes <juex@deja.com>
Re: printing array of hashes <godzilla@stomp.stomp.tokyo>
qr and backreferences <joegottman@worldnet.att.net>
Re: Seeking timezone conversion advice (James Weisberg)
Re: simple hash question. <tlav1@earthlink.net>
Re: simple hash question. (Damian James)
Re: testing defined() under strict (Brandon Metcalf)
Re: to shift, or not to shift <uri@sysarch.com>
Re: to shift, or not to shift <nospam@nospam.com>
Re: to shift, or not to shift <wyzelli@yahoo.com>
Re: Windows NT Version <carvdawg@patriot.net>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 30 Jan 2001 15:16:45 -0800
From: news <loy_x@yahoo.com>
Subject: Re: "how can I customize my installation of ActivePerl"
Message-Id: <3A774B5D.78AE82C4@yahoo.com>
Does yours have a section for "how can I customize my installation..."?
It's missing in the documentation I have.
------------------------------
Date: Wed, 31 Jan 2001 00:08:11 GMT
From: amonotod <amonotod@netscape.net>
Subject: Re: "how can I customize my installation of ActivePerl"
Message-Id: <957l15$3cv$1@nnrp1.deja.com>
In article <3A774B5D.78AE82C4@yahoo.com>,
news <loy_x@yahoo.com> wrote:
> Does yours have a section for "how can I customize my
installation..."?
> It's missing in the documentation I have.
>
>
<quote>
How can I customize my installation of Perl for Win32?
NOTE: The following information applies only if you have a versioned
perl installation. Newer versions of
ActivePerl use a simple (non-versioned) installation structure by
default, which is described here. See the
perlwin32 documentation page for more information on how to get a
versioned installation.
Perl uses the @INC array as a search path for use'd and require'd files.
(run perl -V to see what's in @INC)
This can be manipulated at run-time with use lib 'directory_to_add' or
by modifying the Registry or
environment. By default, the following directories are added to @INC:
<myperldir>/site/<version>/lib/<architecturename>
<myperldir>/site/<version>/lib
<myperldir>/<version>/lib/<architecturename>
<myperldir>/<version>/lib
Where <myperldir> is your Perl home directory, such as C:\Perl. And
<architecturename> is something like
MSWin32-x86 or MSWin32-Alpha.
There are a few registry entries you can use to customize your setup.
Under the following keys:
[HKEY_LOCAL_MACHINE/Software/Perl/] and
[HKEY_CURRENT_USER/Software/Perl/], you can add the following
String values:
LIB
LIB-<perlversion>
such as:
LIB
LIB-5.0050
This adds the directory, or directories, you specify to the default lib
paths (for Perl 5.005, this is
C:\Perl\5.00500\lib\MSWin32-x86 and C:\Perl\5.00500\lib). The
LIB-<perlversion> allows you to customize the
path for a given version of Perl, if you have multiple versions of Perl
installed. SITELIB SITELIB-<perlversion>
such as:
SITELIB
SITELIB-5.0050
This adds the directory, or directories, you specify to the default
sitelib paths (for Perl 5.005, this is
C:\Perl\site\5.00500\lib\MSWin32-x86, C:\Perl\site\5.00500\lib, and
C:\Perl\site\lib). The SITELIB-<perlversion>
allows you to customize the site path for a given version of Perl, if
you have multiple versions of Perl installed.
[HKEY_CURRENT_USER/Software/Perl] is searched before
[HKEY_LOCAL_MACHINE/Software/Perl], so you
can customize Perl on a per-user basis.
In addition, if you set the environment variable Perl5lib, it will be
added to @INC as well. Perl5lib will be
looked up in the environment first, and then in the registry as outlined
above.
</quote>
amonotod
--
`\|||/ amonotod@
(@@) netscape.net
ooO_(_)_Ooo________________________________
_____|_____|_____|_____|_____|_____|_____|_____|
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Tue, 30 Jan 2001 17:53:57 -0600
From: "Neil" <neil@alaweb.com>
Subject: Re: calling variable subroutines
Message-Id: <t7el03h1i2402b@corp.supernews.com>
"Kurt Stephens" <kstep@pepsdesign.com> wrote in message
news:9579ph$34v$1@slb6.atl.mindspring.net...
> "Neil" <neil@alaweb.com> wrote in message
> news:t7e1i8rb1socb@corp.supernews.com...
> > Hello,
> >
> > What I would like to do is create a loop in the manner of
>
> > # do the sub we ask with the params we ask, and return the results
> > # assume that we have variable number and types for the return and
> send
>
> First read perlref for info on creating references to subroutines, then
> perhaps perlsub as well. References to subroutines allow you to implement
> callbacks, closures, vtables and other cool stuff. Below is some sample
> code that won't solve your problem but may inspire your imagination.
Thanks Kurt ! Just what I was after !! All I really needed was a pointer in
the right direction....and it appears that that is what you have given
me....
I haven't tried looking the code and ref's over yet .... but that will be
this evenings work !
Thanks Again,
Neil
------------------------------
Date: 31 Jan 2001 01:55:34 GMT
From: damian@qimr.edu.au (Damian James)
Subject: Re: copying an array of hashes
Message-Id: <slrn97es56.6n.damian@puma.qimr.edu.au>
Thus spake Uri Guttman on Tue, 30 Jan 2001 18:56:22 GMT:
>>>>>> "PB" == Philip Blandford <philblandford@lineone.net> writes:
>
> PB> I have an array of hashes @x, and want to create a spare copy @y
> PB> so that changes I make to the hashes in @x don't affect @y.
>
> PB> I realise there's probably a messy way to do it by dereferencing each
> PB> field in the hash in turn, but this needs to be inside a repeating loop,
> PB> so that could get VERY time consuming.
>
> PB> Is there no Perl equivalent of memcpy?
>
>if your structures are deep then something like Data::Dumper or Storable
>would be one way to do it. i think there are other modules that do
>similar things. but if your list of hashes is only that and none of the hash
>elements are refs, then this should do the trick:
>
> @copy = map { { %{$_} } } @orig ;
>
>you just make new anonymous copies of each hash in the map.
>
The other option that may or may not suit the circumstances in which you
want to do this is to fork, then make the changes you want and work with
the the data in the sub-process. I have found this to be convenient in at
least one situation where:
1. The copy had to be trimmed (elements deleted), then
stringified and saved (via Data::Dumper and DBI).
2. The main process needed to attend to the user asap.
3. No communication was needed between the main process and
the copy of the data.
HTH
Cheers,
Damian
--
$;=ord$%,$:=$;-ord q,.,,$_=q,3346:3366:3276:3326:3386:546:566:966:3396:3376:,.
q,3386:546:;96:3326:3336:3386:3266:3236:3366:546::26:3236:3366:32:6:546:3266,.
q,:;96:;;6:3296:3236:3366:326:56,,s,.,ord($&)-$;-$:,eg,s,$;,chr$&-$:,eg,
eval eval; #requires 5.6.0 ## my first attempt at one of these...
------------------------------
Date: Wed, 31 Jan 2001 09:33:16 +0800
From: "John Lin" <johnlin@chttl.com.tw>
Subject: Re: email address with receiver's name
Message-Id: <957q42$21h@netnews.hinet.net>
Winston <bits101010@my-deja.com> wrote
> ===== from MIME::Lite manual =========
> "Name, Full" <full.name@some.host.com>
> This last form is discouraged because...
Huh... I can not find this in my manual.
Oh, my $MIME::Lite::VERSION is 1.14 (from activestate)
Thank you for reminding me to upgrade.
After upgrading, without surprise, all the formats are OK.
Great!!!
John Lin
------------------------------
Date: Wed, 31 Jan 2001 02:02:15 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: GIF Generator
Message-Id: <slrn97esfa.n8t.mgjv@verbruggen.comdyn.com.au>
On Tue, 30 Jan 2001 15:59:25 GMT,
igotlooks.com <rbfitzpa@my-deja.com> wrote:
> Does anyone have any simple 'on-the-fly' graphics generator? I'm looking
> for something where I could graph an array and create a gif. Any extra
> features would be nice but anything will do for now.
Two people have pointed you to the GD module. GD, in its later
versions does NOT produce GIF, but PNG, JPEG, and some others. If you
can find an older version of GD (1.19 or before) you can produce GIF,
but you still owe Unisys a license fee for the use of the LZW
algorithm.
Alternatively, you can use Image::Magick to produce uncompressed GIF,
or (after you've paid Unisys) compressed GIF when compiled with the
lzw option.
Do you really, really need GIF? PNG is far superior, and doesn't
require any licensing fees.
Martien
--
Martien Verbruggen |
Interactive Media Division | "In a world without fences,
Commercial Dynamics Pty. Ltd. | who needs Gates?"
NSW, Australia |
------------------------------
Date: Wed, 31 Jan 2001 00:16:18 GMT
From: "Studio 51" <leekembel@hotmail.com>
Subject: Image::Magick
Message-Id: <mPId6.28248$V22.6498249@news4.rdc1.on.home.com>
Can someone email the Image::Magick tarball to leekembel@hotmail.com? All
CPAN has is broken links and I'd like to use it.
Thanks,
LKembel
------------------------------
Date: Wed, 31 Jan 2001 02:02:50 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Image::Magick
Message-Id: <slrn97esge.n8t.mgjv@verbruggen.comdyn.com.au>
On Wed, 31 Jan 2001 00:16:18 GMT,
Studio 51 <leekembel@hotmail.com> wrote:
> Can someone email the Image::Magick tarball to leekembel@hotmail.com? All
> CPAN has is broken links and I'd like to use it.
http://www.imagemagick.org/
Martien
--
Martien Verbruggen |
Interactive Media Division | "In a world without fences,
Commercial Dynamics Pty. Ltd. | who needs Gates?"
NSW, Australia |
------------------------------
Date: Wed, 31 Jan 2001 01:52:37 GMT
From: "flash" <bop@mypad.com>
Subject: making a mail reciving script
Message-Id: <FdKd6.33202$HI.236773@news22.bellglobal.com>
i need to copy /var/spool/mail/smash
to my directory
then i need to seperate differant enteries how would i do this?
does anyone have experiance doing this?
--
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "mailto:smash@floodbox.com\n;
print "email me for free webhosting\n";
------------------------------
Date: 30 Jan 2001 19:58:03 -0600
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: making a mail reciving script
Message-Id: <87elxksct0.fsf@limey.hpcc.uh.edu>
** comp.lang.perl removed from Newsgroups line. This
group is no more, it is pushing up the daisies etc. **
>> On Wed, 31 Jan 2001 01:52:37 GMT,
>> "flash" <bop@mypad.com> said:
> i need to copy /var/spool/mail/smash to my directory
> then i need to seperate differant enteries how would i
> do this? does anyone have experiance doing this?
Get thee hence to http://search.cpan.org/ and search for
"mail". One of the subclasses of Mail::Box is probably
what you want.
hth
t
--
Eih bennek, eih blavek.
------------------------------
Date: Wed, 31 Jan 2001 01:14:26 GMT
From: ted <tlav1@earthlink.net>
Subject: Re: Newbie question
Message-Id: <3A779173.ABD33718@earthlink.net>
I think I understand your problem. I work with CSV files a lot. This is a
solution that had worked for me in the past.
###########
# this makes a hash from an array. The hash keys become unique options
foreach (@array_of_options) {
$HASH{$_} = $HASH{$_} + 1;
}
foreach $key (sort keys %HASH) {
$text .= qq[<OPTION VALUE="$key">$key\n]; # I use qq[ ] because
I dislike escaping characters
}
print $text;
############
I hope this is what you're looking for.
asparak@my-deja.com wrote:
> I am trying to generate an HTML Select list using cgi.pm from a csv
> file. I have all the info in a 2 dimensional array, but now I need to
> sort the data from the column I am using to create the OPTION values,
> because many of the entries appear multiple times in the column. What is
> the simplest method or sorting/mapping the column of data, so that each
> entry only appears once, when I generate the OPTION values.
>
> Sent via Deja.com
> http://www.deja.com/
------------------------------
Date: Wed, 31 Jan 2001 08:52:11 +0800
From: "John Lin" <johnlin@chttl.com.tw>
Subject: Re: printf and leading zeros
Message-Id: <957nn2$sc8@netnews.hinet.net>
"Russ Jones" wrote
> I have a number that looks like this:
> $num = 0.33;
> and I want to print it as
> .33
> Never mind, I think I've found an answer.
Hi, how about posting your answer?
John Lin
------------------------------
Date: Tue, 30 Jan 2001 16:31:18 -0800
From: "B McDonald" <motivusNO@SPAMhotmail.com>
Subject: printing array of hashes
Message-Id: <H2Jd6.78402$Wq1.33716117@nnrp5-w.sbc.net>
Hi. I have an array of hashes that is grown like this:
push @AoH_longlines, { line_num => $line_cnt,
doc_id => $doc_id,
begin_num =>
$control_ids{begin_num},
end_num => $control_ids{end_num},
title => $csv_record{title}
};
What I would like to do is to print the hash elements in the order shown
here when I use the following code:
for my $href ( @AoH_longlines ) {
print STATS "\n";
for my $datum ( keys %$href ) {
print STATS "$datum = $href->{$datum}\n";
}
print STATS "\n";
}
I've seen plenty of examples about sorting on one of the hash keys, but how
about just maintaining the order of the keys as entered in a array of
hashes?
Thanks,
Brian
------------------------------
Date: Tue, 30 Jan 2001 17:04:11 -0800
From: "Jürgen Exner" <juex@deja.com>
Subject: Re: printing array of hashes
Message-Id: <3a77648b$1@news.microsoft.com>
"B McDonald" <motivusNO@SPAMhotmail.com> wrote in message
news:H2Jd6.78402$Wq1.33716117@nnrp5-w.sbc.net...
[...]
> I've seen plenty of examples about sorting on one of the hash keys, but
how
> about just maintaining the order of the keys as entered in a array of
> hashes?
By its very definition a hash does not have an order (well, there is an
implementation-defined order but that is pretty much useless for all
practical purposes).
Therefore it cannot preserve any order.
If you want an order, then you must use an array (or pointer lists or
whatever).
jue
------------------------------
Date: Tue, 30 Jan 2001 17:13:49 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: printing array of hashes
Message-Id: <3A7766CD.5868D2C9@stomp.stomp.tokyo>
B McDonald wrote:
(snippage)
> Hi. I have an array of hashes that is grown like this:
> What I would like to do is to print the hash elements in the
> order shown here when I use the following code:
> I've seen plenty of examples about sorting on one of the hash
> keys, but how about just maintaining the order of the keys as
> entered in a array of hashes?
You cannot. Perl core stores data of this nature in
an optimized configuration for best access. You must
specify an exacting order for a print, if you want
your data printed in a specific fashion.
Godzilla!
------------------------------
Date: Wed, 31 Jan 2001 01:48:45 GMT
From: "Joseph Gottman" <joegottman@worldnet.att.net>
Subject: qr and backreferences
Message-Id: <1aKd6.184$G62.16689@bgtnsc04-news.ops.worldnet.att.net>
I just realized that there is a problem with the interaction between the
qr() operator and backreferences. Consider the following code
my $repeat = qr((.)\1); #Look for repeated characters.
If this pattern is later interpolated into a longer regular expression that
also contains capturing parens, then the \1 refers to the first pair of
capturing parentheses in the larger regular expression. Thus
print ('abb' =~ /(.)$repeat/) ? 'true' : 'false'; #Prints false.
print ('aba' =~ /(.)$repeat/) ? 'true' : 'false'; #Prints true.
Is there any way to define $repeat so that it finds repeated characters even
when interpolated into a longer regular expression?
Joe Gottman
------------------------------
Date: Wed, 31 Jan 2001 00:13:31 GMT
From: chadbour@wwa.com (James Weisberg)
Subject: Re: Seeking timezone conversion advice
Message-Id: <LMId6.14272$Sl.614556@iad-read.news.verio.net>
In article Jürgen Exner <juex@deja.com> wrote:
>"James Weisberg" <chadbour@wwa.com> wrote in message
>news:UIod6.13898$Sl.606099@iad-read.news.verio.net...
>> This isn't strictly a perl question, per se, and I apologize in
>> advance for the length, but I'm looking for some advice using perl
>> to calculate a timezone offset. Let me start by describing the idea.
>> Imagine you have a file with configuration info for four sites in
>> different timezones:
>[...]
>> Each site has a database associated with it and there will be some
>> script which comes along and wants to combine records of one database
>> with those of another, but perhaps the combination wants to take into
>> account the timezone difference between the sites. What I have above
>[long description snipped]
>
>Forget it. The easiest and most reliable way is to store your data (for the
>databases in all four time zones!!!) in UTC. Then merging and maintaining
>the data will a snap.
>Only for displaying the time to the user you should convert it into local
>time according to their current setting.
There are many reasons why I have not selected to store records
in UTC. The primary reason is that I want records to be stored in
database files based on *calendar* date. The very name of the file
itself reflects this. The idea is that some client will come along
and ask for records for a range of dates and I do not want to have
to translate this request into UTC-based dates and times, open the
appropriate files, fetch the appropriate records, and translate it
all back into a local timezone for display.
Moreover, if I have databases from different timezones, I might
want to write a request that compares noon in EST with noon in CST
with noon in PST, etc, and no translation is needed. However, it is
when I want to compare noon in EST with 11am in CST, with 10am in
PST that a reference timezone needs to apply. If the reference TZ
is, say, CST, then I need to translate records from PST and EST to
the CST timezone and aggregate. And that's where tzconvert() comes
into play. Such requirements are the exception, and not the norm,
so conversion is done when needed and not all the time.
Anyway, thanks to those who suggested I try setting $ENV{TZ} and
use Time::Local. I thought about that originally but I was uncertain
as to how reliable that method would be. The SCO Enterprise (yeah,
yeah, I know) OS I tried it on makes the change right away so it
worked fine. However, I think the two cooperating functions I had
described might work much faster without the need for various time
system calls. Basically, the isdst() function I proposed could use
another hash which has hardwired the DST dates for several years.
For example, I could have an entry:
$DST{2001} = [20010401, 20011028];
which says that Spring Foreword occurs on April 1st 2001 (the
first Sunday in April) and Fall Backword occurs on October 28th
2001 (the last Sunday in October).
Then someone could write:
isdst($date, $time, $tz);
and if $date < $DST{2001}[0] || $date > $DST{2001}[1], then we
are not in Daylight Savings Time (regardless of timezone). More work
is needed for boundary conditions, but so far I've yet to even need
a time system call [isdst() is not even called unless one timezone
uses DST and the other does not.]
However, unless someone wants to comment specifically on these
ideas, I might just take the path of least resistance and use the
ENV{TZ} method even though I find it "hokey" to ying-yang my TZ.
--
World's Greatest Living Poster
------------------------------
Date: Wed, 31 Jan 2001 01:00:22 GMT
From: ted <tlav1@earthlink.net>
Subject: Re: simple hash question.
Message-Id: <3A778E53.C343304F@earthlink.net>
I like to call this he 'brute force' method. It's kinda ugly, but it
works for me. Hope it helps you...
foreach (@password_array) {
$HASH{$_} = $HASH{$_} + 1;
}
This will give you a %HASH where your passwords are your keys and you'll
have numbers for the values. This will eliminate passwords that appear
more than once.
Again, brute-force-ugly, but works for me.
T
msalerno@my-deja.com wrote:
> I have an array of passwords that I want to convert to a hash so there
> are no duplicates.
>
> I have a subroutine returning a scalar var that is the password.
> Then the password is placed inside an array.
>
> I am just using an array for now because I am having problems with the
> hash.
>
> The array looks like the following:
> $pwarray[0] = "rndpw1";
> $pwarray[1] = "rndpw2";
> $pwarray[2] = "rndpw3";
> $pwarray[3] = "rndpw4";
>
> Any assistance would be appreciated.
>
> Thanks,
> Matt
>
> Sent via Deja.com
> http://www.deja.com/
------------------------------
Date: 31 Jan 2001 01:40:38 GMT
From: damian@qimr.edu.au (Damian James)
Subject: Re: simple hash question.
Message-Id: <slrn97er97.6n.damian@puma.qimr.edu.au>
[You're upside-down quoting: I suggest that you not do that]
Thus spake ted on Wed, 31 Jan 2001 01:00:22 GMT:
>I like to call this he 'brute force' method. It's kinda ugly, but it
>works for me. Hope it helps you...
>
>foreach (@password_array) {
>
> $HASH{$_} = $HASH{$_} + 1;
> }
>
[snip the rest, including OP]
Since you're assigning to a hash (as opposed to a hash reference), the
above is easier (and faster) done with a hash slice:
@hash{ @password_array } = (1) x @password_array;
Also, allcap variable names should be avoided.
Cheers,
Damian
--
$;=ord$%,$:=$;-ord q,.,,$_=q,3346:3366:3276:3326:3386:546:566:966:3396:3376:,.
q,3386:546:;96:3326:3336:3386:3266:3236:3366:546::26:3236:3366:32:6:546:3266,.
q,:;96:;;6:3296:3236:3366:326:56,,s,.,ord($&)-$;-$:,eg,s,$;,chr$&-$:,eg,
eval eval; #requires 5.6.0 ## my first attempt at one of these...
------------------------------
Date: 31 Jan 2001 00:10:06 GMT
From: bmetcalf@nortelnetworks.com (Brandon Metcalf)
Subject: Re: testing defined() under strict
Message-Id: <957l4u$8p3$1@bcarh8ab.ca.nortel.com>
gopalan@cs.sc.edu writes:
> I am doing some conditional text processing. If a given variable is
> defined and contains a filename, the file is opened and processed. For
> example,
>
> use strict;
>
> $hitlist_name = "hitlist.txt"
> ...
>
> if (defined $hitlist_name)
> {
> open .. or die
> blah blah blah
> }
>
> Now if I don't want to process that file, I comment out the definition
> of $hitlist_name
>
> If I remove the strict pragma, everything works as intended. If I
> leave it in, it doesn't compile because it requires an explicit
> definition for $hitlist_name in the test statement.
>
> Is it possible to leave strict in and yet do the above test?
my $hitlist_name;
$hitlist_name = 'hitlist.txt';
Brandon
------------------------------
Date: Tue, 30 Jan 2001 23:10:00 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: to shift, or not to shift
Message-Id: <x7r91kskl4.fsf@home.sysarch.com>
>>>>> "RJ" == Russ Jones <russ_jones@rac.ray.com> writes:
RJ> my $text = shift;
RJ> they don't use "shift" at all, instead they just reference $_[0]
$_[0] and @_ are actually aliases to the original arguments. effectively
args in perl are passed by reference. but when you access those values
and copy them, you get local copies and that becomes pass by value. and
there are 2 major ways to copy @_ into vars and that is with shift and
list assignment. both are ok and each have their uses as well as
stylistic differences.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: 30 Jan 2001 23:21:31 GMT
From: The WebDragon <nospam@nospam.com>
Subject: Re: to shift, or not to shift
Message-Id: <957i9r$p4a$1@216.155.32.241>
In article <3A773EDD.494A84E9@rac.ray.com>, Russ Jones
<russ_jones@rac.ray.com> wrote:
| In Christiansen & Torkington's Perl Cookbook, (in the parse_csv()
| segment on page 31), they show two ways to get a scalar into a
| subroutine. In the first one, they use
|
| my $text = shift;
|
| which seems pretty straight-forward to me. But in the second example,
| they don't use "shift" at all, instead they just reference $_[0]
| which also is relatively straight-forward. So can anyone tell me, is
| this just an example of "there's more than one way to do it" or is
| there some advantage to one way over the other?
|
| (Benchmarking didn't seem to give any significant differences.)
It wouldn't necessarily.
I've seen it done several ways, adn IMHO it seems more like TMTOWTDI
than anything else.
I've written subs that went like
sub coerce2 { sprintf '%04.1f', int(shift()*2+.5)/2 }
although it could have just as easily used $_[0]
and ones that started with
sub check_valid ($$$) {
my($val1, $val2, $val3) = @_;
#...
}
--
send mail to mactech (at) webdragon (dot) net instead of the above address.
this is to prevent spamming. e-mail reply-to's have been altered
to prevent scan software from extracting my address for the purpose
of spamming me, which I hate with a passion bordering on obsession.
------------------------------
Date: Wed, 31 Jan 2001 11:14:53 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: to shift, or not to shift
Message-Id: <SYJd6.10$GN5.4585@vic.nntp.telstra.net>
"Russ Jones" <russ_jones@rac.ray.com> wrote in message
news:3A773EDD.494A84E9@rac.ray.com...
> In Christiansen & Torkington's Perl Cookbook, (in the parse_csv()
> segment on page 31), they show two ways to get a scalar into a
> subroutine. In the first one, they use
>
> my $text = shift;
>
> which seems pretty straight-forward to me. But in the second example,
> they don't use "shift" at all, instead they just reference $_[0]
> which also is relatively straight-forward. So can anyone tell me, is
Generally TMTOWTDI but there is one significant difference that I have
used in the past.
shift removes the first element of @_ whilst referencing $_[0] does not.
I have used this in the past to pass a scalar and an array to a sub like
so:
&somesub($scalar, @array);
sub somesub {
my $scalar = shift; #takes the scalar of the 'front' of the array
my @array = @_; #gives me a scoped copy of the array to work with,
minus the scalar
# do stuff and then return;
}
An example is something I was toying with the other day, a routine to
zero pad all the items of localtime to a specified number of places.
This ensures all values are preset to a 2 digit zero padded number.
($year still needs the 1900 added, and $mon is still 0 indexed).
my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) =
pad('2',localtime());
sub pad{
my $pad = '0'.shift;
my @num = @_;
$_ = sprintf "%${pad}d",$_ for @num;
return @num;
}
I haven't actually used this in any production code, but it illustrates
the point. I could just as easily pass a list of numbers to the pad
subroutine, and the first would be the number of zeros to pad with and
the rest would be returned 'padded'
Wyzelli
--
#Modified from the original by Jim Menard
for(reverse(1..100)){$s=($_!=1)? 's':'';print"$_ bottle$s of beer on the
wall,\n";
print"$_ bottle$s of beer,\nTake one down, pass it around,\n";
$_--;$s=($_==1)?'':'s';print"$_ bottle$s of beer on the
wall\n\n";}print'*burp*';
------------------------------
Date: Tue, 30 Jan 2001 18:30:58 -0500
From: H C <carvdawg@patriot.net>
Subject: Re: Windows NT Version
Message-Id: <3A774EB2.EA11FDE@patriot.net>
> Does anyone know of a Perl way to identify NT Server vs NT Workstation?
> Environment variables only identify Windows_NT in both platforms. I've come
> up with a kludge using winmsd.exe but it's bad ;-( Thanks.
Use Win32::Registry or Win32::TieRegistry (ship with the default install of
ActiveState,
do not need to go to CPAN for them) to access the following Registry Key...
HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Control/ProductOptions/ProductType
Possible values:
ServerNT Server
LanmanNT Domain Controller
WinNT Workstation
------------------------------
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 V10 Issue 179
**************************************