[18061] in Perl-Users-Digest
Perl-Users Digest, Issue: 221 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Feb 6 06:13:59 2001
Date: Tue, 6 Feb 2001 03:10:14 -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: <981457814-v10-i221@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 6 Feb 2001 Volume: 10 Number: 221
Today's topics:
Re: newbie - grep non-used uid from passwd <kolisko@penguin.cz>
Re: newbie - grep non-used uid from passwd <ccx138@coventry.ac.uk>
Re: newbie - grep non-used uid from passwd (Wyzelli)
Re: newbie - grep non-used uid from passwd <kolisko@penguin.cz>
Re: newbie - grep non-used uid from passwd <kolisko@penguin.cz>
Re: newbie - grep non-used uid from passwd <kolisko@penguin.cz>
Package question <taboo@comcen.com.au>
Re: Passwd and Shadow shawn@flurg.com
POSIX::strftime() error under RH7, perl 5.6.0, POSIX 1. <shutupsteve@aNwOdSaPnAgM.com>
Re: Pros / Cons of upgrading from 5.005 to 5.6.0 <bwalton@rochester.rr.com>
So curious <ducateg@info.bt.co.uk>
Re: So curious (Anno Siegel)
Re: So curious (Bernard El-Hagin)
Re: stupid eval tricks <iboreham@my-deja.com>
subwin in curses.. <dorsettest@uk.insight.com>
Re: What's wrong with this (parent fork multiple childr (Chris)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 6 Feb 2001 09:04:11 +0100
From: "- = k o l i s k o = -" <kolisko@penguin.cz>
Subject: Re: newbie - grep non-used uid from passwd
Message-Id: <3a7fafbd@news.cvut.cz>
Thank You for example.
But it is not function. I tried repair it:
#!/usr/bin/perl -w
use strict;
my @uids = ();
while (<STDIN>){ # modify to read from file
push @uids, $1 if m/.*:.*:(\d+):.*:.*:.*:.*/; # grab uids
}
@uids = sort @uids; # ensure uids are sorted
my $newuid = $uids[0]; # set to comparison to match
first uid
foreach my $uid (@uids) {
# unless ($newuid == $uid){
print $uid."\n"; # print the first one that
doesn't match
# last;
# }
# $newuid++; # increment the comparison
}
sorting is not good becouse it sort like this:
1
11
12
13
100
101
2
21
23
3
300
Is possible to correct the sorting?
Where could I get the good manual (introducion to perl) where
will described basic functions like "push, foreach, unless, regular
expression, and more"
Tx
--
S pozdravem,
Michal Kolesar
kolisko@penguin.cz
http://www.egarden.cz
server of free unix services
"Wyzelli" <wyzelli@yahoo.com> pí¹e v diskusním pøíspìvku
news:Xns9040666C1wyzelliyahoocom@203.39.3.131...
> "- = k o l i s k o = -" <kolisko@penguin.cz> wrote in
> <3a7ed39c$1@news.cvut.cz>:
>
> >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' ...
> >
>
> Here is a short working example of one way to address this type of issue.
>
> You will need to handle the modifications to read from the actual file.
Note
> that the regex is pretty loose, but may be tightened up depending on your
real
> data. (I don't have an /etc/passwd to play with here)
>
> #!/usr/bin/perl -w
> use strict;
>
> my @uids = ();
> while (<DATA>){ # modify to read from file
> push @uids, $1 if m/.*:.*:(\d+):.*:.*/; # grab uids
> }
>
> @uids = sort @uids; # ensure uids are sorted
>
> my $newuid = $uids[0]; # set to comparison to match first uid
> foreach my $uid (@uids) {
> unless ($newuid == $uid){
> print $newuid; # print the first one that doesn't match
> last;
> }
> $newuid++; # increment the comparison
> }
> __END__
> user1:x:100:100:....
> user2:x:101:100:....
> user4:x:106:100:....
> user5:x:107:100:....
> user6:x:108:100:....
> user3:x:102:100:....
>
> Note that I changed the order of the sample data to ensure the sort was
needed.
> If you know your data is always in numeric order the sort may not be so
> necessary, but I think better safe than sorry.
>
> Wyzelli
> --
> #beer v2
> ($a,$b,$w,$t)=(' bottle',' of beer',' on the wall','Take one down, pass it
> around');
> for(reverse(1..100)){$s=($_!=1)?'s':'';$c.="$_$a$s$b$w\n$_$a$s$b\n$t\n";
> $_--;$s=($_!=1)?'s':'';$c.="$_$a$s$b$w\n\n";}print"$c*hic*";
------------------------------
Date: Tue, 06 Feb 2001 08:48:35 +0000
From: John Tutchings <ccx138@coventry.ac.uk>
Subject: Re: newbie - grep non-used uid from passwd
Message-Id: <3A7FBA62.E717F3F7@coventry.ac.uk>
- = k o l i s k o = - wrote:
> Thank You for example.
> But it is not function. I tried repair it:
>
> #!/usr/bin/perl -w
> use strict;
>
> my @uids = ();
>
> while (<STDIN>){ # modify to read from file
> push @uids, $1 if m/.*:.*:(\d+):.*:.*:.*:.*/; # grab uids
> }
>
> @uids = sort @uids; # ensure uids are sorted
>
> my $newuid = $uids[0]; # set to comparison to match
> first uid
>
> foreach my $uid (@uids) {
> # unless ($newuid == $uid){
> print $uid."\n"; # print the first one that
> doesn't match
> # last;
> # }
> # $newuid++; # increment the comparison
> }
>
> sorting is not good becouse it sort like this:
> 1
> 11
> 12
> 13
> 100
> 101
> 2
> 21
> 23
> 3
> 300
>
> Is possible to correct the sorting?
>
The sort is treating the numbers as letters.
You need to do
@uids = sort numerically @uids;
sub numerically{$a<=> $b;}
That should do it.
>
> Where could I get the good manual (introducion to perl) where
> will described basic functions like "push, foreach, unless, regular
> expression, and more"
>
I like the O'riely Camel book.
>
> Tx
> --
>
> S pozdravem,
> Michal Kolesar
> kolisko@penguin.cz
> http://www.egarden.cz
> server of free unix services
John
------------------------------
Date: Tue, 06 Feb 2001 09:07:37 GMT
From: wyzelli@yahoo.com (Wyzelli)
Subject: Re: newbie - grep non-used uid from passwd
Message-Id: <Xns9040BAE05wyzelliyahoocom@203.39.3.131>
"- = k o l i s k o = -" <kolisko@penguin.cz> wrote in
<3a7fafbd@news.cvut.cz>:
<snip>
>sorting is not good becouse it sort like this:
>1
>11
>12
>13
>100
>101
>2
>21
>23
>3
>300
>
>
>Is possible to correct the sorting?
Then what we need to do is ensure the sort is numerical (in ascending
order).
Change the sort line like so:
@uids = sort {$a <=> $b} @uids; # ensure uids are sorted
Reversing the $a and $b with sort descending.
>Where could I get the good manual (introducion to perl) where
>will described basic functions like "push, foreach, unless, regular
>expression, and more"
Perl's documentation is in the installation, so typing
perldoc perldoc
at the command prompt will help. Activestate's Perl includes documentation
in html format.
To get the documantation about the sort function, type
perldoc -f sort
at your command prompt.
There are a number of good books about programming with Perl. I personally
recommend
"Elements of programming with Perl" by Andrew Johnson, from Manning Books.
Otherwise several books from O'Reilly, including Learning Perl, and
Programming Perl.
Uri Guttman who posts here regularly has a book review page on his website.
Check his sig for the url.
There are also some on-line tutorials available, or varying quality, and a
good place to start is www.perl.com
Wyzelli
--
#beer v2
($a,$b,$w,$t)=(' bottle',' of beer',' on the wall','Take one down, pass it
around');
for(reverse(1..100)){$s=($_!=1)?'s':'';$c.="$_$a$s$b$w\n$_$a$s$b\n$t\n";
$_--;$s=($_!=1)?'s':'';$c.="$_$a$s$b$w\n\n";}print"$c*hic*";
------------------------------
Date: Tue, 6 Feb 2001 10:15:13 +0100
From: "- = k o l i s k o = -" <kolisko@penguin.cz>
Subject: Re: newbie - grep non-used uid from passwd
Message-Id: <3a7fc06e@news.cvut.cz>
--
S pozdravem,
Michal Kolesar
kolisko@penguin.cz
http://www.egarden.cz
server of free unix services
"John Tutchings" <ccx138@coventry.ac.uk> píse v diskusním príspevku
news:3A7FBA62.E717F3F7@coventry.ac.uk...
>
> - = k o l i s k o = - wrote:
>
> > Thank You for example.
> > But it is not function. I tried repair it:
> >
> > #!/usr/bin/perl -w
> > use strict;
> >
> > my @uids = ();
> >
> > while (<STDIN>){ # modify to read from
file
> > push @uids, $1 if m/.*:.*:(\d+):.*:.*:.*:.*/; # grab uids
> > }
> >
> > @uids = sort @uids; # ensure uids are sorted
> >
> > my $newuid = $uids[0]; # set to comparison to
match
> > first uid
> >
> > foreach my $uid (@uids) {
> > # unless ($newuid == $uid){
> > print $uid."\n"; # print the first one
that
> > doesn't match
> > # last;
> > # }
> > # $newuid++; # increment the comparison
> > }
> >
> > sorting is not good becouse it sort like this:
> > 1
> > 11
> > 12
> > 13
> > 100
> > 101
> > 2
> > 21
> > 23
> > 3
> > 300
> >
> > Is possible to correct the sorting?
> >
>
> The sort is treating the numbers as letters.
> You need to do
>
> @uids = sort numerically @uids;
>
> sub numerically{$a<=> $b;}
>
> That should do it.
>
>
> >
> > Where could I get the good manual (introducion to perl) where
> > will described basic functions like "push, foreach, unless, regular
> > expression, and more"
> >
>
> I like the O'riely Camel book.
The book is very expensive for me. Is it described on the Internet, too?
>
> >
> > Tx
> > --
> >
> > S pozdravem,
> > Michal Kolesar
> > kolisko@penguin.cz
> > http://www.egarden.cz
> > server of free unix services
>
> John
>
------------------------------
Date: Tue, 6 Feb 2001 10:21:48 +0100
From: "- = k o l i s k o = -" <kolisko@penguin.cz>
Subject: Re: newbie - grep non-used uid from passwd
Message-Id: <3a7fc1f0@news.cvut.cz>
When i tried to put the 'numerically' string and ran it I get err:
[root@quarto michal]# cat passwd |./um.pl
Name "main::numerically" used only once: possible typo at ./um.pl line 10.
Undefined sort subroutine "main::numerically" called at ./um.pl line 10,
<STDIN> chunk 229.
[root@quarto michal]#
the line is:
@uids = sort numerically @uids; # ensure
uids are sorted
--
S pozdravem,
Michal Kolesar
kolisko@penguin.cz
http://www.egarden.cz
server of free unix services
"John Tutchings" <ccx138@coventry.ac.uk> píse v diskusním príspevku
news:3A7FBA62.E717F3F7@coventry.ac.uk...
>
> - = k o l i s k o = - wrote:
>
> > Thank You for example.
> > But it is not function. I tried repair it:
> >
> > #!/usr/bin/perl -w
> > use strict;
> >
> > my @uids = ();
> >
> > while (<STDIN>){ # modify to read from
file
> > push @uids, $1 if m/.*:.*:(\d+):.*:.*:.*:.*/; # grab uids
> > }
> >
> > @uids = sort @uids; # ensure uids are sorted
> >
> > my $newuid = $uids[0]; # set to comparison to
match
> > first uid
> >
> > foreach my $uid (@uids) {
> > # unless ($newuid == $uid){
> > print $uid."\n"; # print the first one
that
> > doesn't match
> > # last;
> > # }
> > # $newuid++; # increment the comparison
> > }
> >
> > sorting is not good becouse it sort like this:
> > 1
> > 11
> > 12
> > 13
> > 100
> > 101
> > 2
> > 21
> > 23
> > 3
> > 300
> >
> > Is possible to correct the sorting?
> >
>
> The sort is treating the numbers as letters.
> You need to do
>
> @uids = sort numerically @uids;
>
> sub numerically{$a<=> $b;}
>
> That should do it.
>
>
> >
> > Where could I get the good manual (introducion to perl) where
> > will described basic functions like "push, foreach, unless, regular
> > expression, and more"
> >
>
> I like the O'riely Camel book.
>
> >
> > Tx
> > --
> >
> > S pozdravem,
> > Michal Kolesar
> > kolisko@penguin.cz
> > http://www.egarden.cz
> > server of free unix services
>
> John
>
------------------------------
Date: Tue, 6 Feb 2001 10:27:40 +0100
From: "- = k o l i s k o = -" <kolisko@penguin.cz>
Subject: Re: newbie - grep non-used uid from passwd
Message-Id: <3a7fc351@news.cvut.cz>
now it is ok... i changed it to:
#!/usr/bin/perl -w
use strict;
my @uids = ();
while (<STDIN>){ # modify to read from file
push @uids, $1 if m/.*:.*:(\d+):.*:.*:.*:.*/; # grab uids
}
# @uids = sort numerically @uids; # ensure
uids are sorted
@uids = sort {$a <=> $b} @uids;
my $newuid = $uids[0]; # set to comparison
to match first uid
foreach my $uid (@uids) {
unless ($newuid == $uid){
print $newuid."\n"; # print the first
one that doesn't match
last;
}
$newuid++; # increment the comparison
}
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?
Tx
--
S pozdravem,
Michal Kolesar
kolisko@penguin.cz
http://www.egarden.cz
server of free unix services
"Wyzelli" <wyzelli@yahoo.com> pí¹e v diskusním pøíspìvku
news:Xns9040BAE05wyzelliyahoocom@203.39.3.131...
> "- = k o l i s k o = -" <kolisko@penguin.cz> wrote in
> <3a7fafbd@news.cvut.cz>:
>
> <snip>
>
> >sorting is not good becouse it sort like this:
> >1
> >11
> >12
> >13
> >100
> >101
> >2
> >21
> >23
> >3
> >300
> >
> >
> >Is possible to correct the sorting?
>
> Then what we need to do is ensure the sort is numerical (in ascending
> order).
>
> Change the sort line like so:
>
> @uids = sort {$a <=> $b} @uids; # ensure uids are sorted
>
> Reversing the $a and $b with sort descending.
>
> >Where could I get the good manual (introducion to perl) where
> >will described basic functions like "push, foreach, unless, regular
> >expression, and more"
>
> Perl's documentation is in the installation, so typing
>
> perldoc perldoc
>
> at the command prompt will help. Activestate's Perl includes
documentation
> in html format.
>
> To get the documantation about the sort function, type
>
> perldoc -f sort
>
> at your command prompt.
>
> There are a number of good books about programming with Perl. I
personally
> recommend
>
> "Elements of programming with Perl" by Andrew Johnson, from Manning Books.
>
> Otherwise several books from O'Reilly, including Learning Perl, and
> Programming Perl.
>
> Uri Guttman who posts here regularly has a book review page on his
website.
> Check his sig for the url.
>
> There are also some on-line tutorials available, or varying quality, and a
> good place to start is www.perl.com
>
> Wyzelli
> --
> #beer v2
> ($a,$b,$w,$t)=(' bottle',' of beer',' on the wall','Take one down, pass it
> around');
> for(reverse(1..100)){$s=($_!=1)?'s':'';$c.="$_$a$s$b$w\n$_$a$s$b\n$t\n";
> $_--;$s=($_!=1)?'s':'';$c.="$_$a$s$b$w\n\n";}print"$c*hic*";
------------------------------
Date: 6 Feb 2001 13:03:19 +1100
From: "Kiel R Stirling" <taboo@comcen.com.au>
Subject: Package question
Message-Id: <3a7f5b67$1@nexus.comcen.com.au>
Hi,
I'm have'n prob's. Can anyone help?
I want to return data to an array from a package and loop
through it.
while (@row = UsageReport->fetchrow('SHOW TABLES')) {
# Do something with data in @row.
}
package UsageReport;
sub fetchrow {
my @row;
# At this point I have a open connection to a MYSQL
# server.
$sth = $dbh->prepare($_[1]);
$sth->execute() || die $DBI::errstr;
while (@row=$sth->fetchrow_array()) {
# Is there another way to return data?
return @row;
}
}
1;
------------------------
I just can't seem to find a way to streem the data back to my first while loop.
Lost,
Kiel R Stirling
------------------------------
Date: Tue, 06 Feb 2001 07:01:01 GMT
From: shawn@flurg.com
Subject: Re: Passwd and Shadow
Message-Id: <95o7fb$fa2$1@nnrp1.deja.com>
Hello,
I recently ran into this problem as well, creating a web based
interface to 'passwd' and the like. The first problem (running your
script as root) can be fixed by using suidperl. However, I would
caution against using this without taint checking (and some other
security measures like general sanity checking of /all/ input data)
turned on.
Additionally, I tried using the modules Linux::Passwd and the like. One
thing I found here was, any perl script that actually modifies any
system files is a Bad Thing(tm) and should be avoided at all costs, due
to the fact that they are prone to failure and are guaranteed to do so.
Instead, use system() or `` to use regular unix shell commands to due
the grunt work.
Good Luck,
-Shawn
In article <kSXe6.13032$LQ2.200981@news2-win.server.ntlworld.com>,
"Stuart Lowes" <stuart@zerostate.co.uk> wrote:
> Hi
>
> I am writing a web interface for user admin and other things, like
apache on
> a solaris box. I am learning perl and unix as I go for my final year
degree
> project.
>
> Can anyone suggest good ways of modifying the passwd and shadow files
as
> well as the other obvious admin files.
>
> Obviously I want to avoid running the script as root if possible; but
as the
> script is run from the web I know it doesn't have the permissions to
modify
> the files.
>
> I have found in my research the shadow module, has anyone used it and
is it
> any good and does it get round the permissions problems?
> If people could suggest good ways of approaching these problems,
reading and
> writing to the passwd and shadow or point me towards articles to read
I
> would be grateful.
>
> King regards,
> Stu
>
>
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Tue, 06 Feb 2001 09:05:40 GMT
From: "Stephen Deken" <shutupsteve@aNwOdSaPnAgM.com>
Subject: POSIX::strftime() error under RH7, perl 5.6.0, POSIX 1.03
Message-Id: <E7Pf6.321747$IP1.10623917@news1.giganews.com>
Hello,
I've been introduced to a possible issue with POSIX.pm and RedHat 7 that I
haven't seen mentioned elsewhere, and I was wondering if anyone here might
have an insight into what's going wrong.
The problem, in a nutshell, is that POSIX::strftime() seems to be returning
incorrect values for human-readable months, e.g.:
perl -MPOSIX -e 'print strftime( "%B", 0, 0, 0, 0, 0, 0 ) . "\n";'
This command, under RedHat 7.0, using perl 5.6.0, POSIX 1.03, inexplicably
displays 'December' when it should display 'January'. The mapping is based
on 1 instead of 0, so
1 -> Jan
2 -> Feb
3 -> Mar
And so on, (12 == 0) -> Dec. I had the person with the problem slap
together a little C application which shows that the C libraries that (I
assume) POSIX despends on are working properly.
In attempting to correct this problem she even downloaded the perl source
and built it from scratch, and the problem persists.
Does anyone have ANY ideas whatsoever on this?
--sjd;
------------------------------
Date: Tue, 06 Feb 2001 02:09:55 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Pros / Cons of upgrading from 5.005 to 5.6.0
Message-Id: <3A7F5D95.1A50EE4D@rochester.rr.com>
Terrence Brannon wrote:
>
> The new company I am at is running Perl 5.005 and I have to deal with the
> problems that release had:
> - perl Makefile.PL PREFIX=$PREFIX doesn't set the man3 prefix correctly
> - no 'our' available.
>
> And I am not sure what else.
>
> Would someone mind telling what risks are involved in such an upgrade?
...
Well, it probably depends on what platform and Perl distribution you're
running on. If you're running ActiveState on NT, there are statements
in the install notes that say NT service pack 5 or higher is a
requirement. At our site, we can't guarantee that all the NT boxes on
which Perl might get run have service pack 5 or higher, so we have stuck
with 5.005. For my personal stuff, I keep up with the latest, and have
had no problems. But then I'm not running NT for my personal stuff,
either.
If you don't have NT, keeping up with the latest has all sorts of
advantages, like being able to get the latest modules, taking advantage
of the various bug fixes and new stuff, and being able to ask for help
on the newsgroup without having to apologize for bothing folks with
problems and code that are a couple years obsolete.
--
Bob Walton
------------------------------
Date: Tue, 6 Feb 2001 09:41:59 -0000
From: "Géry" <ducateg@info.bt.co.uk>
Subject: So curious
Message-Id: <95oh2o$ibi$1@pheidippides.axion.bt.co.uk>
I am so curious to know this...
If I put this:
print ((localtime)[6])."\n";
this prints an integer which indicates which day it is where 0 stands for
Sunday, 1 for Monday, 2 for Tuesday...
But
print [(localtime)[6]]."\n";
prints something like:
ARRAY(0x1bb8fac)
Does anyone know why? I am just so curious... what makes the () and the []
context different in this case?
I hope this question does not sound too cheeky. Simply, I am a bit puzzled
at Perl's "advanced syntax".
Many many thanks in advance.
--
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Géry
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
------------------------------
Date: 6 Feb 2001 10:15:03 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: So curious
Message-Id: <95oir7$9sr$1@mamenchi.zrz.TU-Berlin.DE>
Géry <ducateg@info.bt.co.uk> wrote in comp.lang.perl.misc:
>I am so curious to know this...
>If I put this:
>print ((localtime)[6])."\n";
>
>this prints an integer which indicates which day it is where 0 stands for
>Sunday, 1 for Monday, 2 for Tuesday...
>
>But
>print [(localtime)[6]]."\n";
>prints something like:
>
>ARRAY(0x1bb8fac)
>
>Does anyone know why? I am just so curious... what makes the () and the []
>context different in this case?
What made you think () and [] are equivalent? I can't think of a
single case where they are.
In your first case the outer pair of () serve to enclose the arguments
of print; it is interpreted as
print( (localtime)[6] ) . "\n"
This means, it prints (localtime)[6] and then concatenates the
result (1) with "\n" and throws that away. Looking closer at the
output you find that the "\n" isn't printed by that statement.
Switching on warnings would have made perl comment on the "concatenation
in void context" you are doing there. The pertinent rule here is
"If it looks like a function call, it *is* a function call". This
is true, even if you insert spaces to make it look like it isn't
a function call. Always turn on warnings when a bit of Perl code
confuses you.
In your second case, the [] are a constructor of an anonymous list:
The contents of [] (a single scalar, (localtime)[6]) are used to
build a list structure, and a reference to this list is returned.
Printing that forces it into string context, and "ARRAY(0x1bb8fac)"
is the result of that.
Anno
------------------------------
Date: Tue, 6 Feb 2001 10:16:01 +0000 (UTC)
From: bernard.el-hagin@lido-tech.net (Bernard El-Hagin)
Subject: Re: So curious
Message-Id: <slrn97vjn0.2q0.bernard.el-hagin@gdndev25.lido-tech>
On Tue, 6 Feb 2001 09:41:59 -0000, Géry <ducateg@info.bt.co.uk> wrote:
>I am so curious to know this...
>If I put this:
>print ((localtime)[6])."\n";
>
>this prints an integer which indicates which day it is where 0 stands for
>Sunday, 1 for Monday, 2 for Tuesday...
>
>But
>print [(localtime)[6]]."\n";
>prints something like:
>
>ARRAY(0x1bb8fac)
>
>Does anyone know why?
The construct:
[(localtime)[6]]
creates an anonymous array and returns a reference to it. The garbage
you're getting when printing the value of a reference is an address in
memory. Read about references and anonymous data structures here:
perldoc perlref
perldoc perldsc
perldoc perllol
Cheers,
Bernard
--
#requires 5.6.0
perl -le'* = =[[`JAPH`]=>[q[Just another Perl hacker,]]];print @ { @ = [$ ?] }'
------------------------------
Date: Tue, 06 Feb 2001 08:11:23 GMT
From: Ian Boreham <iboreham@my-deja.com>
Subject: Re: stupid eval tricks
Message-Id: <95obja$i5r$1@nnrp1.deja.com>
In article
<iowa88_song88.remove_eights-0102011420490001@205.184.122.221>,
iowa88_song88.remove_eights@hotmail.com (Weston Cann) wrote:
> So I thought "hey! eval!" and tried this:
>
> OK, how about this:
>
> $filestr = slurp($filename);
> $strToScan = "\"$fileStr\"";
> $scannedStr = eval($strToScan);
> print $scannedStr;
>
> Are they cooler or do they have any advantage over the way I've
presented?
You have to be careful with this one. It does not just interpolate
simple variables. You can interpolate code:
prompt> perl -e '$string = q[hello ${ \(print \"rm -rf *\n\")}
there]; eval ("\"$string\"");'
rm -rf *
This would not be too good if the "print" were a "system", and this were
user input via CGI.
It's not just interpolation that's a problem. What if the $string
contained double-quote characters:
prompt> perl -e '$string = q[hello" . system("echo FRED") . " there];
eval ("\"$string\"");'
FRED
A malevolent string could produce a well-formed eval string that
executed code even without interpolation. An apparently harmless bit of
data that just happened to include quotes could cause the eval to fail.
This sort of code should not be used anywhere where potentially
dangerous users can provide input, and when it is used, only people who
understand what it is doing should be allowed to use it (and then, only
with care). It is, however, a very flexible templating mechanism when
used under controlled circumstances.
Also, be warned that this is a touchy subject that has caused flame wars
in this group as recently as four or five months ago.
Regards,
Ian
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Tue, 06 Feb 2001 05:07:30 +0000
From: Kelly Dorset <dorsettest@uk.insight.com>
Subject: subwin in curses..
Message-Id: <3A7F8692.83D5E96C@uk.insight.com>
Just a quick question:
How do you use subwin() from the curses module?
$subwind = subwin(stdscr,$COLS - 2, $LINES / 2, $LINES / 2, 2);
box($subwind, '*', '*');
This generates:
Uncaught exception from user code:
argument 0 to Curses function 'box' is not a Curses window at curses2.pl
line 17.
Could someone illuminate me?
cheers :)
k
------------------------------
Date: Tue, 06 Feb 2001 07:28:55 GMT
From: cprasley@home.com (Chris)
Subject: Re: What's wrong with this (parent fork multiple children)?
Message-Id: <3a849d2f.49418309@news.rchmd1.bc.wave.home.com>
On Tue, 16 Jan 2001 17:27:11 GMT, "David Sisk" <davesisk@ipass.net> wrote
in comp.lang.perl.misc:
>With that now corrected, if I comment out part 1, I only get output from
>one child and no parent in part 3. If I comment out part 2, I get output
>from one parent and no children in part 3. I'm still confused about how to
>do this, so if anyone has an example (or knows where I can find one), please
>post.
When you use one parent to fork multiple children then the wait will
return after the first child dies. Your parent ends soon after, and I'll
guess you end up with a proc table full of zombies....
I think the following example is much more compact than the typical
documentation fragment:
#!/usr/bin/perl
my $wanted = 5;
my $children = 0;
my $pid = -1;
while( ($pid != 0) && ($children < $wanted) ) {
# While I am the parent and need more children...
$children++;
print "$$: Entering fork $children.\n";
if( ($pid = fork()) < 0) { die "Can't fork."; }
# One goes in, two come out.
print "$$: Exiting fork $children.\n";
}
if( $pid != 0 ) {
# Only the parent in here.
sleep 1;
while( $children-- ) {
wait;
print "$$: Reaping. $children remain.\n";
}
exit;
} else {
# Each child goes here to do the "real" work.
sleep 1;
print "$$: Child $children lives and dies.\n";
}
The sleep statements stretch things out so the output is easier to
understand.
------------------------------
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 221
**************************************