[18120] in Perl-Users-Digest
Perl-Users Digest, Issue: 280 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Feb 13 09:05:46 2001
Date: Tue, 13 Feb 2001 06: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: <982073110-v10-i280@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 13 Feb 2001 Volume: 10 Number: 280
Today's topics:
Re: a bug in perl-5.6.0? (Csaba Raduly)
Re: cgi and NT installing and testing <wyzelli@yahoo.com>
Re: cgi script sending mail (Abigail)
cgi visitors check <fsaffih@venus.uwaterloo.ca>
Re: directory structure <hafner-usenet@ze.tu-muenchen.de>
Re: directory structure (Abigail)
Re: Finding multiply of prime factors <jonni@ifm.liu.se>
getopt doesn't (J.C.Posey)
Re: getopt doesn't (Abigail)
Re: getopt doesn't (Anno Siegel)
Re: getopt doesn't (J.C.Posey)
Re: getopt doesn't (Anno Siegel)
Re: Global Variables (Anno Siegel)
Re: How can I modify the value of a variable directly f (Anno Siegel)
Re: measuring sizeof of STDIN (Logan Shaw)
Re: need help going from UNIX to Windows (Clinton A. Pierce)
Re: Performance question <jonni@ifm.liu.se>
Re: Perl FAQ: Stripping blank space <krahnj@acm.org>
Re: Scaling up sample data in an array of hashes (Philip Lees)
shadow file, replace *LK* <Per-fredrik.Pollnow@epk.ericsson.se>
Re: shadow file, replace *LK* <Peter.Dintelmann@dresdner-bank.com>
Re: shadow file, replace *LK* <jonni@ifm.liu.se>
Re: shadow file, replace *LK* (Anno Siegel)
Re: shadow file, replace *LK* <Per-fredrik.Pollnow@epk.ericsson.se>
STDIN - mutliple actions <sean@tnq.com>
Re: STDIN - mutliple actions (Anno Siegel)
Thanks - just what I needed. <DavePerkins@bigfoot.com>
Re: Two dimensional arrays (Gwyn Judd)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 13 Feb 2001 11:45:29 +0000 (UTC)
From: real.email@signature.this.is.invalid (Csaba Raduly)
Subject: Re: a bug in perl-5.6.0?
Message-Id: <Xns90477065Cquuxi@194.203.134.135>
And so it came to pass that Chris Stith <mischief@velma.motion.net>
on 10 Feb 2001 wrote <t897rjgu7jhs05@corp.supernews.com>:
>Csaba Raduly <real.email@signature.this.is.invalid> wrote:
>> And so it came to pass that Chris Stith
>> <mischief@velma.motion.net> on 07 Feb 2001 wrote
>> <t83fcptb9o5u9e@corp.supernews.com>:
>
[snip]
>
>> Csaba Raduly, Software Developer (OS/2)
>
>What a brave soul, still working on what should have been the
>successor to DOS.
>
It's only partially my fault (well, I did put OS/2 experience on my
resume when I sent it; they weren't supposed to use that against me :-)
--
Csaba Raduly, Software Developer (OS/2), Sophos Anti-Virus
mailto:csaba.raduly@sophos.com http://www.sophos.com/
US Support +1 888 SOPHOS 9 UK Support +44 1235 559933
You are in a maze of twisty little open source licenses, all different.
------------------------------
Date: Tue, 13 Feb 2001 18:13:26 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: cgi and NT installing and testing
Message-Id: <Rs6i6.5$w1.623@vic.nntp.telstra.net>
"nowayandnohow" <nowayandnohow@hotmail.com> wrote in message
news:BS1i6.8340$R45.2586372@typhoon2.ba-dsg.net...
> I am sure that all of you are tired of these questions, I have been around
> and all guides are either to high level for me or just about the apache
> server or unix servers.
>
> I downloaded the cgi.pm package and performed the makefile.pm.
>
Run, dont walk to www.activestate.com and download activeperl.
Run the installation on your webserver, and accept the options to associate
.pl with perl, and register for your web-server.
Then check the Activestate FAQ which will be in the html documentation you
just installed, about the details of making your webserver work,
specifically for sites other than the default site.
cgi.pm is included as part of that package, so you should not need to
install anything else.
The only other issue is ensureing the application associations in the
web-server are set correctly, and if you can't get the necessary information
from the faq provided, feel free to email me, as that is OT for this group.
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*';d
------------------------------
Date: 13 Feb 2001 09:08:15 GMT
From: abigail@foad.org (Abigail)
Subject: Re: cgi script sending mail
Message-Id: <slrn98hubv.60r.abigail@tsathoggua.rlyeh.net>
Kannan Narayanan (nkan@cup.hp.com) wrote on MMDCCXXII September MCMXCIII
in <URL:news:3A885C64.A221DC16@cup.hp.com>:
|| I am writing a CGI script in Perl.
||
|| When the user sumits a form from the web browser the CGI script should
|| collect all the information put in the form and send that info in
|| a mail.
||
|| Is it possible to do that in Perl?
Yes.
|| Does anybody done similar stuff or have pointers to related info?
man CGI;
Abigail
--
use lib sub {($\) = split /\./ => pop; print $"};
eval "use Just" || eval "use another" || eval "use Perl" || eval "use Hacker";
------------------------------
Date: Tue, 13 Feb 2001 08:22:47 -0500
From: Faycal Saffih <fsaffih@venus.uwaterloo.ca>
Subject: cgi visitors check
Message-Id: <3A893527.908C1035@venus.uwaterloo.ca>
Hi all;
Cn anyone tell me how can I get my website visitors servers or emails?
Please reply me if you know the answer.
Thanks .
Saffih
------------------------------
Date: 13 Feb 2001 09:45:48 +0100
From: Walter Hafner <hafner-usenet@ze.tu-muenchen.de>
Subject: Re: directory structure
Message-Id: <srj3ddjnf7n.fsf@w3projns.ze.tu-muenchen.de>
ben-fuzzybear@geocities.com (Ben Okopnik) writes:
> The ancient archives of 12 Feb 2001 17:28:19 GMT showed
> Abigail of comp.lang.perl.misc speaking thus:
> >
> > my @foo = ('aa' .. 'zz');
> > my $i = 0;
> > while (1) {print "/$foo[($i+=1)%=@foo]/\n"}
>
>
> Yow. Elegant you wanted, elegant you got - and precisely per spec, too.
> Assignment, postincrement, modulo the return scalar from array, even that
> (1) as a nice placeholder for whatever loop condition you might want - all
> in one shot. OK, call me easily impressed, but that's _cool._ :)
Yes, i think so, too. Exactly, what I was looking for. I program perl
for about 4 months now - serious programming, that is - and i'm still
impressed. I feel that i slowly get into "perl thinking", but evaluating
the array in scalar context to compute the modulo was simply beyond my
thinking.
I modified the code sligthly
my $i; # just a little testloop
for($i=0; $i<2000; $i++) {
my $dir = &next_dir($i);
print "$dir - ";
}
...
sub next_dir {
my ($i) = @_;
my @foo = ('aa' .. 'zz');
return $foo[($i)%=@foo];
}
because I don't need the directory access in a single loop, but in
different locations in the main program.
Thanks a lot!
-Walter
------------------------------
Date: 13 Feb 2001 09:06:52 GMT
From: abigail@foad.org (Abigail)
Subject: Re: directory structure
Message-Id: <slrn98hu9c.60r.abigail@tsathoggua.rlyeh.net>
Walter Hafner (hafner-usenet@ze.tu-muenchen.de) wrote on MMDCCXXIII
September MCMXCIII in <URL:news:srj3ddjnf7n.fsf@w3projns.ze.tu-muenchen.de>:
<> ben-fuzzybear@geocities.com (Ben Okopnik) writes:
<>
<> > The ancient archives of 12 Feb 2001 17:28:19 GMT showed
<> > Abigail of comp.lang.perl.misc speaking thus:
<> > >
<> > > my @foo = ('aa' .. 'zz');
<> > > my $i = 0;
<> > > while (1) {print "/$foo[($i+=1)%=@foo]/\n"}
<> >
<> >
<> > Yow. Elegant you wanted, elegant you got - and precisely per spec, too.
<> > Assignment, postincrement, modulo the return scalar from array, even that
<> > (1) as a nice placeholder for whatever loop condition you might want - all
<> > in one shot. OK, call me easily impressed, but that's _cool._ :)
<>
<> Yes, i think so, too. Exactly, what I was looking for. I program perl
<> for about 4 months now - serious programming, that is - and i'm still
<> impressed. I feel that i slowly get into "perl thinking", but evaluating
<> the array in scalar context to compute the modulo was simply beyond my
<> thinking.
<>
<> I modified the code sligthly
<>
<> my $i; # just a little testloop
<> for($i=0; $i<2000; $i++) {
<> my $dir = &next_dir($i);
<> print "$dir - ";
<> }
<> ...
<> sub next_dir {
<> my ($i) = @_;
<> my @foo = ('aa' .. 'zz');
<> return $foo[($i)%=@foo];
<> }
<>
<> because I don't need the directory access in a single loop, but in
<> different locations in the main program.
I would write that different, for two reasons. Now you require all those
different locations to share an index, and you reinitialize @foo each time
you call next_dir.
{ my ($i, @foo);
INIT {$i = 0; @foo = ('aa' .. 'zz');
sub next_dir {$foo [($i += 1) %= @foo]}
# The following would work too, unless you call the function
# about 2^53 times.
# sub next_dir {$foo [$i ++ % @foo]}
}
The block is for scope, the INIT makes that $i and @foo are initialized
even if you put the block at the end of your code.
Now you can just call next_dir(), without the need of remembering an index.
Abigail
--
sub f{sprintf'%c%s',$_[0],$_[1]}print f(74,f(117,f(115,f(116,f(32,f(97,
f(110,f(111,f(116,f(104,f(0x65,f(114,f(32,f(80,f(101,f(114,f(0x6c,f(32,
f(0x48,f(97,f(99,f(107,f(101,f(114,f(10,q ff)))))))))))))))))))))))))
------------------------------
Date: Tue, 13 Feb 2001 09:08:23 +0100
From: "Jonas Nilsson" <jonni@ifm.liu.se>
Subject: Re: Finding multiply of prime factors
Message-Id: <96apvl$fjk$1@newsy.ifm.liu.se>
Well, it obviously woun't work for integers that can't be represented as
integers.
use this to see which is your limit between integers and floats:
for (1..100) {print "$_:",2**$_};
Math::BigInt might do the trick for large numbers.
/jN
--
_____________________ _____________________
| Jonas Nilsson | | |
|Linkoping University | | Telephone |
| IFM | | --------- |
| Dept. of Chemistry | | work: +46-13-285690 |
| 581 83 Linkoping | | fax: +46-13-281399 |
| Sweden | | home: +46-13-130294 |
|_____________________| |_____________________|
"Tony L. Svanstrom" <tony@svanstrom.com> wrote in message
news:1eord41.14n7ydyxxc0aN%tony@svanstrom.com...
> Jonas Nilsson <jonni@ifm.liu.se> wrote:
>
> > Heres a nice quick one that does it recursively.
> >
> > sub factorize {
> > return(2,factorize($_[0]/2)) if (($_[0]%2)==0);
> > my $limit=int(sqrt($_[0]));
> > my $i=3;
> > while ($i<=$limit) {
> > if ($_[0]%$i==0) {return($i,factorize($_[0]/$i))};
> > $i+=2;
> > }
> > return $_[0];
> > }
> >
> > $a=int rand 1e8;
> > print "$a = ",join(" x ",factorize($a));
>
> 7409230211 = 3 x 3 x 823247801.222222
>
> Since when's "823247801.222222" a prime?
>
>
> /Tony
> PS don't quote jeopardy-style... =)
> --
> /\___/\ Who would you like to read your messages today? /\___/\
> \_@ @_/ Protect your privacy: <http://www.pgpi.com/> \_@ @_/
> --oOO-(_)-OOo---------------------------------------------oOO-(_)-OOo--
> on the verge of frenzy - i think my mask of sanity is about to slip
> ---ôôô---ôôô-----------------------------------------------ôôô---ôôô---
> \O/ \O/ ©99-00 <http://www.svanstrom.com/?ref=news> \O/ \O/
------------------------------
Date: 13 Feb 2001 09:16:11 +0000
From: jcp@myrtle.ukc.ac.uk (J.C.Posey)
Subject: getopt doesn't
Message-Id: <jkoy9vbymck.fsf@myrtle.ukc.ac.uk>
This is a basic question, I'm sure, but it has been frustrating me for days.
I am using Perl 5.0 on Solaris 8. All I want to do is accept command line
arguments. I am using getopt as follows:
---begin code snippet----
use Getopt::Std;
my %options;
getopt(`rsf`, \%options);
if ($opt_r){
print "Running Response Time Mode...\n";
$temp = $options{$opt_r};
print $temp;
&res_times;
}elsif ($opt_s){
&ref_eff;
}else{
die "Not working crack head.";
}
---end code snippet----
I've looked through the documentation, and the book I have available (the
Camelbook, but I think it's first edition...it's what they had....).
When I use getopt(`rsf`), the switches work fine. When I try to pass some
options, I don't get anything in the hash.
Command line> my_prog.pl -r Value my_file
Will not pick up Value, but
Command line> my_prog.pl -r my_file
Will pick up my switch, go into the sub routine, and process my_file.
Thanks for your patience and help toward a non-Perl programmer still trying to
learn.
Jake
--
Jake C. Posey | +44 (0)1227 827692
Junior Technical Support Officer | http://www.mau.ac.uk/
MAU/TAU | http://www.tau.ac.uk/
University of Kent at Canterbury | http://www.jisc.ac.uk/
------------------------------
Date: 13 Feb 2001 10:12:55 GMT
From: abigail@foad.org (Abigail)
Subject: Re: getopt doesn't
Message-Id: <slrn98i257.6o7.abigail@tsathoggua.rlyeh.net>
J.C.Posey (jcp@myrtle.ukc.ac.uk) wrote on MMDCCXXIII September MCMXCIII
in <URL:news:jkoy9vbymck.fsf@myrtle.ukc.ac.uk>:
:} This is a basic question, I'm sure, but it has been frustrating me for days.
:} I am using Perl 5.0 on Solaris 8. All I want to do is accept command line
:} arguments. I am using getopt as follows:
:}
:} ---begin code snippet----
:}
:} use Getopt::Std;
:}
:} my %options;
:}
:} getopt(`rsf`, \%options);
That calls a program called rsf....
Abigail
--
package Just_another_Perl_Hacker; sub print {($_=$_[0])=~ s/_/ /g;
print } sub __PACKAGE__ { &
print ( __PACKAGE__)} &
__PACKAGE__
( )
------------------------------
Date: 13 Feb 2001 10:36:12 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: getopt doesn't
Message-Id: <96b2ms$417$2@mamenchi.zrz.TU-Berlin.DE>
J.C.Posey <jcp@myrtle.ukc.ac.uk> wrote in comp.lang.perl.misc:
>This is a basic question, I'm sure, but it has been frustrating me for days.
>I am using Perl 5.0 on Solaris 8. All I want to do is accept command line
>arguments. I am using getopt as follows:
>
>---begin code snippet----
>
>use Getopt::Std;
>
>my %options;
>
>getopt(`rsf`, \%options);
Wrong quotes around "rsf". The backticks you're using will try to
execute the external program rsf and supplant its output. Use ''
instead.
>if ($opt_r){
> print "Running Response Time Mode...\n";
> $temp = $options{$opt_r};
> print $temp;
You might as well print $options{$opt_r} directly. But why do you
expect $options{$opt_r} to contain anything interesting? $opt_r
can either be "1" or undefined (but see below).
> &res_times;
>}elsif ($opt_s){
> &ref_eff;
>}else{
> die "Not working crack head.";
>}
>
>---end code snippet----
>
>I've looked through the documentation, and the book I have available (the
>Camelbook, but I think it's first edition...it's what they had....).
The best source of information about a module is usually the module
itself. If you do "perldoc Getopt::Std" you will find that the
getopt() function expects the option letters to take an argument.
If you have argument-less switches, use getopts().
You may further find that using the form of getopts with a hashref
as a second argument the global variables $opt_* are not set, so
using both in a single program is bound to fail.
Anno
------------------------------
Date: 13 Feb 2001 10:59:57 +0000
From: jcp@myrtle.ukc.ac.uk (J.C.Posey)
Subject: Re: getopt doesn't
Message-Id: <jkopugmq24y.fsf@myrtle.ukc.ac.uk>
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) writes:
> >---begin code snippet----
> >
> >use Getopt::Std;
> >
> >my %options;
> >
> >getopt(`rsf`, \%options);
>
> Wrong quotes around "rsf". The backticks you're using will try to
> execute the external program rsf and supplant its output. Use ''
> instead.
When I use '', the program hangs and doesn't execute. When I use ``, the
program reads my individual switches and runs, i.e. 'r' is identified, 's' is
identified, etc.
>
> >if ($opt_r){
> > print "Running Response Time Mode...\n";
> > $temp = $options{$opt_r};
> > print $temp;
>
> You might as well print $options{$opt_r} directly. But why do you
> expect $options{$opt_r} to contain anything interesting? $opt_r
> can either be "1" or undefined (but see below).
I thought that I should be able to print $options{$opt_r}, and I *thought* that
$opt_r operated as the key, but I see now that it does not...so how does one
go about referencing %options? Perldoc states:
"For those of you who don't like additional variables being
created, getopt() and getopts() will also accept a hash
reference as an optional second argument. Hash keys will be
x (where x is the switch name) with key values the value of
the argument or 1 if no argument is specified."
I understand this to mean that x is the switch name, i.e. $opt_r and I use
that to access my hash. But obviously I'm mistaken? Don't understand a thing?
>
> > &res_times;
> >}elsif ($opt_s){
> > &ref_eff;
> >}else{
> > die "Not working crack head.";
> >}
> >
> >---end code snippet----
> >
>
> The best source of information about a module is usually the module
> itself. If you do "perldoc Getopt::Std" you will find that the
> getopt() function expects the option letters to take an argument.
> If you have argument-less switches, use getopts().
Again, the way I understand the docs. getopt, getopts perform the same
function. I've tried using getopts(), but with the same results.
> You may further find that using the form of getopts with a hashref
> as a second argument the global variables $opt_* are not set, so
> using both in a single program is bound to fail.
I understood that if no second argument was passed, then the argument was
set to 1 by default. Obviously my understanding is misunderstanding. Any
further help would be greatly appreciated.
Maybe someone could be kind enough to produce a simply options code, an example
of a working getopt, with secondary options?
Regards,
Jake
--
Jake C. Posey | +44 (0)1227 827692
Junior Technical Support Officer | http://www.mau.ac.uk/
MAU/TAU | http://www.tau.ac.uk/
University of Kent at Canterbury | http://www.jisc.ac.uk/
------------------------------
Date: 13 Feb 2001 11:41:20 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: getopt doesn't
Message-Id: <96b6h0$a1n$1@mamenchi.zrz.TU-Berlin.DE>
J.C.Posey <jcp@myrtle.ukc.ac.uk> wrote in comp.lang.perl.misc:
>anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) writes:
>> >---begin code snippet----
>> >
>> >use Getopt::Std;
>> >
>> >my %options;
>> >
>> >getopt(`rsf`, \%options);
>>
>> Wrong quotes around "rsf". The backticks you're using will try to
>> execute the external program rsf and supplant its output. Use ''
>> instead.
>
>When I use '', the program hangs and doesn't execute. When I use ``, the
>program reads my individual switches and runs, i.e. 'r' is identified, 's' is
>identified, etc.
You must be misinterpreting-interpreting the results you see. Using backticks should
give you an error message (unless you happen to have an executable named
"rsf"). Using single quotes is (one) correct way to hand the switch
names down to getopt.
>>
>> >if ($opt_r){
>> > print "Running Response Time Mode...\n";
>> > $temp = $options{$opt_r};
>> > print $temp;
>>
>> You might as well print $options{$opt_r} directly. But why do you
>> expect $options{$opt_r} to contain anything interesting? $opt_r
>> can either be "1" or undefined (but see below).
>
>I thought that I should be able to print $options{$opt_r}, and I *thought* that
>$opt_r operated as the key, but I see now that it does not...so how does one
>go about referencing %options? Perldoc states:
>
>"For those of you who don't like additional variables being
> created, getopt() and getopts() will also accept a hash
> reference as an optional second argument. Hash keys will be
> x (where x is the switch name) with key values the value of
> the argument or 1 if no argument is specified."
>
>I understand this to mean that x is the switch name, i.e. $opt_r and I use
>that to access my hash. But obviously I'm mistaken? Don't understand a thing?
What makes you think "$opt_r" is the name of the switch? It's a Perl
scalar after all, and its value is described in the passage you quoted.
The switch names are simply the single letters your string "rsf" is made
of, i.e. "r", "s" and "f".
>>
>> > &res_times;
>> >}elsif ($opt_s){
>> > &ref_eff;
>> >}else{
>> > die "Not working crack head.";
>> >}
>> >
>> >---end code snippet----
>> >
>>
>> The best source of information about a module is usually the module
>> itself. If you do "perldoc Getopt::Std" you will find that the
>> getopt() function expects the option letters to take an argument.
>> If you have argument-less switches, use getopts().
>
>Again, the way I understand the docs. getopt, getopts perform the same
>function. I've tried using getopts(), but with the same results.
Then you haven't looked close enough. The difference is clearly
stated (under the Synopsis heading).
>> You may further find that using the form of getopts with a hashref
>> as a second argument the global variables $opt_* are not set, so
>> using both in a single program is bound to fail.
>
>I understood that if no second argument was passed, then the argument was
>set to 1 by default. Obviously my understanding is misunderstanding. Any
>further help would be greatly appreciated.
Without a second argument, the variables $opt_? are set, $opt_r for "r",
$opt_s for "s", etc. They are set to 1 for options that don't take an
argument and to the argument given for those that do.
With a second argument, these variables are *not* set. Instead, the
hash you have given takes the same values as above with a key that
is simply the switch name ("r", "s" and "f").
>Maybe someone could be kind enough to produce a simply options code, an example
>of a working getopt, with secondary options?
Just look at one of the Perl utilities that are already on your
machine. h2xs is one example that uses getopts() from Getopt::Std.
Anno
------------------------------
Date: 13 Feb 2001 08:37:12 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Global Variables
Message-Id: <96arno$jnd$1@mamenchi.zrz.TU-Berlin.DE>
Paul <pmckenna@writeme.com> wrote in comp.lang.perl.misc:
>I have a set of several different scripts and modules which all function
>together. I would like to create a single module which could house the
>global variables used by the scripts. For instance, all of the scripts
>need to access a certain named file. I would like to have this file
>implemented as a variable in all the various scripts and actually
>defined in a single place. I also don't want it to be redefined anywhere
>but in the master location. What is the best way of going about this?
>How do I make sure that my chosen master definition overides all other
>possible definitions. Thanks
Put your definitions in a module and use the module where needed.
Normally it is most handy to simply export a few scalar variables.
If you want to make sure values cannot be changed in other parts
of your program you can use constants. They are less flexible
however, because, being subroutines, they don't interpolate easily
into strings.
See perldoc perlmod and perldoc Exporter for details on how to set
up a module.
Anno
------------------------------
Date: 13 Feb 2001 13:51:58 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: How can I modify the value of a variable directly from within a sub?
Message-Id: <96be5u$h1f$1@mamenchi.zrz.TU-Berlin.DE>
Godzilla! <godzilla@stomp.stomp.tokyo> wrote in comp.lang.perl.misc:
>Randal wrote:
>
>> >>>>> Godzilla! wrote:
>
>> Godzilla!> Try this syntax:
>
>> Godzilla!> $number = ${\&commify($number)};
>
>> Operative word being "try" because the dereferencing of the reference
>> really isn't getting you anything.
>
>> This code can be trivially transformed, accomplishing the same thing
>> with less CPU, to:
>
>> $number = commify($number);
>
>> And we're back to where we started.
>
>Works too! I tested both formats.
It's uncontested that it works, if "works" means it assigns the
commify()d version of $number to $number. The problem is actually
that it works too much, doing unnecessary referencing and de-referencing.
The other problem is that it doesn't solve the OP's problem, which
was how to modify the value of $number in place, without an explicit
use of assignment.
Anno
PS: sub commify_in_place { $_[ 0] = commify( $_[ 0]) }
This uses the fact that @_ is a list of aliases to the original
arguments.
------------------------------
Date: 13 Feb 2001 04:09:32 -0600
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: measuring sizeof of STDIN
Message-Id: <96b14s$kj3$1@boomer.cs.utexas.edu>
In article <Zn4i6.17625$lI2.19423@news1.rochd1.qld.optushome.com.au>,
Sean <sean@tnq.com> wrote:
>When I do something like:
>cat test.msg | ./perltest.pl
>
>I can manipulate the data using \*STDIN
>
>What is available to me to also find out the size (in bytes) that is being
>piped to the perl script?
There is no way to tell. The size of the input might be infinite.
It all depends on the program that is sending the data. (The "cat"
program is supposed to print the file and exit, but how do you know
it will really do that? Maybe someone will come along and open
'test.msg' and add more data to the end of it.)
The best that you can do is simply read all the input, count how much
you've read, and hope that the program sending data through the pipe
terminates.
- Logan
--
my your his her our their *its*
I'm you're he's she's we're they're *it's*
------------------------------
Date: Tue, 13 Feb 2001 12:16:15 GMT
From: clintp@geeksalad.org (Clinton A. Pierce)
Subject: Re: need help going from UNIX to Windows
Message-Id: <jA9i6.306694$hD4.73207706@news1.rdc1.mi.home.com>
[Posted and mailed]
In article <MZ3i6.216$NE2.218622@news.pacbell.net>,
"Jeff Fletcher" <jeff_fletcher@pacbell.net> writes:
> 1. Most of my scripts are pretty simple, and work with either version of
> Perl. In fact they work on my new server when called directly, but when they
> are called from an SSI into an HTML page, I get some strange output like
> this: HTTP/1.1 200 OK Date: Tue, 13 Feb 2001 05:43:21 GMT Server:
> Microsoft-IIS/5.0 Content-type: text/html. Can anyone explain that?
Yeah...you need to not emit a header, IIS is going to do that for you.
(Which makes writing CGI that emit things other than text/html No Fun.)
Try:
use CGI (-nph); # Check this, it's been a while.
> 2. This may sound silly, but I don't understand this command line stuff?
> I've tried opening an MS-DOS window and typing the commands in there, but
> that doesn't work. I've tried opening the perl.exe (recently downloaded)
> window, and nothing I type in there seems to do anything. Until I figure
> this out, it's a major stumbling block to my doing anything else.
What commands are you typing? ls? vi? Of course not. dir and edit are
the native ones. (You can install Unix replacements). Also, perl may
not be in your path. If perl -v doesn't give you the version, you'll have
to correct that.
And you can't open a "perl.exe" window. That's the interpreter. It'll run
and expect you to type a perl program at it. Just like if you've started
perl at the command prompt in Unix.
Put your script in a file (with edit or notepad or something) and then
run it by typing:
perl myscriptfilename
At the command prompt.
--
Clinton A. Pierce Teach Yourself Perl in 24 Hours *and*
clintp@geeksalad.org Perl Developer's Dictionary -- May 2001
"If you rush a Miracle Man, for details, see http://geeksalad.org
you get rotten Miracles." --Miracle Max, The Princess Bride
------------------------------
Date: Tue, 13 Feb 2001 11:48:57 +0100
From: "Jonas Nilsson" <jonni@ifm.liu.se>
Subject: Re: Performance question
Message-Id: <96b3cm$j4$1@newsy.ifm.liu.se>
use Benchmark to time different codes. (perldoc Benchmark)
look into
perldoc -f substr
It might be faster.
/jN
--
_____________________ _____________________
| Jonas Nilsson | | |
|Linkoping University | | Telephone |
| IFM | | --------- |
| Dept. of Chemistry | | work: +46-13-285690 |
| 581 83 Linkoping | | fax: +46-13-281399 |
| Sweden | | home: +46-13-130294 |
|_____________________| |_____________________|
"Paul" <pmckenna@writeme.com> wrote in message
news:3A88E2A3.FB93B497@writeme.com...
> I need to parse a very long text file and remove about 25+ different
> words as well as punctuation. Words like "a" "the" "of" and so forth.
> What I have done is string together a series of ORs like
> s/\bthe\b/\bof\b/............ This seems so awkward and I am sure is
> very slow. Is there a more elegant and faster way to this kind of
> substitution. Thanks
>
> Paul
>
------------------------------
Date: Tue, 13 Feb 2001 07:56:43 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Perl FAQ: Stripping blank space
Message-Id: <3A88E9D8.3A8EE157@acm.org>
Jeffrey Nowakowski wrote:
>
> Joe Schaefer <joe+usenet@sunstarsys.com> writes:
>
> > Jeffrey Nowakowski <jeffno@denali.ccs.neu.edu> writes:
> >
> > > There exists in the Perl FAQ the question "How do I strip blank space
> > > from the beginning/end of a string?"
> > >
> > > Could the FAQ maintainer please add the question "Why doesn't Perl
> > > include a built in function to do this?"
> >
> > What do you suggest the answer should be?
> >
> > A : Perl has a regexp engine that can do this trivially.
> > Hence, Perl doesn't need an extremely specialized function
> > (Perl already has it's fair share of those.) If you really
> > want to, you could always write your own:
>
> I'd prefer the answer: It was an oversight and will be added in.
>
> The operation is so common that to not include it is just silly.
> Defining a subroutine yourself is nowhere near as convenient as having
> a built-in API.
A lot of languages don't have this. Are you whining on all their
newsgroups too?
John
------------------------------
Date: Tue, 13 Feb 2001 12:19:33 GMT
From: pjlees@ics.forthcomingevents.gr (Philip Lees)
Subject: Re: Scaling up sample data in an array of hashes
Message-Id: <3a892505.79975168@news.grnet.gr>
On Sat, 10 Feb 2001 03:35:01 GMT, "Ben Kennedy" <bkennedy99@Home.com>
wrote:
>You could use map to create the new hash with something like
>
>my($i,$tmpval);
>
>my %newhash = map {
> $i++ % 2 and $tmpval = int(rand(@patients));
> ($_, $patients[$tmpval]{$_} )
> } qw(lastname ename1 firstname ename2 fathersnam ename3 birthdata);
>
>++$max_id;
>$newhash{patcode} = $max_id;
>push @patients, \%newhash;
>
>On each iteration of map, a new array index is picked on the 1st, 3rd, and
>5th elements, then the key -> value pair is added to the hash
Thanks for responding, Ben. it took me some time to figure out how
this works - a valuable piece of Perl education for me.
As it stands, it's not quite right, but changing $i++ to ++$i does the
trick. It's certainly much neater (and niftier) than what I had.
Phil
--
Philip Lees
ICS-FORTH, Heraklion, Crete, Greece
Ignore coming events if you wish to send me e-mail
'The aim of high technology should be to simplify, not complicate' - Hans Christian von Baeyer
------------------------------
Date: Tue, 13 Feb 2001 10:44:18 +0100
From: "Per- Fredrik Pollnow" <Per-fredrik.Pollnow@epk.ericsson.se>
Subject: shadow file, replace *LK*
Message-Id: <96auvj$7ho$1@newstoo.ericsson.se>
Hi,
I need some help with a script...
The script is going to replace *LK* in a Solaris shadow file, and I cant
figure out how to do.
The shadow file look like this:
/etc/shadow
bin:NP:6445::::::
sys:NP:6445::::::
adm:NP:6445::::::
lp:NP:6445::::::
smtp:NP:6445::::::
uucp:NP:6445::::::
nuucp:NP:6445::::::
listen:*LK*:::::::
nobody:NP:6445::::::
noaccess:NP:6445::::::
nobody4:NP:6445::::::
I want the: listen:*LK*:::::::
to bee: listen:tada:::::::
and then be saved as /etc/shadow.new
Can someone do an example fore me so I can see how to do this I wold be
thankful..
/PS: Please Email me if you know how to do, I'm out of office so I cant
follow the mail list.
------------------------------
Date: Tue, 13 Feb 2001 11:18:13 +0100
From: "Dr. Peter Dintelmann" <Peter.Dintelmann@dresdner-bank.com>
Subject: Re: shadow file, replace *LK*
Message-Id: <96b195$f0c2@news-1.bank.dresdner.net>
Hi,
"Per- Fredrik Pollnow" <Per-fredrik.Pollnow@epk.ericsson.se> wrote in
message news:96auvj$7ho$1@newstoo.ericsson.se...
> Hi,
>
> I need some help with a script...
>
> The script is going to replace *LK* in a Solaris shadow file, and I cant
> figure out how to do.
[snip]
so you want to replace all the NP with *LK*, right?
What about
perl -pe "s/:NP/:\*LK\*/" /etc/shadow >/var/tmp/shadow.new
HTH,
Peter Dintelmann
------------------------------
Date: Tue, 13 Feb 2001 11:44:10 +0100
From: "Jonas Nilsson" <jonni@ifm.liu.se>
Subject: Re: shadow file, replace *LK*
Message-Id: <96b33n$a6$1@newsy.ifm.liu.se>
open(FILE,"</etc/shadow");
{
local($\); #slurp mode;
$data=<FILE>;
}
close(FILE);
$data=~s/\*LK\*/tada/g;
open(FILE,">/etc/shadow.new");
print FILE $data;
close(FILE);
/jN
--
_____________________ _____________________
| Jonas Nilsson | | |
|Linkoping University | | Telephone |
| IFM | | --------- |
| Dept. of Chemistry | | work: +46-13-285690 |
| 581 83 Linkoping | | fax: +46-13-281399 |
| Sweden | | home: +46-13-130294 |
|_____________________| |_____________________|
"Per- Fredrik Pollnow" <Per-fredrik.Pollnow@epk.ericsson.se> wrote in
message news:96auvj$7ho$1@newstoo.ericsson.se...
> Hi,
>
> I need some help with a script...
>
> The script is going to replace *LK* in a Solaris shadow file, and I cant
> figure out how to do.
>
> The shadow file look like this:
>
> /etc/shadow
>
> bin:NP:6445::::::
> sys:NP:6445::::::
> adm:NP:6445::::::
> lp:NP:6445::::::
> smtp:NP:6445::::::
> uucp:NP:6445::::::
> nuucp:NP:6445::::::
> listen:*LK*:::::::
> nobody:NP:6445::::::
> noaccess:NP:6445::::::
> nobody4:NP:6445::::::
>
> I want the: listen:*LK*:::::::
> to bee: listen:tada:::::::
>
> and then be saved as /etc/shadow.new
>
> Can someone do an example fore me so I can see how to do this I wold be
> thankful..
>
> /PS: Please Email me if you know how to do, I'm out of office so I cant
> follow the mail list.
>
>
------------------------------
Date: 13 Feb 2001 10:54:41 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: shadow file, replace *LK*
Message-Id: <96b3ph$5ml$1@mamenchi.zrz.TU-Berlin.DE>
Per- Fredrik Pollnow <Per-fredrik.Pollnow@epk.ericsson.se> wrote in comp.lang.perl.misc:
>Hi,
>
>I need some help with a script...
>
>The script is going to replace *LK* in a Solaris shadow file, and I cant
>figure out how to do.
So what have you tried so far and where is the problem?
>The shadow file look like this:
[snip]
>and then be saved as /etc/shadow.new
>
>Can someone do an example fore me so I can see how to do this I wold be
>thankful..
Again, where is the problem? Matching a literal asterisk? Answer:
escape it. Writing back the modified file? Answer: check out Perl's
-i switch. Something else?
>/PS: Please Email me if you know how to do, I'm out of office so I cant
>follow the mail list.
No sir. Post here, read here.
This group discusses (among other things) problems in the usage of
the Perl language. It is not a service that mails you ready-made
solutions. Usenet is useful, but not that useful.
Anno
------------------------------
Date: Tue, 13 Feb 2001 13:26:45 +0100
From: "Per- Fredrik Pollnow" <Per-fredrik.Pollnow@epk.ericsson.se>
Subject: Re: shadow file, replace *LK*
Message-Id: <96b8g7$q88$1@newstoo.ericsson.se>
Thanx
"Dr. Peter Dintelmann" <Peter.Dintelmann@dresdner-bank.com> wrote in message
news:96b195$f0c2@news-1.bank.dresdner.net...
> Hi,
>
> "Per- Fredrik Pollnow" <Per-fredrik.Pollnow@epk.ericsson.se> wrote in
> message news:96auvj$7ho$1@newstoo.ericsson.se...
> > Hi,
> >
> > I need some help with a script...
> >
> > The script is going to replace *LK* in a Solaris shadow file, and I cant
> > figure out how to do.
>
> [snip]
>
> so you want to replace all the NP with *LK*, right?
> What about
>
> perl -pe "s/:NP/:\*LK\*/" /etc/shadow >/var/tmp/shadow.new
>
> HTH,
>
> Peter Dintelmann
>
>
>
------------------------------
Date: Tue, 13 Feb 2001 11:35:16 GMT
From: "Sean" <sean@tnq.com>
Subject: STDIN - mutliple actions
Message-Id: <UZ8i6.17665$lI2.19446@news1.rochd1.qld.optushome.com.au>
Trying to do 2 different actions to stdin, can I not seek to the start of
the STDIN after I use it? (piped to the perl script) because it is "gone",
or do I have to move STDIN to a temp file to do this?
Just curious about my options?
while (<STDIN>) {
$bytes +=length;
}
print $bytes;
$where=tell(<STDIN>);
print $where; # returns -1 ??
seek(STDIN,$where,0);
my $msg = new Mail::Internet \*STDIN;
....
...
..
.
Sean
------------------------------
Date: 13 Feb 2001 11:50:51 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: STDIN - mutliple actions
Message-Id: <96b72r$a1n$2@mamenchi.zrz.TU-Berlin.DE>
Sean <sean@tnq.com> wrote in comp.lang.perl.misc:
>Trying to do 2 different actions to stdin, can I not seek to the start of
>the STDIN after I use it? (piped to the perl script) because it is "gone",
>or do I have to move STDIN to a temp file to do this?
>
>Just curious about my options?
Some files are seekable (mainly ordinary disk files), others aren't
(sockets, terminals). When all you have is a file handle (STDIN or
otherwise) you usually don't know what kind of file is behind it, so
it is best not to assume anything.
You can test if a file is seekable, preferably using the tell()
function which should succeed on any file handle that is seekable
at all. Then you can either tell the user the file is no good, or
think of something else to re-read the data.
Anno
------------------------------
Date: Tue, 13 Feb 2001 10:21:52 -0000
From: "DaveP" <DavePerkins@bigfoot.com>
Subject: Thanks - just what I needed.
Message-Id: <96b1qq$fri$1@news8.svr.pol.co.uk>
Joe, Wyzell - Many thanks
>>>This wouldn't be a HW problem now, would it?
? No. I have a file full of licence numbers that I want to issue to
customers by removing them one by one from the end of the file.
David
------------------------------
Date: Tue, 13 Feb 2001 10:13:29 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Two dimensional arrays
Message-Id: <slrn98i265.999.tjla@thislove.dyndns.org>
I was shocked! How could Mahesh A <maheshasolkar@yahoo.com>
say such a terrible thing:
>#!/usr/local/bin/perl -w
>use strict;
>
>my @lines=<DATA>;
>my $lines = length ($lines[0]);
>for my $i (1..$lines-1) {
> map {
> s/\n\r//g;
> print ${[split //]}[$i] if (${[split //]}[$i] =~ /\S/);
> } @lines;
> print " ";
>}
>print "\n";
Much better.
--
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
"Life is too important to take seriously."
-- Corky Siegel
------------------------------
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 280
**************************************