[18062] in Perl-Users-Digest
Perl-Users Digest, Issue: 222 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Feb 6 11:06:08 2001
Date: Tue, 6 Feb 2001 08: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: <981475510-v10-i222@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 6 Feb 2001 Volume: 10 Number: 222
Today's topics:
a bug in perl-5.6.0? <morozov@novosoft.ru>
Convert from base 10 to hex <leekembel@hotmail.com>
Re: Create executable from Perl script (Reto Hersiczky)
Directory structure <jp@eyup.org>
directory where perl script is located. <greyrider@iname.com>
Re: directory where perl script is located. (Anno Siegel)
Re: directory where perl script is located. <greyrider@iname.com>
Re: Emailing with a file attached (Reto Hersiczky)
Re: Emailing with a file attached <bdulfer@my-deja.com>
Re: Handling flock failure (Garry Williams)
Re: Hello. I'm back. (Tad McClellan)
Re: how do I use 'strict' and 'vars' (Tad McClellan)
Re: Is scalar a float, int or string? (Mark Jason Dominus)
Re: Is scalar a float, int or string? (Peter J. Acklam)
Re: Is this a rename() bug??? richardstands@my-deja.com
Re: JAPH <mischief@velma.motion.net>
MSIE, XML and Accents <maw@markaw.com>
Re: MSIE, XML and Accents <ptittom+news@free.fr>
Re: MSIE, XML and Accents <maw@markaw.com>
Re: newbie - grep non-used uid from passwd <wyzelli@yahoo.com>
Re: newbie - grep non-used uid from passwd <krahnj@acm.org>
Re: newbie - grep non-used uid from passwd <kolisko@penguin.cz>
Re: newbie - grep non-used uid from passwd <kolisko@penguin.cz>
Re: perl & expect - STDOUT vs. redirect to file (Garry Williams)
Re: perl & expect - STDOUT vs. redirect to file (Rudolf Polzer)
perl -V error edis9@my-deja.com
Printing from "@_" <gvautour@nb.sympatico.ca>
Re: Printing from "@_" <joe+usenet@sunstarsys.com>
Re: Problem opening for writing, going nuts, please hel <red_orc@my-deja.com>
Re: Redirecting stdout/stderr from a call to system() dave_vb@my-deja.com
Re: suidperl problem <mischief@velma.motion.net>
test creation and delivery systems <polemarch@fut.net>
There is a project of new game for InterCasino. <delphi@ns.tchercom.ru>
Re: Using Braces <mischief@velma.motion.net>
Using tie in an OO-like manner myrddin_charis@my-deja.com
Re: Very Newbie: perlcc on NT <graham_j_bailey@my-deja.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 6 Feb 2001 12:15:33 GMT
From: Alexey Morozov <morozov@novosoft.ru>
Subject: a bug in perl-5.6.0?
Message-Id: <95opt5$u8b$1@news.itfs.nsk.su>
Look at two sample scripts:
-----------------------------------------------------
use strict;
my @array = ('a','b',undef,'c','d');
my @results = map {
;
SWITCH:
{
$_.'null', last SWITCH unless defined $_;
$_.$_, last SWITCH if ($_ eq 'a');
$_.", wow!", last SWITCH if ($_ eq 'b');
$_." default";
}
} @array;
print "Results: ('".join("', '",@results)."')\n";
-----------------------------------------------------
my @array = ('a','b',undef,'c','d');
my @results = map {
;
SWITCH:
{
'null', last SWITCH unless defined $_; # this line was changed
$_.$_, last SWITCH if ($_ eq 'a');
$_.", wow!", last SWITCH if ($_ eq 'b');
$_." default";
}
} @array;
print "Results: ('".join("', '",@results)."')\n";
-----------------------------------------------------
Do you see the significant difference between these two? I don't.
Nevertheless, the first is compiled and work properly, the second can not
even be compiled. If we change that line to, say
''.'null', last SWITCH unless defined $_;
we even get result, but the _wrong_ result
(Results: ('aa', 'b, wow!', 'c default', 'd default')).
I can't explain this. Please suggest.
SY, Alexey Morozov
------------------------------
Date: Tue, 06 Feb 2001 16:00:26 GMT
From: "Studio 51" <leekembel@hotmail.com>
Subject: Convert from base 10 to hex
Message-Id: <ucVf6.90743$V22.18386025@news4.rdc1.on.home.com>
What's the easiest way to convert a number from base 10 to hex? The value
will always be between 0 and 255.
LKembel
------------------------------
Date: 6 Feb 2001 14:42:06 GMT
From: fight_against_spam_cut_here_retoh@dplanet.ch (Reto Hersiczky)
Subject: Re: Create executable from Perl script
Message-Id: <Xns90409A15Afightagainstspamcuth@195.141.200.222>
If you need speed, you should install mod_perl.
If you need to protect your intellectual property or a useful way to
distribute your program to customers, you should use one of the Perl
compilers available on the market. Indigo's Perl2Exe is truly recommended.
It has useful pragmas so you can join several Modules together in a single
executable.
I'm not quite sure about the speed and memory question, but as far I
have observed, the scripts seems to run a bit faster. Assume the
memory consumption is a very little bit higher than running that
your script ordinary. What a Perl compiler does, is usually join
your script together with the Parser and set the boot start address
for the OS.
--Reto
"Studio 51" <leekembel@hotmail.com> wrote in
<iAUe6.61037$V22.12720657@news4.rdc1.on.home.com>:
>I guess theres few options out there for doing this, Indigo's Perl2Exe,
>and activestate has something called PerlApp. What I'm wondering is how
>they compare to a regular Perl script?
>
>Is there a speed difference?
>
>Do they use more/less resources?
>
>Are there any other limitations? Maybe some functions don't work so
>well?
>
>Is there anyone out there that's done this on a regular basis, or use a
>Perl executable in a high-load environment, and would like to share
>thier experiences?
>
>
>LKembel
------------------------------
Date: Tue, 06 Feb 2001 14:54:40 GMT
From: John Poltorak <jp@eyup.org>
Subject: Directory structure
Message-Id: <3A801051.3741A9D4@eyup.org>
Can someone give a pointer to what a typical directory structure looks
like wrt PERL?
I want to install PERL on OS/2 but would like to get as close as
possible to a Unix-like
directory structure.
--
John
------------------------------
Date: Tue, 6 Feb 2001 14:59:22 +0200
From: "Lloyd" <greyrider@iname.com>
Subject: directory where perl script is located.
Message-Id: <3a7ff485$0$231@hades.is.co.za>
Hi, I have a small problem.
I've written a package which when installed is not in the same directory as
the perl script which 'use's it. I need that package to know the directory
in which the perl script is located.
I've found a solution, but I'd like to know if there isn't a simpler
(perhaps predefined variable) method...
My solution as it stands:
#import cool current working directory package.
use Cwd;
#get the script path and name from cmd line. Such as "../../dir/script.pl"
my $dollarzero = $0;
#match against path containing forward or back - slashes
my $pathonly = '';
if ($dollarzero =~ /(.*[\\\/]).*/) {$pathonly = $1;}
#below: cwd gives current directory. abs path gives canonical path.
my $scriptpath = Cwd::abs_path(Cwd::cwd."/".$pathonly);
thanks in advance.
------------------------------
Date: 6 Feb 2001 14:00:33 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: directory where perl script is located.
Message-Id: <95p021$rh4$1@mamenchi.zrz.TU-Berlin.DE>
Lloyd <greyrider@iname.com> wrote in comp.lang.perl.misc:
>Hi, I have a small problem.
>I've written a package which when installed is not in the same directory as
>the perl script which 'use's it. I need that package to know the directory
>in which the perl script is located.
>
>I've found a solution, but I'd like to know if there isn't a simpler
>(perhaps predefined variable) method...
>
>My solution as it stands:
>#import cool current working directory package.
> use Cwd;
>
>#get the script path and name from cmd line. Such as "../../dir/script.pl"
> my $dollarzero = $0;
The content of $0 is famous for being non-portable. In particular,
when your script is found somewhere on your (Unix-) path, you
may end up with the full path name of the script that is actually
found (good for your algorithm) or with just the name the script
was called as (bad).
>#match against path containing forward or back - slashes
> my $pathonly = '';
> if ($dollarzero =~ /(.*[\\\/]).*/) {$pathonly = $1;}
>
> #below: cwd gives current directory. abs path gives canonical path.
> my $scriptpath = Cwd::abs_path(Cwd::cwd."/".$pathonly);
The module "FindBin" has been written to address the portability
problems involved. I'd recommend using that.
Anno
------------------------------
Date: Tue, 6 Feb 2001 16:35:59 +0200
From: "Lloyd" <greyrider@iname.com>
Subject: Re: directory where perl script is located.
Message-Id: <3a800b2a$0$226@hades.is.co.za>
Thank you Anno, this is _exactly_ what I was looking for.
Anno replied to Lloyd with ...
.The content of $0 is famous for being non-portable. In particular,
.when your script is found somewhere on your (Unix-) path, you
.may end up with the full path name of the script that is actually
.found (good for your algorithm) or with just the name the script
.was called as (bad).
.The module "FindBin" has been written to address the portability
.problems involved. I'd recommend using that.
------------------------------
Date: 6 Feb 2001 11:27:36 GMT
From: fight_against_spam_cut_here_retoh@dplanet.ch (Reto Hersiczky)
Subject: Re: Emailing with a file attached
Message-Id: <Xns904078AEFfightagainstspamcuth@195.141.200.222>
Use MIME::Lite for that task!
Sample code snippet:
eval("use MIME::Lite");
Error "Seems MIME::Lite is'nt installed yet on this machine $@" if $@;
my $message = MIME::Lite->new(
From => 'reply@yourhost.com' ,
To => 'your-customer@custhost.com ,
Subject => 'your attachment in this mail',
Type => 'text/plain',
Encoding => '8bit',
Data => "Dear Sirs,\nBest regards,\nbla bla"
);
my ($mime_type, $encoding) = ('application/octet-stream', 'base64');
$message->attach (
Type => $mime_type ,
Encoding => $encoding ,
Path => '/home/attachments/offer.doc' ,
Filename => 'offer.doc'
);
# ----- Tell MIME::Lite to use Net::SMTP instead of sendmail
MIME::Lite->send('smtp', 'smtp.your-smtp-host.com', Timeout => 20);
$message->send;
--Reto
------------------------------
Date: Tue, 06 Feb 2001 11:34:47 GMT
From: Bernd Dulfer <bdulfer@my-deja.com>
Subject: Re: Emailing with a file attached
Message-Id: <95ongn$rhj$1@nnrp1.deja.com>
Hi Eric
> I have a perl script that needs to be able to send an email with an
> attached ascii file.
try Mail::Mailer from CPAN
rgds
--
Bernd Dulfer
Sybase Professional Services Germany
bdulfer@sybase.com.spam.no
Sybase Manuals: http://sybooks.sybase.com
Sybase FAQ: http://www.isug.com/Sybase_FAQ
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Tue, 06 Feb 2001 13:39:16 GMT
From: garry@zvolve.com (Garry Williams)
Subject: Re: Handling flock failure
Message-Id: <88Tf6.40$561.1395@eagle.america.net>
On Tue, 6 Feb 2001 08:28:30 -0000, Andy <flair@blueyonder.co.uk> wrote:
>Probably a simple thing but it's got me stumped at present! I've got a perl
>script that opens a semaphore file, attempts to flock it and if the flock is
>successful add data to a log file then go on and display a web page.
>
>What I would like to do is add some code so that if the flock has not
>succeeded after say 3 seconds, we just skip the logging bit and go on with
>displaying the output page.
This is a FAQ. See the perlfaq8 manual page, "How do I timeout a slow
event?".
--
Garry Williams
------------------------------
Date: Tue, 06 Feb 2001 14:07:58 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Hello. I'm back.
Message-Id: <slrn97vpkn.56b.tadmc@tadmc26.august.net>
Philip Newton <clpmisc@newton.digitalspace.net> wrote:
>On Fri, 19 Jan 2001 14:09:51 GMT, tadmc@augustmail.com (Tad McClellan) wrote:
>
>> I collect perl-related scorefiles (several have been posted here
>> in the past, some I requested in email), I wouldn't have thought
>> to look in an article with this Subject though...
>
>Could you make them available? For example, put them on a web or ftp site
>somewhere?
That has been on my To Do list.
I have a tuit shortage, but I will eventually put them on a website
somewhere (after sanitizing them some).
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 06 Feb 2001 14:07:59 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: how do I use 'strict' and 'vars'
Message-Id: <slrn97vpp0.56b.tadmc@tadmc26.august.net>
Joel Nelson <extramail@home.com> wrote:
>Abigail wrote:
>
>> Joel Nelson (extramail@home.com) wrote on MMDCCVIII September MCMXCIII in
>> <URL:news:3A74C1AD.F664EBAE@home.com>:
>> && When I use 'strict' I get a lot of :
>> &&
>> && Global symbol $soAndSo requires explicit package name at scriptName.cgi
>> && line 22
>> man vars
>> man strict
>>
>> Could it have been more obvious?
>Hah! You assume I'm on unix.
Then you do this instead:
perldoc vars
perldoc strict
>So no, it could NOT have been more obvious.
Seems a bit obvious still...
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 06 Feb 2001 13:37:43 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: Is scalar a float, int or string?
Message-Id: <3a7ffe27.502$39a@news.op.net>
In article <95ndjm$ps9$1@nnrp1.deja.com>,
Daniel Pfeiffer <occitan@esperanto.org> wrote:
>When treating a number passed in as a scalar, I need to do nothing if it
>is an int, split it up if it is a float, transform it and possibly split
>it up if it is a string. Question is, how can I tell what it is _very_
>efficiently, i.e. without potentially casting it to a string and then
>parsing that.
I think the Devel::Peek module has a function that will tell you which
of the NV, IV, and PV slots in a scalar is populated. I suggest you
look at that.
I don't think there is any way to do it in pure Perl without using an
extension.
--
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print
------------------------------
Date: 06 Feb 2001 14:48:27 +0100
From: jacklam@math.uio.no (Peter J. Acklam)
Subject: Re: Is scalar a float, int or string?
Message-Id: <wkofwgne1w.fsf@math.uio.no>
Daniel Pfeiffer <occitan@esperanto.org> writes:
> Background is that I am currently rewriting Math::BigInt, which
> was lousy and has now become faster by a varying (enormous in
> some cases) factor. And I need this for an optimal "new"
> method.
Umm...if you don't know enough Perl to answer this question,
perhaps you shouldn't be messing with the Math::BigInt module.
Peter
--
sub int2roman{@x=split//,sprintf'%04d',shift;@r=('','I','V','X','L','C','D'
,'M');@p=([],[1],[1,1],[1,1,1],[1,2],[2],[2,1],[2,1,1],[2,1,1,1],[1,3],[3])
;join'',@r[map($_+6,@{$p[$x[0]]}),map($_+4,@{$p[$x[1]]}),map($_+2,@{$p[$x[2
]]}),map($_+0,@{$p[$x[3]]})];}print "@{[map{int2roman($_)}@ARGV]}\n";#JAPH!
------------------------------
Date: Tue, 06 Feb 2001 13:46:34 GMT
From: richardstands@my-deja.com
Subject: Re: Is this a rename() bug???
Message-Id: <95ov7p$1gk$1@nnrp1.deja.com>
I got to thinking more about this. You are right, on some levels it's
the same file, but the name can be changed to the short 8.3 form so
that wherever it appears on disk/wherever you list it that short name
is the one that appears. Yea, it's a Windows thing for sure, one file
that can be referred to with different names :o( just to be 8.3
compliant. So I guess the reason none of the forms of "rename" work is
that they get "short-circuited" because the file to rename to
technically already exists hence they do nothing. I got around this by
<KLUDGE>
renaming the long file to a temp name then finally to the short form.
</KLUDGE>
-Rich
In article <95na2f$mkb$1@nnrp1.deja.com>,
bits101010@my-deja.com wrote:
> The short name is still referring to the original file name (in short
> form only). You haven't changed it at all.
>
> In article <95n8cr$kur$1@nnrp1.deja.com>,
> richardstands@my-deja.com wrote:
> > This appears to be a bug, at least on Windows NT 4.0 with Active
> > State's Perl "v5.6.0 built for MSWin32-x86-multi-thread". If you
> > attempt to rename a file in the same directory with its valid Win32
> > short name rename() will return success(1) but won't rename the
file:
> >
> > #!perl -w
> >
> > use strict;
> > use Win32;
> >
> > my $foo = "d:\\temp\\this is a foo.txt";
> >
> > my $bar = Win32::GetShortPathName( $foo );
> > # -OR-
> > # my $bar = "d:\\temp\\THISIS~1.TXT";
> >
> > print rename( $foo, $bar ), "\n";
> >
> > This prints "1" but the file is not renamed. It works if you simply
> > change the value of $bar to say "d:\\temp\\THISBE~1.TXT"
> > or "d:\\THISIS~1.TXT"(different target directory). Does anyone know
> why
> > this happens? Can it be fixed? Thanks :o)
> >
> > -Rich
> >
> > Sent via Deja.com
> > http://www.deja.com/
> >
>
> Sent via Deja.com
> http://www.deja.com/
>
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Tue, 06 Feb 2001 15:42:38 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: JAPH
Message-Id: <t806rebp9b0f27@corp.supernews.com>
amonotod <amonotod@netscape.net> wrote:
> In article <3A7C42B4.3B42484E@stomp.stomp.tokyo>,
> "Godzilla!" <godzilla@stomp.stomp.tokyo> wrote:
>> Just when you think your Just Another Perl Hacker
>> signature file is the ultimate, along comes Godzilla!
> <snip>
>> Godzilla! Just Amazing Perl Hacker
>> --
> <snip some "obfuscated" code>
> You are such a moronzilla. That is not a JAPH.
> From the Perl FAQ:
> http://theoryx5.uwinnipeg.ca/CPAN/perl/pod/perlfaq1/What_is_a_JAPH_.html
> As described by Abigail:
> http://x68.deja.com/[ST_rn=ps]/getdoc.xp?AN=663707134&CONTEXT=981390637.
> 1910243439&hitnum=18
Agreed. .sig blocks have been around a while. A JAPH has to
reproduce the string 'Just another Perl Hacker' or something
very similar. If it's a .sig that's not a JAPH, just call it
a .sig so people don't jump into terminology wars, please. ;)
Chris
--
Christopher E. Stith
Even in the worst of times, there is always someone who's
never had it better. Even in the best of times, there is
always someone who's never had it worse.
------------------------------
Date: Tue, 6 Feb 2001 13:40:41 -0000
From: "Mark A. Williams" <maw@markaw.com>
Subject: MSIE, XML and Accents
Message-Id: <3a7fff08_1@nnrp1.news.uk.psi.net>
Hi,
I am having troubles with this peice of XML in MSIE 5.5. Basically it fails
on the accented e (é) in the <description> data - specifically the word
ingénieur . Can anyone help me out? Is there something I am missing? As you
can see I have changed characters like & ' " < and > Does this mean I need
to change all accented characters as well?
Thanks
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="jobserve.xsl" ?>
<items>
<detail>
<number>00001</number>
<description>Nous recherchons pour le compte de l'un de nos client un
Chef/Directeur de Projet CRM. Vous participerez des missions de definition
des besoins, de pilotage de projets, de conception ou de mise en place. Vous
tes ingénieur ou Bac +4/5 en informatique avec une experience de 3 10
ans.</description>
<location>Paris, France</location>
</detail>
</items>
------------------------------
Date: Tue, 6 Feb 2001 14:54:21 +0100
From: Tom. <ptittom+news@free.fr>
Subject: Re: MSIE, XML and Accents
Message-Id: <95ovl4$bq7$1@wanadoo.fr>
In <3a7fff08_1@nnrp1.news.uk.psi.net>, Mark A. Williams wrote:
> I am having troubles with this peice of XML in MSIE 5.5. Basically it
> fails on the accented e (é) in the <description> data - specifically the
> word ingénieur . Can anyone help me out? Is there something I am missing?
> [...]
> <?xml version="1.0"?>
This means your file is encoded in utf-8 or utf-16.
> Vous tes ingénieur ou Bac +4/5 en informatique avec une experience de 3 10
This seams to be encoded in iso-8859-1, incompatible with any utf encoding.
HTH
Tom.
------------------------------
Date: Tue, 6 Feb 2001 13:59:12 -0000
From: "Mark A. Williams" <maw@markaw.com>
Subject: Re: MSIE, XML and Accents
Message-Id: <3a80033c_1@nnrp1.news.uk.psi.net>
So, forgive me the obvous question, but how do I overcome this so that I can
make use of it, bearing in mind that in "real life" there are many <detail>
elements which are written English, although may include the odd French
<description>..... ie how do I overcome this and stop MSIE from choking?
Thanks
Mark
"Tom." <ptittom+news@free.fr> wrote in message
news:95ovl4$bq7$1@wanadoo.fr...
> In <3a7fff08_1@nnrp1.news.uk.psi.net>, Mark A. Williams wrote:
> > I am having troubles with this peice of XML in MSIE 5.5. Basically it
> > fails on the accented e (é) in the <description> data - specifically the
> > word ingénieur . Can anyone help me out? Is there something I am
missing?
> > [...]
> > <?xml version="1.0"?>
>
> This means your file is encoded in utf-8 or utf-16.
>
> > Vous tes ingénieur ou Bac +4/5 en informatique avec une experience de 3
10
>
> This seams to be encoded in iso-8859-1, incompatible with any utf
encoding.
>
> HTH
>
> Tom.
------------------------------
Date: Tue, 6 Feb 2001 21:12:11 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: newbie - grep non-used uid from passwd
Message-Id: <nqRf6.9$ux6.1544@vic.nntp.telstra.net>
"- = k o l i s k o = -" <kolisko@penguin.cz> wrote in message
news:3a7fc351@news.cvut.cz...
> now it is ok... i changed it to:
>
<snip>
>
> Now I get 1st free uid, but not from a range.
> Where could I define that I would like 1st free uid from range in example
> from 300 to 350?
>
What have you tried so far?
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, 06 Feb 2001 11:26:20 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: newbie - grep non-used uid from passwd
Message-Id: <3A7FE067.692571D6@acm.org>
- = k o l i s k o = - wrote:
>
> Hello!
>
> I am newbie to perl.
>
> Is possible to grep from my /etc/passwd the 1st non-used uid in
> range from 100 to 999?
>
> ex:
> user1:x:100:100:....
> user2:x:101:100:....
> user3:x:102:100:....
> user4:x:106:100:....
> user5:x:107:100:....
> user6:x:108:100:....
>
> In this example is 1st non-used uid '103' ...
Well, here's one way to do it.
#!/usr/bin/perl -w
use strict;
my $uid;
my %hash;
while ( ( undef, undef, $uid ) = getpwent() ) {
if ( $uid >= 100 && $uid <= 999 ) {
$hash{ $uid } = 1;
}
}
my @keys = sort {$a <=> $b} keys %hash;
for ( $keys[0] .. $keys[-1] ) {
unless ( exists $hash{ $_ } ) {
print "$_\n";
last;
}
}
John
------------------------------
Date: Tue, 6 Feb 2001 13:23:07 +0100
From: "- = k o l i s k o = -" <kolisko@penguin.cz>
Subject: Re: newbie - grep non-used uid from passwd
Message-Id: <3a7fec74$1@news.cvut.cz>
Thank You!
It work very well!
Last thing - I dont know where is defined the /etc/passwd file.
Becouse for my use I change the passwd like file which is in
other directory.
--
S pozdravem,
Michal Kolesar
kolisko@penguin.cz
http://www.egarden.cz
server of free unix services
"John W. Krahn" <krahnj@acm.org> píse v diskusním príspevku
news:3A7FE067.692571D6@acm.org...
> - = k o l i s k o = - wrote:
> >
> > Hello!
> >
> > I am newbie to perl.
> >
> > Is possible to grep from my /etc/passwd the 1st non-used uid in
> > range from 100 to 999?
> >
> > ex:
> > user1:x:100:100:....
> > user2:x:101:100:....
> > user3:x:102:100:....
> > user4:x:106:100:....
> > user5:x:107:100:....
> > user6:x:108:100:....
> >
> > In this example is 1st non-used uid '103' ...
>
> Well, here's one way to do it.
>
>
> #!/usr/bin/perl -w
> use strict;
>
> my $uid;
> my %hash;
>
> while ( ( undef, undef, $uid ) = getpwent() ) {
> if ( $uid >= 100 && $uid <= 999 ) {
> $hash{ $uid } = 1;
> }
> }
>
> my @keys = sort {$a <=> $b} keys %hash;
>
> for ( $keys[0] .. $keys[-1] ) {
> unless ( exists $hash{ $_ } ) {
> print "$_\n";
> last;
> }
> }
>
>
> John
------------------------------
Date: Tue, 6 Feb 2001 16:03:42 +0100
From: "- = k o l i s k o = -" <kolisko@penguin.cz>
Subject: Re: newbie - grep non-used uid from passwd
Message-Id: <3a801224$1@news.cvut.cz>
In this code is still a bug.
When I have a passwd file like this:
u1:x:100:...
u2:x:101:...
u3:x:102:...
u4:x:103:...
u5:x:104:...
u6:x:300:...
u7:x:400:...
and when I specific the range from '100' to '200' the following
code dont display any free uid number - that is error becouse
right is the number '105'.
--
S pozdravem,
Michal Kolesar
kolisko@penguin.cz
http://www.egarden.cz
server of free unix services
"John W. Krahn" <krahnj@acm.org> píse v diskusním príspevku
news:3A7FE067.692571D6@acm.org...
> - = k o l i s k o = - wrote:
> >
> > Hello!
> >
> > I am newbie to perl.
> >
> > Is possible to grep from my /etc/passwd the 1st non-used uid in
> > range from 100 to 999?
> >
> > ex:
> > user1:x:100:100:....
> > user2:x:101:100:....
> > user3:x:102:100:....
> > user4:x:106:100:....
> > user5:x:107:100:....
> > user6:x:108:100:....
> >
> > In this example is 1st non-used uid '103' ...
>
> Well, here's one way to do it.
>
>
> #!/usr/bin/perl -w
> use strict;
>
> my $uid;
> my %hash;
>
> while ( ( undef, undef, $uid ) = getpwent() ) {
> if ( $uid >= 100 && $uid <= 999 ) {
> $hash{ $uid } = 1;
> }
> }
>
> my @keys = sort {$a <=> $b} keys %hash;
>
> for ( $keys[0] .. $keys[-1] ) {
> unless ( exists $hash{ $_ } ) {
> print "$_\n";
> last;
> }
> }
>
>
> John
------------------------------
Date: Tue, 06 Feb 2001 13:27:45 GMT
From: garry@zvolve.com (Garry Williams)
Subject: Re: perl & expect - STDOUT vs. redirect to file
Message-Id: <lZSf6.39$561.1395@eagle.america.net>
On Mon, 05 Feb 2001 17:19:36 -0600, Perl User <bogus@bogus.com> wrote:
>bits101010@my-deja.com wrote:
>>
>> Try adding $|++; to both programs.
>This worked!
>
>Thanks. I had used $AUTOFLUSH thinking that it was the same
>as $|++. Guess not.
Start _all_ of your Perl scripts with
#!/usr/local/bin/perl -w
use strict;
and many mysteries will be revealed.
--
Garry Williams
------------------------------
Date: Tue, 6 Feb 2001 13:03:37 +0100
From: rpolzer@web.de (Rudolf Polzer)
Subject: Re: perl & expect - STDOUT vs. redirect to file
Message-Id: <slrn97vq0p.uf.rpolzer@rebounce.rpolzer-lx>
Perl User <bogus@bogus.com> schrieb Folgendes:
> This worked!
>
> Thanks. I had used $AUTOFLUSH thinking that it was the same
> as $|++. Guess not.
It IS the same, if you write
use English;
at the beginning of your program. Try using
use strict;
to catch such errors.
------------------------------
Date: Tue, 06 Feb 2001 14:40:08 GMT
From: edis9@my-deja.com
Subject: perl -V error
Message-Id: <95p2c7$4f5$1@nnrp1.deja.com>
The output of the 'perl -V' command gives me the following error:
Can't locate Config.pm in @INC.
BEGIN failed--compilation aborted.
However, the 'perl -v' command gives me:
This is perl, version 5.003 with EMBED
built under solaris at Jun 27 1996 07:29:27
+ suidperl security patch
Is it possible that perl was not installed correctly on this server??
Can anyone decrypt this for me?
Thanks!
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Tue, 06 Feb 2001 15:52:25 GMT
From: Gil Vautour <gvautour@nb.sympatico.ca>
Subject: Printing from "@_"
Message-Id: <3A8039F3.B75E822D@nb.sympatico.ca>
Hello,
I have a CGI script in Perl that accepts input from a Form. The Form
contains some Radio Button input tags that are not initialized (not
SELECTED). In the Perl script the values from the form are passed to a
subroutine with @_ variable and written out to a text file using a
Foreach loop that prints out the value for each $key ($query->param)
within a pair of double quotes. The strange thing that I have noticed
is that if the radio button remains unselected when the Form is
submitted sometimes the value (or lack of one) doesn't get printed. I
would at least expect to see a pair of empty double quotes indicating
where the value should be. Does anyone know why this might be? I'm
fairly new to Perl so below is a snippet...maybe I'm missing something
obvious?
sub DataFile {
my($query) = @_;
my($values,$key);
open(DATAFILE, ">>/some/directory/datafile.txt") || die "ERROR! can't
open file: $!\n";
foreach $key ($query->param) {
$values = $query->param($key);
print DATAFILE "\"$values\",";
}
print DATAFILE "\n";
close(DATAFILE) || die "ERROR! can't close file: $!\n";
}
Thanks,
------------------------------
Date: 06 Feb 2001 11:04:10 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Printing from "@_"
Message-Id: <m34ry7kdc5.fsf@mumonkan.sunstarsys.com>
Gil Vautour <gvautour@nb.sympatico.ca> writes:
> The strange thing that I have noticed is that if the radio button remains
> unselected when the Form is submitted sometimes the value (or lack of one)
> doesn't get printed. I would at least expect to see a pair of empty double
> quotes indicating where the value should be. Does anyone know why this might
> be? I'm fairly new to Perl so below is a snippet...maybe I'm missing
> something obvious?
Maybe. I think your code is OK, however your HTML probably needs
fixing. "Unsuccessful" form widgets need not be returned to the server:
see
http://www.w3.org/TR/1998/REC-html40-19980424/interact/forms.html#h-17.13.3
for details. As this is not a Perl issue, it's OT here; so if you can't
figure it out from the spec, ask again in a HTML or cgi newsgroup. I'm
sure people can answer this there, if you include your form's html as well.
HTH
--
Joe Schaefer "In order to form an immaculate member of a flock of sheep one
must, above all, be a sheep."
--Albert Einstein
------------------------------
Date: Tue, 06 Feb 2001 15:50:42 GMT
From: Rodney Engdahl <red_orc@my-deja.com>
Subject: Re: Problem opening for writing, going nuts, please help!
Message-Id: <95p6gd$8b4$1@nnrp1.deja.com>
In article <95im4d$7uc$1@nnrp1.deja.com>,
misterfive@my-deja.com wrote:
> Ok, I am going totaly nuts here. I'm modifying some existing BBS code.
I am
> trying to open a file for writing, and the program stops after the
open
> statement. (No, it does not execute the "die" statement, it just
stop.)
>
> open(USERFILE, ">$forum_dir/$userfile") ||
> &CgiDie("Could't open $userfile for writing");
> print "File opened for writing";
>
> The end result is:
> ----
> Inside session compare
> CorrectDir/CorrectFile
> ----
>
1. What goes on inside CgiDie? Is any other part of the code actually
invoking this call?
2. What happens if you replace
open(USERFILE, ">$forum_dir/$userfile") || &CgiDie("Could't open
$userfile for writing");
with
open(USERFILE, ">$forum_dir/$userfile") || die "Cannot open $forum_dir/
$userfile for writing $!";
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Tue, 06 Feb 2001 15:43:21 GMT
From: dave_vb@my-deja.com
Subject: Re: Redirecting stdout/stderr from a call to system()
Message-Id: <95p62n$7qk$1@nnrp1.deja.com>
> system("program args 1>/tmp/program.stdout 2>/tmp/program.stderr");
> (...)
Still didn't work. I must be screwing up somewhere. I'll just take a
good look and see what I can find... thanks to all who responded.
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Tue, 06 Feb 2001 15:51:14 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: suidperl problem
Message-Id: <t807bi81l6bmf1@corp.supernews.com>
In comp.lang.perl.misc David Efflandt <efflandt@xnet.com> wrote:
> On 03 Feb 2001 18:06:40 +0000, nobull@mail.com <nobull@mail.com> wrote:
>>Beggar <cpegbeggar@mail.com> writes:
>>
>>> #!/usr/bin/suidperl -w
>>> $ENV{'PATH'}="/usr/bin:/usr/sbin:/bin:/sbin";
>>>
>>> print "content-type: text/html\n\n";
>>>
>>> $temp1=`cat /etc/shadow`;
>>> $temp2=`/bin/ps`;
>>>
>>> `nohup "start_my_server_program"`
>>>
>>> print "$temp1,$temp2"
>>> =========================================
Both previous posters explained a few important details,
but I still feel the most important thing has been missed.
DO NOT print your shadowed password file to a web page!
If you choose to do so, make absolutely sure that you
have taken every possible precaution to make sure only the
properly authorized people have access to it. The best thing
to do is to still NEVER print this sort of thing to a web
page.
Chris
--
Christopher E. Stith
For the pleasure of others, please adhere to the following
rules when visiting your park:
No swimming. No fishing. No flying kites. No frisbees.
No audio equipment. Stay off grass. No pets. No running.
------------------------------
Date: Tue, 6 Feb 2001 12:46:57 -0000
From: "Polemarch" <polemarch@fut.net>
Subject: test creation and delivery systems
Message-Id: <ImSf6.16346$Ee3.429142@news6-win.server.ntlworld.com>
I have an extensive website already created and want to add a
powerful, automated test creation and delivery system to it. My
requirements are that it needs to run under a Perl system with its own
datafiles, ideally in a text format rather than a database one. The system
needs to be able to generate tests on the fly from lists of questions rather
than test
pages having to be built seperately. Lastly I want the students data
recorded for assessment purposes.
Does anybody have some recomendations? I have tested CQuest, Contest and
Examiner and none of these fit my requirements. Is there a 'mother of all
test creation and delivery systems' out there? Thanks.
yours
Mike
------------------------------
Date: Tue, 6 Feb 2001 18:37:35 +0300
From: "Vladimir Privalov" <delphi@ns.tchercom.ru>
Subject: There is a project of new game for InterCasino.
Message-Id: <3a8029b1$1@news.tchercom.ru>
Hello All,
There is a project of new game for InterCasino.
The basic of this project is the famous game "Life" by John H. Conway.
There is a demo programm.
See please my home page:
http://privaloff.narod.ru/
http://privaloff.narod.ru/vleng.html
http://privaloff.narod.ru/gameeng.html
Read the rules of game, download and try my demo version.
I hope and believe that you'll have interesting to this new game.
Sincerely, Vladimir Privalov.
------------------------------
Date: Tue, 06 Feb 2001 15:33:02 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: Using Braces
Message-Id: <t8069eg58lrn31@corp.supernews.com>
Abigail <abigail@foad.org> wrote:
> David H. Adler (dha@panix2.panix.com) wrote on MMDCCXV September MCMXCIII
> in <URL:news:slrn97u5bv.t4i.dha@panix2.panix.com>:
> -- On 30 Jan 2001 19:00:11 GMT, Rich Lafferty <rich@bofh.concordia.ca> wrote:
> -- >In comp.lang.perl.misc,
> -- >jlamport@calarts.edu <jlamport@calarts.edu> wrote:
> -- >>
> -- >> Read the docs a little more carefully. The "quote like" operators
> -- >> ( q qq qx qw s m tr ) can use *any* set of delimiters you choose. The
> -- >> following are all equivalent:
> -- >>
> -- >> $sql=q{select sysdate from dual};
> -- >> $sql=q(select sysdate from dual);
> -- >
> -- >[etc]
> -- >
> -- >You left out my favorites: q`` qw'' qx"" :-)
> --
> -- Personally, my reaction to that first one is "Gah!"
> --
> -- I don't like the idea that there are wild backticks roaming the
> -- prairie if you lose that q through some horrible text editor
> -- accident...
> I'm partially to q"" and qq''.
> Specially if your not-so-perl-savvy PFY is going to maintain it.
> But that's ok, I'm just cruel.
Really cruel would be q## or q;; I suppose. I tend to like those.
A substitution can be really fun to look at when you have something
like
$value =~ s;^0+(?=\.);;;
or
$value =~ s#^0+(?=\.)##;## ## ### Adjust formatting ###
since the match, substitution, and transliteration operators can do
the same things as the quote-like ops.
Chris
--
Christopher E. Stith
Product shown enlarged to make you think you're getting more.
------------------------------
Date: Tue, 06 Feb 2001 13:37:49 GMT
From: myrddin_charis@my-deja.com
Subject: Using tie in an OO-like manner
Message-Id: <95ound$11u$1@nnrp1.deja.com>
Hi,
A lot of scripts that I produce at work need to do some form of time
stamping, whether it be to write to a log with an extension for the
current day and month, or to write information to a log with the current
date and time.
Up until now I have been doing this by having lots of pieces of code
that do something like
my $ext=strftime(EXT_FORMAT,localtime);
open(LOG,">" . LOG_NAME . $ext) or die "Failed to open log file: $!
\n";
my $date=strftime(LOG_DATE,localtime);
print $date," - Started application";
print LOG $date," - Started application";
Whilst there is nothing inherently wrong in doing this I'm a "lazy"
programmer and work with people who are new to Perl. I was thinking
along the lines of having a tied variable that does the strftime as
a FETCH and uses STORE to set the format if required. This can then
be set at the start of the script and used wherever the timestamp is
required.
No problem so far, but I've noticed that people sometimes get a bit
confused by the 'tie' syntax and wondered if I could use the OO new
method for consistency. However, it seems that tie is "magic" in that
you cannot return a reference to it and have it work like the original.
So the following doesn't work:
package Time::Stamp;
sub new
{
my $class = shift;
my $object;
tie $object,$class,shift;
return bless \$object,$class;
}
...
my $extension = new Time::Stamp;
Printing $extension just prints the "SCALAR(0x26ac2c)" reference string.
although doing $$extension does print the correct date.
However, doing a
local *extension = new Time::Stamp;
does allow you to use $extension as intended.
Would I be better off just getting the newbies to using the
tie my $extension,Time::Stamp;
syntax or is there a way of using new to perform a tie?
Or, conversely, is there a way of using objects in a similar manner
to a tied variable?, i.e. FETCHing them calls a user-defined method.
All suggestions welcome.
Dave.
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Tue, 06 Feb 2001 15:04:27 GMT
From: Graham Bailey <graham_j_bailey@my-deja.com>
Subject: Re: Very Newbie: perlcc on NT
Message-Id: <95p3pl$5k0$1@nnrp1.deja.com>
In article <95bc2e$851$1@nnrp1.deja.com>,
Graham Bailey <graham_j_bailey@my-deja.com> wrote:
> Help!!
>
> I have written some Perl scripts that enable me to create Oracle
> databases in a consistent manner for a development team. I would like
> to deploy these scripts now but, in their present form, there will be
a
> requirement to install Perl on the servers before I can execute the
> scripts.
>
> My aim is to make the scripts into "stand-alone" executables, such
that
> no Perl installation is required. I am trying to use the Perl
> compiler: perlcc to perform this task but I am hitting a problem where
> perlcc cannot find a particular file:
>
> D:\oracle\ora816
\admin\utilities\database_creator\perl_scripts>perlcc -
> b hello_world.p
>
> ----------------------------------------------------------------------
>
> Compiling hello_world.p:
> ----------------------------------------------------------------------
>
> Making Bytecode(hello_world.pc) for hello_world.p!
> C:\Perl\bin\Perl.exe -IC:/Perl/lib -IC:/Perl/site/lib -I. -MB::Stash -
> c hello_world.p
> C:\Perl\bin\Perl.exe -IC:/Perl/lib -IC:/Perl/site/lib -I. -
MO=Bytecode,-
> umain,-u
> attributes,-uDB,-u<none>,-uWin32 hello_world.p
> The system cannot find the file specified.
> ERROR: In generating code for hello_world.p!
>
> (I used hello_world.p because it doesn't contain any references to
> modules - I am using ActiveState Perl 5.6.0 Build 623)
>
> Is the solution fairly straightforward or am I missing something
> fundamental here. I have checked out other threads in this forum -
> some of them quite lengthy, going off at tangents and not providing an
> answer.
>
> Can someone give me a straightforward answer without having a pop at
> me - my core skills are as an Oracle DBA and I am just starting out
> with Perl.
>
> Thanks in advance...
>
> Sent via Deja.com
> http://www.deja.com/
>
Any takers yet ????
Sent via Deja.com
http://www.deja.com/
------------------------------
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 222
**************************************