[19686] in Perl-Users-Digest
Perl-Users Digest, Issue: 1881 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Oct 5 18:05:53 2001
Date: Fri, 5 Oct 2001 15:05:11 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1002319511-v10-i1881@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 5 Oct 2001 Volume: 10 Number: 1881
Today's topics:
"chdir" argument as a variable... (Bruce Schreiber)
Re: "chdir" argument as a variable... <jeff@vpservices.com>
Re: "chdir" argument as a variable... <jeff@vpservices.com>
Re: "chdir" argument as a variable... <thomas@baetzler.de>
Re: Can't get $? to work... (BUCK NAKED1)
Re: Can't get $? to work... nobull@mail.com
CGI Authorization module? <cybertoast@mindless.com>
Re: Coding pratices (Miko O'Sullivan)
Re: Coding pratices (Todd Weaver)
Re: Coding pratices <newspost@coppit.org>
Re: Efficient code? <s.warhurst@rl.ac.uk>
Re: Embedding Problem Win32 (Thomas Stammeier)
Help -- array/hash headaches viscido@u.washington.edu
Re: Help -- array/hash headaches <thomas@baetzler.de>
Re: Help -- array/hash headaches viscido@u.washington.edu
Re: How to add date stamp to a log file (Venkatesh Babu Sira)
Re: HTTP Binary File Transfer <thomas@baetzler.de>
Re: HTTP Binary File Transfer <r1ckey@home.com>
LISA 2001: Explore the future of system administration <mktgadm@usenix.org>
Re: Multiplexing strings - one line only <joe+usenet@sunstarsys.com>
Re: Multiplexing strings <bart.lateur@skynet.be>
Re: oop question <mjcarman@home.com>
Re: Perl and Solaris Version Upgrade <calle@lysator.liu.se>
perldoc problem, on darwin/OS X 10.1 <ookookook@yahoo.com>
Re: perldoc problem, on darwin/OS X 10.1 <znu@znu.dhs.org>
Reading the arguments paased to perl script (Tana)
Re: Reading the arguments paased to perl script <jeff@vpservices.com>
sending AT commands to a modem (costa)
Re: strangeness (bug?) in regexp handling <vvv@vsu.ru>
Re: strangeness (bug?) in regexp handling <thomas@baetzler.de>
Re: strangeness (bug?) in regexp handling <vvv@vsu.ru>
Re: strangeness (bug?) in regexp handling <thomas@baetzler.de>
Re: what am I doing wrong ? (Miko O'Sullivan)
Re: what am I doing wrong ? <jeff@vpservices.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 5 Oct 2001 11:58:14 -0700
From: bruces@real-info.com (Bruce Schreiber)
Subject: "chdir" argument as a variable...
Message-Id: <f1645a5c.0110051058.721fcbc4@posting.google.com>
I would like to change directory within a script where the directory
name is taken from a list in a text file, i.e.
$file = 'list.txt'; # Name the file
open(INFO, $file); # Open the file
@lines = <INFO>; # Read it into an array
foreach $i (@lines) { # Read each line of the array
#chdir $i
open(OUT,"> command$i"); # Open output file
print OUT "FILE $i.unl"; # Print text to output file
print OUT "DELIMITER '|' 20\;\n"; # Print text to output file
print OUT "INSERT INTO sales_temp\;\n"; # Print text to output file
close(OUT); # Close output file
#chdir '..';
}
close (INFO); # Close array
So that every line within 'list.txt' is the name of an actual
directory below the script directory. So if 'list.txt' is:
dirA
dirB
dirC
Then each iteration of the foreach loop will create the file
"commanddirA" (or whatever is next) in the directory "dirA" (which
does exist) and then go back to the original script directory. I've
tired quotes, double quotes, parentheses, nothing seems to work. (Yes,
I know the lines are commented out)
Can anybody help me with this?
Thanks
------------------------------
Date: Fri, 05 Oct 2001 12:02:03 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: "chdir" argument as a variable...
Message-Id: <3BBE03AB.BC67D2DB@vpservices.com>
Bruce Schreiber wrote:
>
> open(INFO, $file); # Open the file
1. ALWAYS check the sucsess of file operations, change that to:
open(INFO,$file) or die "Couldn't open '$file': $!";
> @lines = <INFO>; # Read it into an array
2. Learn how to read a file a line at a time rather than putting the
file into an array. Cardinal Surphammer is justifiably grouchy.
> #chdir $i
If you apply rule #1 above here, you'll solve your own problem by
finding out what is going wrong:
chdir $i or die "Couldn't cd to '$i': $!";
--
Jeff
------------------------------
Date: Fri, 05 Oct 2001 12:04:39 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: "chdir" argument as a variable...
Message-Id: <3BBE0447.F45E0C73@vpservices.com>
Jeff Zucker wrote:
>
> 2. Learn how to read a file a line at a time rather than putting the
> file into an array. Cardinal Surphammer is justifiably grouchy.
Ooops, hope he doesn't nail me for spelling his name wrong
s/Surphammer/Slurphammer/;
--
Jeff
------------------------------
Date: Fri, 05 Oct 2001 21:27:26 +0200
From: Thomas Bätzler <thomas@baetzler.de>
Subject: Re: "chdir" argument as a variable...
Message-Id: <t92srtgd719a77smacq2327en57j4nfrso@4ax.com>
On Fri, 05 Oct 2001, Jeff Zucker <jeff@vpservices.com> wrote:
>Jeff Zucker wrote:
>> 2. Learn how to read a file a line at a time rather than putting the
>> file into an array. Cardinal Surphammer is justifiably grouchy.
>
>Ooops, hope he doesn't nail me for spelling his name wrong
>
>s/Surphammer/Slurphammer/;
Well, I'd say the follow-up was speedy enough to ensure that he only
nails one of your feet to the floor :-)
Dinsdale?
SCNR,
--
use strict;my($i,$t,@r)=(0,'5 -.@BHJPT4acd6e2hk2lmn2o4r2s3tuz',map{ord}
split//,unpack('u*','L#`T&)QD5#0`#!!`#%1D)#08`#P05!!(3``$$"``#"0L&``('.
'"`P<!`````0$`'));$t=~s/(\d)(.)/$2x$1/eg;map{$t.=substr$t,$i,1,''while
$_--;$i++}@r;print"$t\n";# Thomas@Baetzler.de - http://baetzler.de/perl
------------------------------
Date: Fri, 5 Oct 2001 13:38:30 -0500 (CDT)
From: dennis100@webtv.net (BUCK NAKED1)
Subject: Re: Can't get $? to work...
Message-Id: <2647-3BBDFE26-33@storefull-243.iap.bryant.webtv.net>
$? doesn't appear to work with the Net::FTP module either. It must be a
bug in the module.
Regards,
--Dennis
------------------------------
Date: 05 Oct 2001 21:13:04 +0100
From: nobull@mail.com
Subject: Re: Can't get $? to work...
Message-Id: <u9u1xdonfz.fsf@wcl-l.bham.ac.uk>
peter@servplex.com (Peter Elsner) writes:
> `echo \"cd data\nascii\nput $FILENAME\nquit\n\" | ftp -i $SERVER`;
>
> $ERR=$?;
ISTR that the exit value of a pipeline may be the exit value of the
_first_ command (i.e. echo in this case) in some shells.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Fri, 05 Oct 2001 15:37:44 -0500
From: sundar <cybertoast@mindless.com>
Subject: CGI Authorization module?
Message-Id: <3BBE1A18.4090508@mindless.com>
I've been using some code for authorizing my users against a MySQL
database for my CGI code (using File::Cache and cookies).
I was wondering if there was anyone working on something like a
CGI::Auth in order to do this. I've found that I'm adding more and
more features, and it dawned on me that I should see if any module
exists out there that does this. Could not find anything on CPAN, so I
figured that this would be the best place to check.
Thanks.
------------------------------
Date: 5 Oct 2001 11:56:49 -0700
From: miko@idocs.com (Miko O'Sullivan)
Subject: Re: Coding pratices
Message-Id: <db27ea77.0110051056.1c396133@posting.google.com>
Michael Carman <mjcarman@home.com> wrote in message news:<3BB0E2F8.25651ACD@home.com>...
> As a general rule; if you have a piece of functionality that you may
> want to use in multiple scripts, it makes sense to factor it out and
> make it into a module.
I've adopted a variant of this concept that has worked quite well for
me. I no longer break things out into modules just because I predict
that they may be useful elsewhere. I've found that (speaking for
myself anyway) I'm rarely able to predict what will actually be useful
and what the module's interface should be. I've ended up writing many
modules that it turns out I don't need again or are needed in a very
different manner than I anticipated.
Instead, I just write the code in place. Later if (big if) I actually
need that functionality again I find that it's pretty simple to tear
out the code and call it in two places. By doing so I have two data
points on how that functionality is needed. Often I wait for three.
Some of my programmer friends find this practice almost heresy.
Perhaps I'm just a lousy coder who has no talent for predicting, but
in lieu of actual talent I find that my "wait and see" approach serves
me quite well.
-Miko
------------------------------
Date: 5 Oct 2001 12:20:49 -0700
From: toddw@doubletwist.com (Todd Weaver)
Subject: Re: Coding pratices
Message-Id: <4b7e74e5.0110051120.42c101ba@posting.google.com>
I must agree breaking up code early and often can also help you to
write better code and more relevent comments. You will avoid the
habit of reffering to specific details that pertain to just this
script in your comments when you are writing a new sub or new
functionality.
one of the first modules I wrote (vss.pm) was designed to deal with
command line operation to interact with that piece of garbage code -
MS Visual SourceSafe (what a nightmare) if I need to talk to VSS I
would call the module. The script was aware of vss.pm because it is
noted in a "use" statement just like "use strict;" it would be "use
vss;" By the way if you do not have "use strict;" at the beginning of
every script you write or yo uare not familiar with "my" when
initializing variable (my $var=$ENV{COMPONENTS_HOME} instead of
$var=$ENV{COMPONENTS_HOME}) you should start right now. as your
scripts grow you are asking for trouble if you don't use strict.
I would suggest that you "abstract" your perl code, it will help you
when you are faced with real object oriented programming, which you
can do in Perl now if you wish.
IMHO,
Todd
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message news:<9pkf7o$iks$1@mamenchi.zrz.TU-Berlin.DE>...
> According to Michael Carman <mjcarman@home.com>:
> > Dylan Riley wrote:
>
> [one big source or many small modules?]
>
> > As a general rule; if you have a piece of functionality that you may
> > want to use in multiple scripts, it makes sense to factor it out and
> > make it into a module. Anything unique to the current script normally
> > goes in the main file.
> >
> > > I'm faced with the dilema of either making the script bigger and
> > > bigger or cutting it into a bunch of smaller interconnected files.
> >
> > At some (arbitrary) point, it's probably a good idea to break it apart.
> > It will make maintenance easier. When you reach that point, try to find
> > logical subsets of the functionality and break things apart that way.
>
> Breaking apart source code that has grown too big is hard. *Because*
> it has all been developed in one file, there tend to be cross-dependencies
> that could have been avoided, and which now make it hard even to discern
> the logical subsets, let alone separate them.
>
> Putting together modules in a single file is usually far easier. There-
> for I recommend to break out subparts early and often, even if they don't
> seem to deserve to be an independent module at the time. That way you
> get to keep clean interfaces between the parts, even if they finally end
> up in one file. It will help making the code maintainable.
>
> Anno
------------------------------
Date: Fri, 05 Oct 2001 16:56:26 -0400
From: David Coppit <newspost@coppit.org>
Subject: Re: Coding pratices
Message-Id: <3BBE1E7A.1080703@coppit.org>
Miko O'Sullivan wrote:
> Michael Carman <mjcarman@home.com> wrote in message news:<3BB0E2F8.25651ACD@home.com>...
>
>>As a general rule; if you have a piece of functionality that you may
>>want to use in multiple scripts, it makes sense to factor it out and
>>make it into a module.
>
> I've adopted a variant of this concept that has worked quite well for
> me. I no longer break things out into modules just because I predict
> that they may be useful elsewhere. I've found that (speaking for
> myself anyway) I'm rarely able to predict what will actually be useful
> and what the module's interface should be. I've ended up writing many
> modules that it turns out I don't need again or are needed in a very
> different manner than I anticipated.
Actually, this point of view is supported by extreme programming--don't
invest resources implementing a solution that (1) may turn out to be
wrong, and (2) may never be used. It's likely that later on you'll start
to see the right structure of your system, and will be better able to
modularize.
That said, I'm not a big fan of this philosophy when taken as gospel.
There's a lot of benefit that can be had by doing some up-front design
work. People who jump right in and start coding often have software that
looks like the Winchester House in California
(http://www.winchestermysteryhouse.com/), or they spend a lot of time
reworking things as they go.
David
------------------------------
Date: Fri, 5 Oct 2001 19:17:58 +0100
From: "S Warhurst" <s.warhurst@rl.ac.uk>
Subject: Re: Efficient code?
Message-Id: <9pktgm$uua@newton.cc.rl.ac.uk>
"Benjamin Goldberg" <goldbb2@earthlink.net> wrote in message
news:3BBD086B.B21DA3C7@earthlink.net...
> Hmm, for each line of the 1E5 line file, you want to know whether or not
> at least one of the 50 strings is part of that line...
>
> Here are a number of methods, though which one is fastest, I don't know.
[...]
Thanks for the compilation :)
At the moment the code runs in a little over 2 minutes.. that's with my
clunky if..elsif method.. 2 minutes is acceptable for this application but I
want to get into the right programming practise to make programs as
efficient as possible. I have a deadline to make but after that I will try
these other methods and benchmark them.
Regards
Spencer
------------------------------
Date: 5 Oct 2001 11:06:12 -0700
From: tst3000@hotmail.com (Thomas Stammeier)
Subject: Re: Embedding Problem Win32
Message-Id: <6a8da949.0110051006.6563e@posting.google.com>
tst3000@hotmail.com (Thomas Stammeier) wrote in message news:<6a8da949.0110040649.4d6ee4f1@posting.google.com>...
> Hi,
>
> I'm having problems embedding Perl 5.6.1 (W2k) in my application. I
> downloaded the source code, compiled, installed...everything OK.
> When I try to link my application I get a couple of linker errors, for
> example the symbol "Perl_Isv_undef_ptr" is not defined.
> The thing is, I can compile and link perfectly using ActiveState's
> ActivePerl 5.6.
> The symbol in question (among others) is exported by ActiveState's
> perl56.dll but not by perl56.dll that I have compiled myself.
>
> Looking up in perlapi.h i found
> #undef PL_sv_undef
> #define PL_sv_undef (*Perl_Isv_undef_ptr(aTHXo))
>
> Scanning through the source code, I found that "Perl_Isv_undef_ptr" is
> defined nowhere ?
Ok, Found out myself, I missed some configuration settings in Makefile
(multiplicity, ithreads, etc.)
Thomas
------------------------------
Date: 05 Oct 2001 11:12:25 -0700
From: viscido@u.washington.edu
Subject: Help -- array/hash headaches
Message-Id: <m3d742yn06.fsf@fiddler.u.washington.edu>
I am working on doing some statistics involving groups of animals,
where the animals can change groups from one time step to the
next. Each animal in the population has an ID# (1, 2, 3...).
We want to know which group mates (stored in @mates in the current
iteration loop as an array) are the same this time step, as last time
step, and which are different, for each individual. I have the nitty
gritty of the mechanics figured out, but array and hash referencing is
driving me bananas. I thought perhaps someone here could help, since
none of my books are giving me any insight. I'm using perl 5.6.1 on a
linux 2.2 system.
The %schoolmates hash contains the school mates from the previous time
step, for each animal (fish in this case). Thus, for each animal,
$fish, the hash element $schoolmates{$fish} is an array, containing
the id# of each other fish in the school. So if animal 1 has animals
2, 4, and 7 in his school, then $schoolmates{1} = [2, 4, 7]. And so
on.
At the top of the program, I have the following lines to initialize
things, since "your school mates last time step" at time 0 must be "no
one" (or something similar).
for ($fish=1, $fish <= $n, $fish++) {
# For each fish, set its $schoomates{$fish} to "empty"
$schoolmates{$fish} = [];
}
(Note, I have tried this using a "ghost number" (-9999) and the
problems listed below do not go away.)
Now, deeper into the program, we build a list of groups, as a
hash called %grp. Thus, $grp{1} = the members of group 1. $grp{2} =
the members of group 2, and so on. Again, each hash element is an
array, so if group 1 contains 1, 2, 4, and 7, then $grp{1} = [1, 2, 4,
]. Etc.
Here is how I go about finding the current list of school mates for
individual x, and then read in the previous list of school mates:
foreach $fish ( @{ $grp{$key} } ) {
# We can store for each fish, its school mates
# for this frame. We "remove" the $fish element
# -- you're not your own group mate.
# First set the array
my @mate_array = @{ $grp{$key} };
# Remove the focal fish using a subroutine written
# specifically for that purpose
my @mates = remove(@mate_array, $fish);
# Figure out who his mates were last frame.
@lastmates = $schoolmates{$fish};
.....
<then lots of other programming here that doesn't mean
much for this question>
# Now set up the schoolmates for the next cycle with
# the current @mates list, so we can compare next time
# step
$schoolmates{$fish} = [ @mates ];
print LOG "$frame $fish @mates <--- @lastmates\n";
}
What this should print out is the list of current mates, and the list
of previous mates, with "<----" separating them (for now, since the
stats of the program are not working, this is all I have it doing).
@mates comes up just fine, but @lastmates prints as
ARRAY(0x102231fc). Because I am doing other types of comparisons,
using @lastmates compared to @mates, since @mates prints out as
numbers and @lastmates prints as stuff such as ARRAY(0x102231fc), I am
getting results that look odd. For instance, even though 4 of 4 fish
are in the same group in time 41 and time 42, individual #1's mates
are considred 100% different (which is not possible, since the entire
population was in his group in both time steps). Thus @mates and
@lastmates are not being seen as equivalent, even though they are
identical and should come up as such.
I have tried doing
@lastmates = @{ $schoolmates{$fish} };
to no avail. (In fact, that is how I first wrote it, thinking it was
the proper way of doing this.) Instead what I get is an error message,
"Can't use an undefined value as an ARRAY reference at ...." blah,
blah, blah. This is true whether $schoolmates{$fish} is set to [] at
the top of the program, or [-9999] (a "ghost" value just to see if it
couldn't deal with empty arrays, given the nature of the error
message).
It seems to me that I need to in some way use
referencing/dereferencing here, but my attempts to do so have
similarly met with failure, resulting either in errors or in
ARRAY(0x102231fc) type results. Also, setting $schoolmates{$fish} =
@mates (instead of = [@mates]) does not work either.
Anyone have any advice for how to get @lastmates to read
$schoolmates{$fish} as a regular old array, and behave properly?
Thanks in advance for any help you can offer.
Steve
--
Steven Viscido [viscido@u.washington.edu]
Department of Zoology, Box 351800 Kincaid Hall
University of Washington
Seattle, WA 98195 Tel: 206-221-6893
------------------------------
Date: Fri, 05 Oct 2001 21:45:59 +0200
From: Thomas Bätzler <thomas@baetzler.de>
Subject: Re: Help -- array/hash headaches
Message-Id: <7n2srt4a3neuoacjpp7g8nfkk1scconeap@4ax.com>
On 05 Oct 2001 11:12:25 -0700, viscido@u.washington.edu wrote:
>I am working on doing some statistics involving groups of animals,
>where the animals can change groups from one time step to the
>next. Each animal in the population has an ID# (1, 2, 3...).
[...]
>for ($fish=1, $fish <= $n, $fish++) {
> # For each fish, set its $schoomates{$fish} to "empty"
> $schoolmates{$fish} = [];
>}
Looks good. $schoolmates{$fish} is now a reference to an empty
anonymous array.
> @lastmates = $schoolmates{$fish};
This should be @{$schoolmates{$fish}}, unless you want @lastmates to
become an array of one element, i.e. the pointer to the array.
> $schoolmates{$fish} = [ @mates ];
> print LOG "$frame $fish @mates <--- @lastmates\n";
>@mates comes up just fine, but @lastmates prints as
>ARRAY(0x102231fc).
See above.
>I have tried doing
>
>@lastmates = @{ $schoolmates{$fish} };
>
>to no avail. (In fact, that is how I first wrote it, thinking it was
>the proper way of doing this.) Instead what I get is an error message,
>"Can't use an undefined value as an ARRAY reference at ...." blah,
Must be a problem somewhere else.
#!/usr/bin/perl -w
use strict;
my %schoolmates;
$schoolmates{thomas} = [];
sub find_mates {
if( shift ){
return qw( Tom Dick Harry );
} else {
return qw( Foo Baz Bar );
}
}
for ( 0..1 ){
my @oldmates = @{$schoolmates{thomas}};
my @newmates = find_mates( $_ );
$schoolmates{thomas} = [ @newmates ];
print "'@newmates' <- '@oldmates'\n";
}
--
use strict;my($i,$t,@r)=(0,'5 -.@BHJPT4acd6e2hk2lmn2o4r2s3tuz',map{ord}
split//,unpack('u*','L#`T&)QD5#0`#!!`#%1D)#08`#P05!!(3``$$"``#"0L&``('.
'"`P<!`````0$`'));$t=~s/(\d)(.)/$2x$1/eg;map{$t.=substr$t,$i,1,''while
$_--;$i++}@r;print"$t\n";# Thomas@Baetzler.de - http://baetzler.de/perl
------------------------------
Date: 05 Oct 2001 13:47:55 -0700
From: viscido@u.washington.edu
Subject: Re: Help -- array/hash headaches
Message-Id: <m3adz5zudg.fsf@fiddler.u.washington.edu>
Thomas Bätzler <thomas@baetzler.de> writes:
>
> >I am working on doing some statistics involving groups of animals,
> >where the animals can change groups from one time step to the
> >next. Each animal in the population has an ID# (1, 2, 3...).
> [...]
> >for ($fish=1, $fish <= $n, $fish++) {
> > # For each fish, set its $schoomates{$fish} to "empty"
> > $schoolmates{$fish} = [];
> >}
>
> Looks good. $schoolmates{$fish} is now a reference to an empty
> anonymous array.
Actually, I missed something obvious (logically) but easy to miss
(visually). Look up at the for (....) line. See it? Yup. I had commas
there instead of semi-colons. Arrggh.... This syntax caused $fish = 2
for every case, thus $schoolmates{1}, {4}, etc, were "undefined",
which is why @lastmates = @{ $schoolmates{$fish} } was yelling at
me. Fixing this simple syntax error solved my problem.
Thanks for the help though! And I'm glad I'm not the only one blind
enough to miss the difference between "," and ";" :)
>
> >I have tried doing
> >
> >@lastmates = @{ $schoolmates{$fish} };
> >
> >to no avail. (In fact, that is how I first wrote it, thinking it was
> >the proper way of doing this.) Instead what I get is an error message,
> >"Can't use an undefined value as an ARRAY reference at ...." blah,
>
> Must be a problem somewhere else.
Yup, father on up. I found it by doing this:
print LOGFILE "@{$schoolmates{1}}\n";
as a line of code, and moving it up one block of code at a time, till
I figured out that it failed even INSIDE the original execution loop
where %schoolmates is first set, but changing it to {$fish} instead of
{1}, it worked. I then looked at the output in the log file, I saw
every single value of "$fish" was 2. Then I knew something was up, and
caught the "," instead of ";" bug.
Argh. Maybe I need to get glasses. Or at least hire a typist....
Steve
--
Steven Viscido [viscido@u.washington.edu]
Department of Zoology, Box 351800 Kincaid Hall
University of Washington
Seattle, WA 98195 Tel: 206-221-6893
------------------------------
Date: 5 Oct 2001 12:41:31 -0700
From: vsira@hotmail.com (Venkatesh Babu Sira)
Subject: Re: How to add date stamp to a log file
Message-Id: <d5b8dfd2.0110051141.7cd2cf19@posting.google.com>
Michael Budash <mbudash@sonic.net> wrote in message news:<mbudash-23BBBB.16484704102001@news.sonic.net>...
> In article <d5b8dfd2.0110041522.4a958ff5@posting.google.com>,
> vsira@hotmail.com (Venkatesh Babu Sira) wrote:
>
> > Michael Budash <mbudash@sonic.net> wrote in message
> > news:<mbudash-5266EF.12472303102001@news.sonic.net>...
> > > In article <d5b8dfd2.0110031103.2500563@posting.google.com>,
> > > vsira@hotmail.com (Venkatesh Babu Sira) wrote:
> > >
> > > > Michael Budash <mbudash@sonic.net> wrote in message
> > > > news:<mbudash-CAB4B9.13105302102001@news.sonic.net>...
> > > > > In article <d5b8dfd2.0110021136.3c5c31e7@posting.google.com>,
> > > > > vsira@hotmail.com (Venkatesh Babu Sira) wrote:
> > > > >
> > > > > > I have code like,
> > > > > > $LOGFILENAME = "logfile.txt";
> > > > > > I want to add time stamp like
> > > > > > $LOGFILENAME = "logfile.txt.$time";
> > > > > > ex: that it may look like logfile.txt.2oct2001 .
> > > > > > Tx
> > > > > > -B
> > > > >
> > > > > this does it with a format you probly _oughta_ use, if you ever
> > > > > wanna
> > > > > sort (or view a dir listing of) these files:
> > > > >
> > > > > NOTE: beware of word wrap below!
> > > > >
> > > > > use POSIX;
> > > > > $LOGFILENAME = 'logfile.txt.' . POSIX::strftime("%Y%m%d", 0, 0, 0,
> > > > > (localtime)[3..5]);
> > > > >
> > > > > the above (currently) yields;
> > > > >
> > > > > logfile.txt.20011002
> > > > >
> > > > > this version does it exactly as you requested:
> > > > >
> > > > > use POSIX;
> > > > > my @t = localtime;
> > > > > $LOGFILENAME = 'logfile.txt.' . $t[3], lc(POSIX::strftime("%b%Y\n",
> > > > > 0,
> > > > > 0, 0, @t[3..5]));
> > > > >
> > > > > the above (currently) yields;
> > > > >
> > > > > logfile.txt.2oct2001
> > > > >
> > > > > hth-
> > > >
> > > > Tx a lot Michael,second one i had to remove $t[3],other wise it will
> > > > create logfile.txt.3 .
> > > > -B
> > >
> > > that actually looks like a typo to me. replace the comma after $t[3]
> > > with a space-dot. i.e., should be:
> > >
> > > $LOGFILENAME = 'logfile.txt.' . $t[3] . lc(POSIX::strftime("%b%Y\n", 0,
> > > 0, 0, @t[3..5]));
> > >
> > > (tested)
> > >
> > > hth-
> >
> > Excellent,
> > It works,
>
> good
>
> >i have one more ? ,
> > What this means @t[3..5]
>
> it's called an array slice:
>
> http://www.perldoc.com/perl5.6/pod/perldata.html#Slices
>
> > also how can add time stamp to the above
> > ex 04oct2001:12:00:00
> > I am novice to perl :)
>
> the documentation you need to read is on your unix box:
>
> perldoc POSIX
> man strftime
>
> > Tx in advance
>
> no prob,
Hi,
Just an extension, how to add timestamp,
it should result like logfile05oct2001:12:00:00
------------------------------
Date: Fri, 05 Oct 2001 20:15:02 +0200
From: Thomas Bätzler <thomas@baetzler.de>
Subject: Re: HTTP Binary File Transfer
Message-Id: <h1urrt4t54qhfkdeok6hdra4ca32ojnim5@4ax.com>
On Fri, 05 Oct 2001 18:03:41 GMT, r1ckey <r1ckey@home.com> wrote:
> I'm trying to download a binary file via HTTP and save locally.
[...]
> $req->content_type('application/octet-stream');
This doesn't make sense.
> print BIN $ua->request($req)->as_string;
Have you looked at your output at all? as_string includes headers and
all - you want content instead. Do read the man pages.
HTH,
--
use strict;my($i,$t,@r)=(0,'5 -.@BHJPT4acd6e2hk2lmn2o4r2s3tuz',map{ord}
split//,unpack('u*','L#`T&)QD5#0`#!!`#%1D)#08`#P05!!(3``$$"``#"0L&``('.
'"`P<!`````0$`'));$t=~s/(\d)(.)/$2x$1/eg;map{$t.=substr$t,$i,1,''while
$_--;$i++}@r;print"$t\n";# Thomas@Baetzler.de - http://baetzler.de/perl
------------------------------
Date: Fri, 05 Oct 2001 20:08:18 GMT
From: r1ckey <r1ckey@home.com>
Subject: Re: HTTP Binary File Transfer
Message-Id: <Sqov7.5862$IY3.4737490@news1.rdc1.sfba.home.com>
>On Fri, 05 Oct 2001 18:03:41 GMT, r1ckey <r1ckey@home.com> wrote:
>> I'm trying to download a binary file via HTTP and save locally.
>[...]
>> $req->content_type('application/octet-stream');
>This doesn't make sense.
>> print BIN $ua->request($req)->as_string;
I tried to use content, it doesn't work either.
>Have you looked at your output at all? as_string includes headers and
>all - you want content instead. Do read the man pages.
Yes, I did look at the file, it's a bunch of binary junk, as it should be.
Maybe you could point me to the man page you're referring to. I went through
Google, local man pages and online docs, now I'm here.
>HTH,
>--
>use strict;my($i,$t,@r)=(0,'5 -.@BHJPT4acd6e2hk2lmn2o4r2s3tuz',map{ord}
>split//,unpack('u*','L#`T&)QD5#0`#!!`#%1D)#08`#P05!!(3``$$"``#"0L&``('.
>'"`P<!`````0$`'));$t=~s/(\d)(.)/$2x$1/eg;map{$t.=substr$t,$i,1,''while
>$_--;$i++}@r;print"$t\n";# Thomas@Baetzler.de - http://baetzler.de/perl
--
____ __
______/_ | ____ | | __ ____ ___.__.
\_ __ \ |/ ___\| |/ // __ < | |
| | \/ \ \___| <\ ___/\___ |
|__| |___|\___ >__|_ \\___ > ____|
_________________\/_____\/____\/\/_____
---------------------------------------
------------------------------
Date: Fri, 05 Oct 2001 11:26:52 -0700
From: Ann Tsai <mktgadm@usenix.org>
Subject: LISA 2001: Explore the future of system administration
Message-Id: <mktgadm-73E7F7.11265205102001@reader.news.uu.net>
Keywords: system administrator, system administrations, sys admin, UNIX, LINUX, OS, database, LISA, technical conference, seminar, tutorials, classes, invited talks, refereed papers, white papers, computers, operating systems, applications, hardware, software, SUN, Microsoft, windows, windows NT, symposium, security, databases, development, maintenance, troubleshooting, performance tuning, methodology, training, scaling, integration, programming, network, networking, technology, protocol, Perl, TCP/IP, hubs, routers, servers, CISCO, Oracle, Sybase, Open Systems
For fifteen years, LISA, The Systems Administration Conference, has been
the leading forum for system administrators to meet, learn, and exchange
ideas with one another on every aspect of computer and network
management. This year, LISA focuses on the latest in system and network
security by including security focused tutorials, invited talks, and a
special Network/Security track.
Register online by November 9 and SAVE up to $300.
15th Systems Administration Conference (LISA 2001)
December 2-7, 2001
San Diego, CA USA
http://www.usenix.org/events/lisa2001
Invited Speakers Include:
William LeFebvre, CNN Internet Technologies - JUST ADDED
"CNN.com: Facing a World Crisis
Greg Bear, multiple Hugo and Nebula Award winner, best-selling author of
Eon, Slant & Darwin's Radio "Slime vs. Silicon"
Phil Cox, SystemExperts Corp
"Hardening Windows 2000"
John S. Flowers, nCircle Network Security
"Armoring the Next Wave of Security Technology"
Ernest Prabhakar, Apple
"Rebuilding the Digital Enterprise Around Internet Standards"
LISA also provides practical, professional-level education through over
50 TUTORIALS, half of which are NEW.
* Real-World Intrusion Detection
* Network Security Profiles
* Hacking-Exposed: LIVE!
* An Introduction to Computer Security NEW!
* Practical Wireless IP Security and Connectivity
* Creating a Computer Security Incident Response Team NEW!
* UNIX Security Threats and Solutions NEW!
* Sendmail and Security NEW!
* System and Network Monitoring NEW!
* Forensic Computing
NEW!
SAGE, the System Adminstators Guild, is pleased to announce the launch
of our certification exam. Be the first to experience the SAGE Core exam
at LISA! For more info visit us today at
http://www.usenix.org/events/lisa2001
Attendees at LISA also receive a free copy of Selected Papers in System
Administration, to be published by Wiley in December and edited by Eric
Anderson, Mark Burgess, and Alva Couch.
------------------------------
Date: 05 Oct 2001 14:18:27 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Multiplexing strings - one line only
Message-Id: <m33d4yhrws.fsf@mumonkan.sunstarsys.com>
Dave Tweed <dtweed@acm.org> writes:
> I think to have a "proper" one-liner in this context, it needs to be an
> expression that yields the output value without side-effects.
> Jean-Philippe's first effort met these criteria, but wasn't fully general.
$n = 2;
@str = ($str1, $str2, $str3);
$out=(sub{$^A="",formline"^$_"x@_."~~",@_ for"<"x(shift()-1)}
->($n, map $_,@str),$^A); # map to avoid side-effects
--
Joe Schaefer "Sacred cows make the best hamburger."
--Mark Twain
------------------------------
Date: Fri, 05 Oct 2001 19:04:41 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Multiplexing strings
Message-Id: <b11srt00bu2ejq5fv63do5luf9nds95la1@4ax.com>
Anno Siegel wrote:
> $str1 =~ s/(..)/$1\0\0\0\0/g;
> $str2 =~ s/(..)/\0\0$1\0\0/g;
> $str3 =~ s/(..)/\0\0\0\0$1/g;
> $out = $str1 ^ $str2 ^ $str3;
>
>No, it isn't fast.
And why are you using xor instead of or?
--
Bart.
------------------------------
Date: Fri, 05 Oct 2001 12:45:44 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: oop question
Message-Id: <3BBDF1C8.AE9617C2@home.com>
Jens Luedicke wrote:
>
> $foo = new Foo;
> $foo->bar->baz("hello, world!");
>
> My object-oriented Perl knowledge is a little limited,
> so I would like to know how the above lines are coded in Perl
> (package Foo, methods, ...)
RTFM. There are several manpages included in the standard documentation
that discuss OO programming:
perlboot
perltoot
perltootc
perlobj
-mjc
------------------------------
Date: 05 Oct 2001 23:54:59 +0200
From: Calle Dybedahl <calle@lysator.liu.se>
Subject: Re: Perl and Solaris Version Upgrade
Message-Id: <868zep4urw.fsf@tezcatlipoca.algonet.se>
>>>>> "tintin" == tintin <tintin@snowy.calculus> writes:
> The OP was asking what versions of Perl are *compatible* with the Solaris
> version. That being the case, they all are.
Perl 4.036 is a total bastard to compile on most anything later than
Solaris 2.3, though.
--
Calle Dybedahl <calle@lysator.liu.se>
"Last week was a nightmare, never to be repeated - until this week"
-- Tom, a.s.r
------------------------------
Date: Fri, 05 Oct 2001 13:06:43 -0700
From: Ook <ookookook@yahoo.com>
Subject: perldoc problem, on darwin/OS X 10.1
Message-Id: <ookookook-F34B36.13064305102001@enews.newsguy.com>
I'm trying to do something along the lines of man -k fork, to look up how to fork off processes.
So, I'm using perldoc -r:
ook% perldoc -r fork
Can't opendir /Network/Library/Perl/darwin: No such file or directory at /usr/bin/perldoc line 287.
Any idea what I can do to fix this, or work around it?
--
Any inquiries without Ook! in the subject will be deleted without being read.
------------------------------
Date: Fri, 05 Oct 2001 16:59:49 -0400
From: ZnU <znu@znu.dhs.org>
Subject: Re: perldoc problem, on darwin/OS X 10.1
Message-Id: <znu-95C540.16594905102001@news.acedsl.com>
In article <ookookook-F34B36.13064305102001@enews.newsguy.com>,
Ook <ookookook@yahoo.com> wrote:
> I'm trying to do something along the lines of man -k fork, to look up how to
> fork off processes.
> So, I'm using perldoc -r:
>
> ook% perldoc -r fork
> Can't opendir /Network/Library/Perl/darwin: No such file or directory at
> /usr/bin/perldoc line 287.
>
>
> Any idea what I can do to fix this, or work around it?
Does 'perldoc -f fork' not give you what you want?
--
Even if you do learn to speak correct English, whom are you going to speak it
to?
-- Clarence Darrow
------------------------------
Date: 5 Oct 2001 11:46:21 -0700
From: tana@acedsl.com (Tana)
Subject: Reading the arguments paased to perl script
Message-Id: <4294f74d.0110051046.33d24c1d@posting.google.com>
Hi, I am new in perl programming:
How do I pass the arguments to a perl script in browser?
How do I read the arguments within a script?
I tried this:
#!/usr/bin/perl
use CGI;
$cgi=new CGI;
print $cgi->header();
# read the post
read (STDIN, $query, $ENV{'CONTENT_LENGTH'});
# assign posted variables to local variables
$user_id = $variable{'user_id'};
print "User ID: $user_id";
I call the script like this:
http://hepek.com/cgi-bin/PostPayPal.pl?first_name=John&last_name=Smith
But my script did not read the argument value.
What am I doing wrong?
thanks
Tana
------------------------------
Date: Fri, 05 Oct 2001 11:51:01 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Reading the arguments paased to perl script
Message-Id: <3BBE0115.7900928B@vpservices.com>
Tana wrote:
>
> How do I pass the arguments to a perl script in browser?
> How do I read the arguments within a script?
You already asked this yesterday and got three replies. If your
newsfeed doesn't still have yesterday's news, then look up the replies
here:
http://groups.google.com/groups
>
> # read the post
> read (STDIN, $query, $ENV{'CONTENT_LENGTH'});
NO do not do that. Read the CGI.pm documentation on the param() method.
--
Jeff
------------------------------
Date: 5 Oct 2001 12:36:16 -0700
From: costa.asti@tiscalinet.it (costa)
Subject: sending AT commands to a modem
Message-Id: <c7c06bf6.0110051136.5e2fa140@posting.google.com>
I'd like to control my serial modem from a perl script.
Do you know if there are any modules around?
I've read somewhere to use system calls (on Unix) but I wouldn't like
to use them because I'd like my script to run on non-Unix platforms
such us MacOS (using MacPerl)
thanks
Costa
------------------------------
Date: Fri, 05 Oct 2001 22:30:58 +0400
From: Vladimir Volovich <vvv@vsu.ru>
Subject: Re: strangeness (bug?) in regexp handling
Message-Id: <eyr8sidjml.fsf@vsu.ru>
Thomas, David,
TB> perldoc perlre
TB> I suspect \1 is not doing what you think it does.
yes. i \1 in a substitution text should expand into a character with
code 1 (because to get a reference value, i could use notation $1).
i wonder why there is such a duplication (and imho inconsistency).
to get byte values, should i always use 0-prefixed values like \001 ?
(will this work in both left-hand side and right-hand sides?)
TB> Maybe you could explain what you're trying to achieve first, next
TB> time.
i was removing everything from a string after a semicolon, except
preserving entities like é
TB> That makes finding potential bugs a lot easier. Anyways:
TB> my $a="abcáabc";
TB> $a =~ s/&([A-Za-z0-9#]+?);/<$1>/g;
this is more error-prone than using binary characters with codes 0 and
1, because a string could contain < and >.
TB> $a =~ s/;.*//;
TB> $a =~ s/<([A-Za-z0-9#]+?)>/&$1;/g;
DH> Also, some of those substitutions aren't doing anything. I think
DH> you need to re-examine this code.
the explanation above explains why i was using s/;.*//
DH> As another poster mentioned, please perldoc perlre and make sure
DH> you completely understand \1, etc.
Thanks, and sorry for bothering. [yet i'd like to understand the
reason for duplicating access to references as $<digits> \<digits>, to
the detriment of access to byte values. why not use $<digits> solely
for references, and \<digits> solely for bytes?]
Best,
v.
------------------------------
Date: Fri, 05 Oct 2001 21:07:49 +0200
From: Thomas Bätzler <thomas@baetzler.de>
Subject: Re: strangeness (bug?) in regexp handling
Message-Id: <5c0srt439tjrbjt8hqdv1h77s58110dubc@4ax.com>
On Fri, 05 Oct 2001, Vladimir Volovich <vvv@vsu.ru> wrote:
> TB> perldoc perlre
> TB> I suspect \1 is not doing what you think it does.
>yes. i \1 in a substitution text should expand into a character with
>code 1 (because to get a reference value, i could use notation $1).
Should it? Let's ask perlre:
"The customary Unix meaning of \1 is kludged in for s///."
>i wonder why there is such a duplication (and imho inconsistency).
Another quote from the same source::
"[...] to avoid shocking the sed addicts [...]"
>to get byte values, should i always use 0-prefixed values like \001 ?
>(will this work in both left-hand side and right-hand sides?)
As long as you're aware that this is the octal (base 7) notation, yes
in both cases.
> TB> my $a="abcáabc";
> TB> $a =~ s/&([A-Za-z0-9#]+?);/<$1>/g;
>
>this is more error-prone than using binary characters with codes 0 and
>1, because a string could contain < and >.
This was just to see wether this was what you had tried to achieve. I
mean, without the explanation
>i was removing everything from a string after a semicolon, except
>preserving entities like é
> TB> $a =~ s/;.*//;
> DH> Also, some of those substitutions aren't doing anything. I think
> DH> you need to re-examine this code.
>
>the explanation above explains why i was using s/;.*//
Yes, but you didn't achieve anything because the ; was already gone by
then - it was eaten in the first substitution. I still can't see what
exactly it is that you're trying to do. Could you give a real world
example?
>Thanks, and sorry for bothering. [yet i'd like to understand the
>reason for duplicating access to references as $<digits> \<digits>, to
>the detriment of access to byte values. why not use $<digits> solely
>for references, and \<digits> solely for bytes?]
For historical reasons. See above.
HTH,
--
use strict;my($i,$t,@r)=(0,'5 -.@BHJPT4acd6e2hk2lmn2o4r2s3tuz',map{ord}
split//,unpack('u*','L#`T&)QD5#0`#!!`#%1D)#08`#P05!!(3``$$"``#"0L&``('.
'"`P<!`````0$`'));$t=~s/(\d)(.)/$2x$1/eg;map{$t.=substr$t,$i,1,''while
$_--;$i++}@r;print"$t\n";# Thomas@Baetzler.de - http://baetzler.de/perl
------------------------------
Date: Fri, 05 Oct 2001 23:38:41 +0400
From: Vladimir Volovich <vvv@vsu.ru>
Subject: Re: strangeness (bug?) in regexp handling
Message-Id: <eyitdtev26.fsf@vsu.ru>
"TB" == Thomas Bätzler writes:
>> yes. i \1 in a substitution text should expand into a character
>> with code 1 (because to get a reference value, i could use
>> notation $1).
TB> Should it? Let's ask perlre:
TB> "The customary Unix meaning of \1 is kludged in for s///."
i missed a few words above by mistake. i should have writen "yes. i
thought that \1 in...", and that was my mistake (i should have used
\001 instead of \1).
TB> "[...] to avoid shocking the sed addicts [...]"
OK, thanks. But why sed addicts do not shock on \001 being treated as
a byte with octal value 001? :-)
(This looks like an inconsistency)
>> i was removing everything from a string after a semicolon, except
>> preserving entities like é
[...]
>> the explanation above explains why i was using s/;.*//
TB> Yes, but you didn't achieve anything because the ; was already
TB> gone by then - it was eaten in the first substitution. I still
TB> can't see what exactly it is that you're trying to do. Could you
TB> give a real world example?
consider the string like
François some < text; another text
i'd like to remove anything after (and including) the first "real"
semicolon. By "real" i mean a semicolon which is not used to construct
an HTML entity like the ç above (there could be any number of
entities in a string).
i.e., in the above case the result should be
François some < text
so this could be accomplished by
s/&([A-Za-z0-9#]+?);/\0$1\01/g;
s/;.*//;
s/\0([A-Za-z0-9#]+?)\01/&$1;/g;
(or is there a simpler solution?)
Best,
v.
------------------------------
Date: Fri, 05 Oct 2001 22:01:14 +0200
From: Thomas Bätzler <thomas@baetzler.de>
Subject: Re: strangeness (bug?) in regexp handling
Message-Id: <0l3srt01u1tkvv0a91f1e5eisj66tudblj@4ax.com>
On Fri, 05 Oct 2001, Vladimir Volovich <vvv@vsu.ru> wrote:
>consider the string like
>
>François some < text; another text
>
>i'd like to remove anything after (and including) the first "real"
>semicolon. By "real" i mean a semicolon which is not used to construct
>an HTML entity like the ç above (there could be any number of
>entities in a string).
You could first map all HTML entities to their "real" characters and
then capture a match from the start of the line up to the first
semicolon.
You certainly can't use negative lookback because that would've to be
fixed width.
Thanks for the explanation!
Ciao,
--
use strict;my($i,$t,@r)=(0,'5 -.@BHJPT4acd6e2hk2lmn2o4r2s3tuz',map{ord}
split//,unpack('u*','L#`T&)QD5#0`#!!`#%1D)#08`#P05!!(3``$$"``#"0L&``('.
'"`P<!`````0$`'));$t=~s/(\d)(.)/$2x$1/eg;map{$t.=substr$t,$i,1,''while
$_--;$i++}@r;print"$t\n";# Thomas@Baetzler.de - http://baetzler.de/perl
------------------------------
Date: 5 Oct 2001 11:22:31 -0700
From: miko@idocs.com (Miko O'Sullivan)
Subject: Re: what am I doing wrong ?
Message-Id: <db27ea77.0110051022.71e4903d@posting.google.com>
Jeff Zucker <jeff@vpservices.com> wrote in message news:<3BBD0E60.328C80A1@vpservices.com>...
> > #!/usr/bin/perl
> > use CGI;
>
> You should add warnings and strict to the start of your program,
> otherwise you won't know when something goes wrong.
... and tainting, always tainting for CGI's:
#!/usr/bin/perl -Tw
use strict;
-miko
------------------------------
Date: Fri, 05 Oct 2001 11:33:23 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: what am I doing wrong ?
Message-Id: <3BBDFCF3.72F3B1C7@vpservices.com>
Miko O'Sullivan wrote:
>
> Jeff Zucker <jeff@vpservices.com> wrote in message news:<3BBD0E60.328C80A1@vpservices.com>...
>
> > > #!/usr/bin/perl
> > > use CGI;
> >
> > You should add warnings and strict to the start of your program,
> > otherwise you won't know when something goes wrong.
>
> ... and tainting, always tainting for CGI's:
>
> #!/usr/bin/perl -Tw
> use strict;
Yep.
--
Jeff
------------------------------
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.
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 1881
***************************************