[24543] in Perl-Users-Digest
Perl-Users Digest, Issue: 6721 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jun 24 00:05:48 2004
Date: Wed, 23 Jun 2004 21:05:06 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 23 Jun 2004 Volume: 10 Number: 6721
Today's topics:
Re: 2 queries- first day of month and reading zipped f (Shalini Joshi)
Re: 2 queries- first day of month and reading zipped f <usenet@morrow.me.uk>
Config::Magic .72 released <rustyp@freeshell.org>
Re: Find length of files <tadmc@augustmail.com>
noob trying to learn where to start? <foxhoundIV@yahoo.com>
Re: noob trying to learn where to start? <1usa@llenroc.ude>
Re: noob trying to learn where to start? <ken_sington@nospam_abcdefg.com>
Re: problem between perl-gtk2 and POE::Session <troc@pobox.com>
repeated calculations everyday (Shalini Joshi)
Re: Using closures with "use strict" <tadmc@augustmail.com>
Re: Using Perl to create user accounts on Windows 2003 <ceo@nospam.on.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 23 Jun 2004 19:21:30 -0700
From: shalinij1@yahoo.com (Shalini Joshi)
Subject: Re: 2 queries- first day of month and reading zipped files directly off server
Message-Id: <283d6b7e.0406231821.38e744b7@posting.google.com>
Hey!
Thanks for the date-pointer...it was a biig help.
Paul Lalli <mr_itty@gmail.com> wrote in message news:<20040623125654.Y23512@dishwasher.cs.rpi.edu>...
> On Wed, 23 Jun 2004, Shalini Joshi wrote:
>
> > Hey.
> >
> > This is the code I came up with. I am just looking for the first day
> > of the month, but I still had to use the heavy Date::Manip module.
>
> No, you don't have to. You *can*, but you don't have to. As someone else
> in this thread pointed out, if all you want is the date of the month, the
> built in (and far less heavy) localtime() function could be all you need.
>
> > THis is what I came up with. I was working on a linux system with perl
> > 5.0.8(or some such).
>
> Most likely 5.8.0 - run `perl -v` to verify.
>
> > It has the Date::Manip module inbuilt
>
> Yes, Date::Manip is a standard module.
>
> > but doesnt have hte Date::Calc one!
>
> Date::Calc is available from CPAN: www.cpan.org
>
> > use Date::Manip;
> >
> >
> > #use Date::Calc qw(:all);
> > my @records;
> > my $i;
> > my $wanted_handle;
> > my @selected_records;
> > my $date;
> > my $cpday;
> > my $cpmonth;
> > my $cpyear;
> > my $cpdate;
> > my $cpfilename;
> > my %parameters;
> > my $year;
> > my $month;
> > my $day;
> > my $today;
>
> I'm going to guess that you use all these somewhere else in your actual
> code? If not, please get rid of them. Declaring variables that you don't
> use is bad coding style.
Yeah right I use them elsewhere in the code. Actually i have to name
the output file based on the date read in from the data file. Hence
these variables.
>
> > local $[=1;
>
> Why are you changing the first index of arrays, and first indices of
> substrings? Who (or what documentation) told you to do this, and for what
> purpose?
>
I wanted to parse a really long record....about 160 characters and the
information for parsing that I had started the counting from 1. I
looked up the camel book and to make it less tedious(well!!) for me i
just decided to play with that one, instead of doing the subtractions
!!!
> > open RECORDS, "< AETNA1.txt " or die "Can't read file: $!";
> >
> > $today=&ParseDate("today");
>
> You generally don't want to call subroutines by prefixing them with the &,
> even if you occasionally see it in documentation. It causes side affects
> that are almost always unwanted.
>
>
Thanks a lot for this one..am new and didnt know that. :) Infact your
post has been a biig help.
> > print "Today's date is $today\n";
> > $day= &UnixDate($today,"%d");
> > $month=&UnixDate($today,"%m");
> > $year=&UnixDate($today,"%Y");
> >
> > print "$day\n";
> > print "$month\n";
> > print "$year\n";
> >
> > if ($day == 01)
>
> this works, of course, but just to be picky, you don't need to specify 1
> as 01. If you were doing a string comparison, you would indeed have to
> do:
> if ($day eq '01')
> but you were comparing numerically.
>
>
> As mentioned earlier, if you really just need the day of the month, you
> can skip all that parseDate stuff and just make a call to localtime in
> list context, and take the fourth element from it:
>
> my $day = (localtime)[3];
>
> perldoc -f localtime
> will help you understand what localtime returns.
>
> Hope this helps,
Thanks a bunch..:)
> Paul Lalli
>
Regards,
Shalini
------------------------------
Date: Thu, 24 Jun 2004 03:08:26 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: 2 queries- first day of month and reading zipped files directly off server
Message-Id: <cbdgja$4rf$1@wisteria.csv.warwick.ac.uk>
Quoth shalinij1@yahoo.com (Shalini Joshi):
> Paul Lalli <mr_itty@gmail.com> wrote in message news:<20040623125654.Y23512@dishwasher.cs.rpi.edu>...
> > On Wed, 23 Jun 2004, Shalini Joshi wrote:
> >
> > > my @records;
> > > my $i;
> > > my $wanted_handle;
> > > my @selected_records;
> > > my $date;
> > > my $cpday;
> > > my $cpmonth;
> > > my $cpyear;
> > > my $cpdate;
> > > my $cpfilename;
> > > my %parameters;
> > > my $year;
> > > my $month;
> > > my $day;
> > > my $today;
> >
> > I'm going to guess that you use all these somewhere else in your actual
> > code? If not, please get rid of them. Declaring variables that you don't
> > use is bad coding style.
>
> Yeah right I use them elsewhere in the code. Actually i have to name
> the output file based on the date read in from the data file. Hence
> these variables.
It is generally considered bad style in Perl to declare all your
variables at the top of the file. Declare them just before you first use
them, or as near to that as puts them in the correct scope.
> > > local $[=1;
> >
> > Why are you changing the first index of arrays, and first indices of
> > substrings? Who (or what documentation) told you to do this, and for what
> > purpose?
>
> I wanted to parse a really long record....about 160 characters and the
> information for parsing that I had started the counting from 1. I
> looked up the camel book and to make it less tedious(well!!) for me i
> just decided to play with that one, instead of doing the subtractions
> !!!
This is a very bad idea: $[ is strongly deprecated, and will be removed
from Perl in the not-too-distant future.
If you have, say, an array of offsets into a string, you can do all the
subtractions at once like this:
@offsets = map { $_ - 1 } @offsets;
or, if you have lots of arrays,
$_-- for @offsets, @more_offsets, $yet, $more, $offsets;
Ben
--
"If a book is worth reading when you are six, * ben@morrow.me.uk
it is worth reading when you are sixty." - C.S.Lewis
------------------------------
Date: Wed, 23 Jun 2004 02:10:04 GMT
From: Rusty Phillips <rustyp@freeshell.org>
Subject: Config::Magic .72 released
Message-Id: <HzsJEy.ACD@zorch.sf-bay.org>
New module now available on CPAN for reading all kinds of
configuration files. .7 was just added to CPAN. .72 should enter
shortly, as it was uploaded a few hours ago. The difference is a fix of
some problems with the POD at the end of the module - none of the actual
mechanics of the module were changed.
The modules reads configuration files/strings and converts them into hash
references. It is capable of reading pretty much any kind of standard
config file - XML, CSV, apache, INI files, space separated, equals
separated, and many more. It can even read hybrids. Here's an example of
what the module is capable of:
Input file:
Section 1 {
[Section 4]
#Comment Style 1
\\Comment Style 2
; Comment Style 3
Monkey:1
Monkey=>2
Monkey:=3
Monkey 4
<Section 2>
Foo = Bar
Baz { Bip:1
Pants=5 }
</Section>
<Tasty Cheese="3" />
<Section 5>
Foo=Bippity,boppity,boo
</Section>
}
Output (from Data::Dumper)
$VAR1 = {
'Section 1' => {
'Tasty' => {
'Cheese' => {}
},
'Section' => [
{
'Foo ' => 'Bar',
'Baz' => {
'Bip' => '1',
'Pants' => '5'
},
'2' => {}
},
{
'Foo' => [
'Bippity',
'boppity',
'boo'
],
'5' => {}
}
],
'Section 4' => {
'Monkey' => [
'1',
'2',
'3',
'4'
]
}
}
};
Feedback is greatly appreciated.
------------------------------
Date: Wed, 23 Jun 2004 20:07:02 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Find length of files
Message-Id: <slrncdka9m.ca4.tadmc@magna.augustmail.com>
Michael Preminger <michaelp@hio.no> wrote:
> I have a huge directory, for which I need the word-count of all files
> (like wc -w * , and then put all length into a database)
>
> Is there a smart way to do it in perl?
Yes and no, depending on the definition of "smart". :-)
> (apart from wc * > file and then
> open the file..)
I don't like shelling-out for things that are easily done
in native Perl.
Perhaps you can adapt this "wc -w" workalike one-liner to your purposes?
perl -ane '$c+=@F; print("$c $ARGV\n"), $c=0 if eof(ARGV)' *
or suitable for a Real Program:
my $cnt = 0;
while ( <> ) {
my @words = split;
$cnt += @words;
if ( eof(ARGV) ) {
printf "$cnt $ARGV\n";
$cnt = 0;
}
}
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 24 Jun 2004 01:54:01 GMT
From: <foxhoundIV@yahoo.com>
Subject: noob trying to learn where to start?
Message-Id: <VuqCc.165954$Ly.35985@attbi_s01>
Hi all,
Would like to learn perl but not sure where to even start. Does anyone have suggestions
good books or sites, etc? I have some vb experience and no unix experience (working on that too).
Any help is very much appreaciated.
TIA!!
------------------------------
Date: 24 Jun 2004 02:41:04 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude>
Subject: Re: noob trying to learn where to start?
Message-Id: <Xns9511E6C3ABD4Easu1cornelledu@132.236.56.8>
<foxhoundIV@yahoo.com> wrote in news:VuqCc.165954$Ly.35985@attbi_s01:
> Hi all,
>
> Would like to learn perl but not sure where to even start. Does anyone
> have suggestions good books or sites, etc? I have some vb experience
> and no unix experience (working on that too). Any help is very much
> appreaciated.
Assuming you have Perl installed, check the FAQ:
perldoc -q learn
Also: http://learn.perl.org/
--
A. Sinan Unur
1usa@llenroc.ude (reverse each component for email address)
------------------------------
Date: Wed, 23 Jun 2004 22:47:40 -0400
From: Ken Sington <ken_sington@nospam_abcdefg.com>
Subject: Re: noob trying to learn where to start?
Message-Id: <ZKadnTpo1ede3Ufd4p2dnA@speakeasy.net>
foxhoundIV@yahoo.com wrote:
> Hi all,
>
> Would like to learn perl but not sure where to even start. Does anyone have suggestions
> good books or sites, etc? I have some vb experience and no unix experience (working on that too).
> Any help is very much appreaciated.
>
> TIA!!
>
>
www.perldoc.com
standard stuff:
http://www.oreilly.com/catalog/lperl3/
I recomend: http://www.oreilly.com/catalog/perlcdbs4/
as for unix, try Linux.
www.ibiblio.org
http://www.ibiblio.org/pub/linux/distributions/
------------------------------
Date: Thu, 24 Jun 2004 02:03:34 GMT
From: Rocco Caputo <troc@pobox.com>
Subject: Re: problem between perl-gtk2 and POE::Session
Message-Id: <slrncdke49.hdf.troc@eyrie.homenet>
On Mon, 21 Jun 2004 12:10:27 +0200, Krisztian VASAS wrote:
>
> Hello...
>
> I have some problem with perl-gtk2 and POE...
>
> I'd like to write a small chat client in gtk2, but it doesn't want to
> work as I'd like to.
>
> If the program starts, 2 Gtk2::Window is opened (the main window and the
> login window). After writing the nick and clicking to the OK button, the
> connection should start. In the background I'm watching the OK button's
> signal_connect("clicked") event, and I'd like to start a POE::Session
> callback, but I can't see the $_[SESSION] variable in signal_connect().
>
> The code is viewable here: http://nomorepasting.com/paste.php?pasteID=14758
>
> The problem is in 200th line.
>
> I could see, that the $var variable contains the $okbutton in akarmi()
> function insted of the $_[SESSION].
Line 200 reads:
$okbutton->signal_connect("clicked", akarmi, $var);
You are using the return value of the call to akarmi() as your callback.
That is probably incorrect. Try this instead:
$okbutton->signal_connect("clicked", \&akarmi, $var);
Your code has other problems, too. For example, line 139:
my ($session, $heap) = shift;
$session is being initialized, but $heap remains undefined. It might be
better written as:
my ($session, $heap) = @_;
You may want to turn on C<use warnings> and C<use strict> to flush out
other problems, at least temporarily until you're more comfortable using
Perl.
for($i=0;$i<=$#szerver;$i++) {
my $menuitem = Gtk2::RadioMenuItem->new_with_label($group, $szerver[$i]);
$group = $menuitem->get_group;
$menu->append($menuitem);
$menuitem->show;
}
would be better written as:
foreach my $thingy (@szerver) {
my $menuitem = Gtk2::RadioMenuItem->new_with_label($group, $thingy);
$group = $menuitem->get_group;
$menu->append($menuitem);
$menuitem->show;
}
... replacing $thingy with a better name, of course.
Finally, there is a problem in POE::Loop::Gtk2 on the CPAN. It was reported
last week, but I was at YAPC and couldn't get to it until today. We were able
to diagnose the problem today and send a patch to its author. I hope it will
be updated soon.
--
Rocco Caputo - rcaputo@pobox.com - http://poe.perl.org/
------------------------------
Date: 23 Jun 2004 20:47:22 -0700
From: shalinij1@yahoo.com (Shalini Joshi)
Subject: repeated calculations everyday
Message-Id: <283d6b7e.0406231947.4f882b57@posting.google.com>
Hey.
The following is the logic-structure of the code I am attempting to
write:
if (today is the first of the month)
{
Read all files with name containing SYSMT03.xxxxx.txt
#x denotes arbitrary value
Each file contains information pertaining to a particular owner. So
I parse the data no1, y for each user . Now this entire data from all
these files is to be sorted on the basis of this no1. That is more
than one user can have the same value for no1.
#The question I ask at this point is, how would I go about doing this
in perl? #What data structure would I use given this ?
I have to sum the total of y(from various user files) for each no1. I
call this value BASE1
}
else if (today is not the first day of the week, then for each
remaining day(recurring calculations)
{
Read another set of files names containing SYSMT02Axxxx.txt
Again similar information. Now what I will do here is calculate the
change in BASE and add it to BASE1 to get at BASE2. SImilarly for the
remaining days.(eg BASE3= BASE2+change3)..
}
How will I be able to go about designing the data structures etc in
perl?
I would appreciate any tips/help/reading references...
I am getting stuck right in the beginning itself...where I try and
match the regular expressions:
I say :
open (ACCOUNT_POSITION, '/home/perlstuff' ) or die "Can't open file:
$!\n";
<ACCOUNT_POSITION> =~ /.+03\..{5}\.txt
It doesnt work for some reason although i have the said file in my
directory. Where am I going wrong on this one???
Thanka again for all the help in past and in advance for this one!
Regards
Shalini
------------------------------
Date: Wed, 23 Jun 2004 20:20:37 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Using closures with "use strict"
Message-Id: <slrncdkb35.ca4.tadmc@magna.augustmail.com>
ddtl <this.is@invalid> wrote:
> If I define a "use strict" and want to create a closure,
> -------------------------------------------
> use strict;
>
> {
> our $f = sub {print "Hi\n";};
> }
>
> &$f;
> -------------------------------------------
There is no closure there you know.
Maybe your question is how to make a closure or what constitutes
a "closure"?
> Obviously, though 'f' is declared using 'our' modifier, as there
> is no such a global variable called 'f', using 'our $f;' creates
> some kind of restricted global variable (don't know even how to
> call it - that variable works like a global one, but it's "globalness"
> is restricted to the enclosing block).
I think you are confusing the scope of the _name_ of the variable
with being able to access the value of the variable.
You can always access package variables (so they are "global").
All our() does for you is give you temporary ('til end of block)
permission to use short names instead of fully qualified names.
with our($x):
print $x;
without our($x):
print $main::x;
or
print $Cool::Package::x;
You can access the value at any place in the code, its value is global.
You can access the value by the "short name" only in the our()'s scope.
> Is there is a better way to do that?
I think the other followups have already done that part.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 24 Jun 2004 03:33:37 GMT
From: ChrisO <ceo@nospam.on.net>
Subject: Re: Using Perl to create user accounts on Windows 2003
Message-Id: <lYrCc.811$e71.82@newssvr33.news.prodigy.com>
Maynard wrote:
> Hello all,
>
> I have Windows 2003 FTP servers that I store content on for external
> users to pick up on a schedule. Unfortunately I have about 300 of
> such users, and multiple servers. The time and energy to create these
> user accounts is obviously a factor, especially if I have to rebuild a
> box and have it up and running quickly.
>
> So, I went looking for Perl scripts / modules that could do this, but
> all I came up with was some old (for NT4) ones that used
> Win32::Lanman. I'm not creating domain (Active Directory) accounts,
> just local ones on the box. I have the users in a comma-delimited
> file, and really just need a shove in the right direction.
>
> Any suggestions would be most appreciated.
Win32::Lanman is really nice as I recall, and I think it's had some
updating done since WNT 4.0. Almost positive. Anyway, I'm recalling my
thoughts from about 2-3 years back.
I think if you depend on the ActiveState documentation (assuming that is
what you are using, which it is almost sure to be), it may take you some
time to come to grips with actually pulling it off. Again, as I recall,
it took some time experimenting before I got user adds (deletes, etc.)
exactly right.
Enclosed is a snippet which might help. Some extraneous lines removed.
Just view the hash reference passed in as a data structure holding the
relevant information I had gathered before calling the Win32API::Net
module (is what I chose at the time for doing my adds). This shouldn't
be too hard to follow:
(I know you want just a local machine add -- but keep reading)
use Win32API::Net qw( :User );
sub AddUserToDomain {
## Get parameters.
my $req = shift; # A request hash reference
## Load up local info hash needed by UserAdd, GetInfo, etc.
my $h = {
name => $req->{userid},
password => $req->{password},
passwordAge => 0,
priv => USER_PRIV_USER(),
homeDir => $req->{homedir},
comment => $req->{comment},
flags => (UF_SCRIPT & UF_NORMAL_ACCOUNT),
scriptPath => $req->{loginscript},
authFlags => 0,
fullName => $req->{fullname},
usrComment => $req->{comment},
parms => $Script{DESC},
workstations => '',
lastLogon => 0,
lastLogoff => 0,
acctExpires => -1,
maxStorage => -1,
unitsPerWeek => 0,
logonHours => [ 0x0F, 0x0F, 0x0F,
0x0F, 0x0F, 0x0F,
0x0F, 0x0F, 0x0F,
0x0F, 0x0F, 0x0F,
0x0F, 0x0F, 0x0F,
0x0F, 0x0F, 0x0F,
0x0F, 0x0F, 0x0F, ],
badPwCount => 0,
numLogons => 0,
logonServer => '',
countryCode => 0,
codePage => 0,
userId => 0,
primaryGroupId => 0x201,
profile => $req->{userprofile},
homeDirDrive => $req->{homedrive},
passwordExpired => $req->{expirepwd},
};
## Add the user and get the return value.
## (This is Win32API::Net::UserAdd())
my $rv = 0; # Return value (assume OK)
UserAdd( $req->{pdc}, 3, $h, $rv ); # Add the user
## Return success or error code.
$rv;
}
__END__
I believe $Script{DESC} above was just some descriptive text about the
script running which ended up in the record of the user account created.
Something like that. Now that I look, I see the examples in
Win32API::Net are a bit more descriptive than Win32::NetAdmin.
I believe if you substitute the name of your local machine
($ENV{COMPUTERNAME}) with the "$req->{pdc}" above, this will work for a
local machine add? Sorry, I don't have time to test this in that scenario.
HTH,
-ceo
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 6721
***************************************