[6926] in Perl-Users-Digest
Perl-Users Digest, Issue: 551 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat May 31 23:28:23 1997
Date: Sat, 31 May 97 20:00:20 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sat, 31 May 1997 Volume: 8 Number: 551
Today's topics:
(Help!)Formating output to sendmail <kello@technicom.net>
Re: *NOT SPAM* Apprentice Perl Hacker, Summer Work Offe (Chipmunk)
Re: Bored? Want to evaluate my first (usefull) perl sc (Chipmunk)
Re: Bored? Want to evaluate my first (usefull) perl sc <rra@stanford.edu>
Columnar Report from CGI to SendMail <kello@technicom.net>
Re: filter out uids below 100 <keys@babylon5fan.com>
FRESH Email Addresses 7865nbffy@fia.net
Re: Good Perl Tutorial with exercises ?? rroberts@gowebway.com
Re: Help wanted PERL5.001 -> PERL5.003 (Andrew M. Langmead)
Internal data structure of lists <xrcc0494@dcaca037.ca.boeing.com>
logging script status to a log file <webmaster@deltastar.nb.ca>
Re: Making a pool, but one man = one vote (Ron Mayer)
Re: More PERL questions <rra@stanford.edu>
New FAQ question? Decimal -> Binary conversion <tpo9617@rit.edu>
Re: Perl poems? (Chipmunk)
Re: printf padding ... (Chipmunk)
Re: Slices of lists (Charles DeRykus)
Re: Socket reading (Charles DeRykus)
Re: What does main' in sub main'routine do? (Charles DeRykus)
Re: What's perl equivalent to awk's $1, $2, etc.? (O'Shaughnessy Evans)
while(<>) and perl -e: B.. or feature? <mschilli@blacksun.com>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 01 Jun 1997 03:37:50 -0300
From: Angelo Kello <kello@technicom.net>
Subject: (Help!)Formating output to sendmail
Message-Id: <33910AAE.17CE@technicom.net>
(URGENT HELP!) Formating to SendMail
Hi there,
I'm new to PERL ,can someone please help me with this one:
I'm trying to send a sort of a columnar report EMail through
sendmail,but the results are anything but columnar!. I tried FORMAT but
that doesn't even output any thing and with 'printf()' it doesn't
display as its counterpart in C , the manual of Perl5 says that 'printf'
is an exact match for C's printf. (please Help)
I'm trying to send something like this:
Column1 Column2
----------------------------------------------
$dummy1 $dummy2
I used : printf (MAIL,"%-40s %10s\n"$dummy1,$dummy2) ;
Thanks in advance
A.Kello
synchro@logos.cy.net
------------------------------
Date: 31 May 1997 23:55:45 GMT
From: Ronald.J.Kimball@dartmouth.edu (Chipmunk)
Subject: Re: *NOT SPAM* Apprentice Perl Hacker, Summer Work Offered
Message-Id: <5mqdq1$ikq$3@dartvax.dartmouth.edu>
In article <338E10A6.41C6@kissel.spicerack.ibm.com>
"Robert S. Kissel" <kissel@kissel.spicerack.ibm.com> writes:
> The location is Westchester
> County, just north of the Tappan Zee bridge.
I suppose most people know where Westchester County and the Tappan Zee
bridge are, but I don't. Would you mind enlightening those of us who
aren't so good at geography?
Chipmunk
------------------------------
Date: 31 May 1997 23:23:44 GMT
From: Ronald.J.Kimball@dartmouth.edu (Chipmunk)
Subject: Re: Bored? Want to evaluate my first (usefull) perl script?
Message-Id: <5mqbu0$l0t$1@dartvax.dartmouth.edu>
In article <338dba08.1305172669@news.michiana.net>
mark@michiana.net (Mark Bainter) writes:
> #!/usr/local/bin/perl5 -T #w removed for release
Why do you remove -w for release? If -w is giving you warning
messages, fix your code so it doesn't. :-)
BTW, is it valid to have a comment on the #! line?
> #
> # dialup -r <username> Remove User from alias
> # dialup -a <username> Add user to alias
> # dialup -v View Alias Listing
> # dialup -c <username> Check if a username exists
> #
> # Version 1.5
> # Created 5/28/97 by Mark Bainter
> # for Turner Group, IN
> #
> # Requires: Perl5, File, and Getopt modules.
> #
> # Planned Improvements:
> # Enable processing list of names, on cmdline or from file.
> # Remove the capability of using RegExps with the -r option.
> #
Good header comments!
> #use strict; # Used for debugging.
Why are you just using it for debugging? You should leave it in!
> use File::Copy; # Used to make a backup.
> use Getopt::Std;
> use vars qw($opt_r $opt_a $opt_h $opt_v $opt_c @alias @time $mod $tmp $rm
> $login $ALIASFILE $NEWFILE);
ALIASFILE and NEWFILE are filehandles. You never use the variables
$ALIASFILE and $NEWFILE.
It appears there are other variables in that list you don't use, as
well.
>
> getopts('r:a:hvc:');
>
> unless ( ($opt_h) || ($opt_r) || ($opt_a) ||
> ($opt_v) || ($opt_c) )
You don't need the extra parentheses around the variables, it just
makes the expression look cluttered.
> {
> $opt_h = 1;
> }
>
> if ($opt_h == 1)
> {
The comparison to 1 is unnecessary, just do: if ($opt_h)
> print "\nSyntax for dialup:\n";
> print "\tdialup -r <username>\tRemove user from alias list.\n";
> print "\tdialup -a <username>\tAdd user to alias list.\n";
> print "\tdialup -v \tView alias list.\n";
> print "\tdialup -c <username>\tCheck if a username is in the list\n";
> print "\n";
Consider using a here document for this.
> exit;
> }
> if ($opt_r ne "")
> {
> &Fill_Array;
> &Parse_Array($opt_r,1);
> &Write_Array;
> }
> if ($opt_a ne "")
> {
> &Fill_Array;
> &Append_Array($opt_a);
> &Write_Array;
> }
> if ($opt_c ne "")
> {
> &Fill_Array;
> &Parse_Array($opt_c,0);
> }
> if ($opt_v == 1)
Again, the comparison to 1 is unnecessary.
> {
> &Fill_Array;
> &Display_Array;
> }
>
>
>
> sub Fill_Array
> {
> $ALIASFILE = "/usr/lib/mail/dialup.list";
> open(ALIASFILE) or die "Cannot open data";
> while ( $tmp = <ALIASFILE> )
This could terminate prematurely if the line evaluates to false.
Do
while (<ALIASFILE>)
and use $_ instead.
> {
> chop($alias[scalar(@alias)]=$tmp);
If you're doing that to remove a trailing newline, use chomp instead of
chop.
> }
> close ALIASFILE;
> }
>
> sub Display_Array
> {
> foreach (@alias)
> {
> print "$_\n";
> }
You could also do it this way:
local($") = "\n";
print "@alias\n";
> }
>
> sub Parse_Array
> {
> my($rmalias,$rm) = @_;
> my(@newlist) = ();
> if ($rm)
> {
> foreach(@alias)
> {
> if($_ !~ /^$rmalias$/)
> {
> $newlist[scalar(@newlist)] = $_;
> }
> }
> @alias = @newlist;
It looks like you're trying to do a grep the hard way.
@alias = grep($_ !~ /^$rmalias$/, @alias);
If you don't want metacharacters in $rmalias to have their special
meanings,
use /^\Q$rmalias\E$/.
> }
> else
> {
> foreach(@alias)
> {
> if ($_ =~ /$rmalias/)
> {
> print "$_ Found!\n";
> }
> }
You could do this with grep too:
print join(" Found!\n", grep(/$rmalias/, @alias)), " Found!\n";
but the way you did it makes more sense in this case. :-)
Again, use /\Q$rmalias/ if you want to avoid metacharacters.
> }
> }
>
> sub Append_Array
> {
> my($newalias) = @_;
> $alias[scalar(@alias)] = $newalias;
> }
>
> sub Write_Array
> {
> #Make a backup copy of the file first!
> $login = getlogin;
> copy("/usr/acct/mark/smw/dialup.list","/usr/acct/mark/smw/dialup.${login}");
It might be better to use variables, and assign the paths at the top of
the program, instead of using hard-coded strings. It would make the
program easier to maintain.
>
> $NEWFILE = ">/usr/lib/mail/dialup.list";
Here too.
> open(NEWFILE) or die("Unable to create file");
> select NEWFILE;
>
> foreach(@alias)
> {
> if ($_ ne "")
> {
> print $_,"\n";
Instead of selecting NEWFILE, you could just do:
print NEWFILE $_,"\n";
This would also work:
print NEWFILE "$_\n";
> }
> }
>
> select STDOUT;
> close STDOUT;
Why do you select STDOUT just to close it?
Now print will print to a closed handle.
Why don't you close NEWFILE?
(Or was that what you meant to do?)
> }
Chipmunk
------------------------------
Date: 31 May 1997 17:20:42 -0700
From: Russ Allbery <rra@stanford.edu>
Subject: Re: Bored? Want to evaluate my first (usefull) perl script?
Message-Id: <m3aflb2mxx.fsf@windlord.Stanford.EDU>
Chipmunk <Ronald.J.Kimball@dartmouth.edu> writes:
> mark@michiana.net (Mark Bainter) writes:
>> #!/usr/local/bin/perl5 -T #w removed for release
> Why do you remove -w for release? If -w is giving you warning messages,
> fix your code so it doesn't. :-)
I think it's a bad idea to use -w on released production code. The next
time a new version of Perl comes out, you're almost guaranteed to get a
bunch of warnings from the script, and for widely deployed scripts this
confuses users. Every script should be checked against the new version of
Perl when it comes out and fixed if necessary, but making the users see
the warnings isn't good.
BTW, how much of a speed penalty do -w and use strict cause?
--
Russ Allbery (rra@stanford.edu) <URL:http://www.eyrie.org/~eagle/>
------------------------------
Date: Sun, 01 Jun 1997 03:36:00 -0300
From: Angelo Kello <kello@technicom.net>
Subject: Columnar Report from CGI to SendMail
Message-Id: <33910A40.79F4@technicom.net>
(URGENT HELP!) Formating to SendMail
Hi there,
I'm new to PERL ,can someone please help me with this one:
I'm trying to send a sort of a columnar report EMail through
sendmail,but the results are anything but columnar!. I tried FORMAT but
that doesn't even output any thing and with 'printf()' it doesn't
display as its counterpart in C , the manual of Perl5 says that 'printf'
is an exact match for C's printf. (please Help)
I'm trying to send something like this:
Column1 Column2
----------------------------------------------
$dummy1 $dummy2
I used : printf (MAIL,"%-40s %10s\n"$dummy1,$dummy2) ;
Thanks in advance
A.Kello
synchro@logos.cy.net
------------------------------
Date: Sat, 31 May 1997 12:36:43 -0600
From: Keys <keys@babylon5fan.com>
Subject: Re: filter out uids below 100
Message-Id: <33906FBB.23E@babylon5fan.com>
Michael Fuhr wrote:
> Consider using getpwent instead of reading the password file. See
> the perlfunc manual page for details.
I am using getpwent... here's the critical section...
while(($login,$passwd,$uid,$gid,$quota,$comment,$gcos,$dir,$shell)=getpwent)
{
($name,$office,$phone)=split(/,/,$gcos);
$username{$login}=$name;
}
for (sort keys %username) {
print "<LI> <A
HREF=\"/bwarden/fingerm?$_\">$username{$_} ($_)<$
if (-r "/home/httpd/html/$_/index.html") {
print "<font size=\"-2\"><A
HREF=\"/$_/\">homepage</A><$
}
}
I thought I could add something like:
for ($uid > 100) {
<code from above>
}
but I am not quite sure how to phrase that... am I on the right track?
The script generates a list of all users (whose names are hyperlinked to
a finger script) and a link to each user's homepage, if it exists...
Thanks...
------------------------------
Date: 1 Jun 1997 02:06:49 GMT
From: 7865nbffy@fia.net
Subject: FRESH Email Addresses
Message-Id: <5mqlfp$3qc@news.hic.net>
6 Million Email Addresses FREE!
Hottest Bulk Stealth Software Available
Send up to 1 MILLION per Hour!
*** FREE 10 Day FULLY Functional Program ***
DOWNLOAD @ http://www.mary-world.com/stealth
Bulk Email Web Space and Email Boxes Available
http://www.mary-world.com/webspace
------------------------------
Date: Sun, 01 Jun 1997 01:50:31 GMT
From: rroberts@gowebway.com
Subject: Re: Good Perl Tutorial with exercises ??
Message-Id: <3390d469.15246321@news.interserv.com>
On Fri, 30 May 1997 15:26:09 -0700, Tom Phoenix
<rootbeer@teleport.com> wrote:
>On Fri, 30 May 1997, Jim Garrison wrote:
>
>> Has anyone written a good Perl tutorial that has
>> well-written, meaningful exercises?
>
>Would you be looking for the Llama book? Oh, you said "meaningful", so
>maybe you meant its second edition. :-) That should be out soon, for
>sufficiantly large values of "soon". But I think you'd be fine with the
>current edition, which has helped at least a few dozen people to learn
>Perl. Or maybe it's a few dozen every week?
>
>-- Tom Phoenix http://www.teleport.com/~rootbeer/
>rootbeer@teleport.com PGP Skribu al mi per Esperanto!
>Randal Schwartz Case: http://www.lightlink.com/fors/
>
I am learnign from that book too, it is pretty good.
But I think that this person wanted one that is more PC based, like
the many HTML tutorials on the net.
Unfortunately I have no idea where one is.
But why dont you look around in this perl page:
http://www.perl.com/perl/index.html
------------------------------
Date: Sat, 31 May 1997 22:08:52 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: Help wanted PERL5.001 -> PERL5.003
Message-Id: <EB2G6s.22I@world.std.com>
pjohan@hal.sparta.lu.se (Johan Palmaeus) writes:
>The problem is
>that in all my script i have to include a module, but when scripts are runned
>the require statement generates an errormessage:
>Can't locate cart_rutiner.cgi in @INC at /usr/www/www-nk2/cgi-bin/cart_write.cgi line 19.
>I try to include a script in the same library and I've tried to change
>PERL5LIB andr PERLLIB enviroment variables for nobody to include current
>library .
Environment variables are not set on a per user basis, but a per
process basis. Each process can add or remove variables from its
process, and each child gets a copy of its parents
environment. Putting them in a file called .profile or something does
little good unless something reads them from that file and sets the
corresponding environment variable.
So if you want to set environment variables for a program, you have to
have them set in the program that spawns them. (and hope that they
don't clear the environment before starting the process.)
Another idea would be to see what the default values of @INC are for
the new version of perl, and put the required file in one of those
directories. Run "perl -V" to find out where this new version of perl
looks for files.
--
Andrew Langmead
------------------------------
Date: Fri, 30 May 1997 18:16:48 GMT
From: "robert c. combs" <xrcc0494@dcaca037.ca.boeing.com>
Subject: Internal data structure of lists
Message-Id: <338F1990.3DA9@dcaca037.ca.boeing.com>
Okay, first a bit of background.
I have a service written in c using sockets that services
various data requests.
The clients talking to the server are perl scripts.
I'd like to respond with perl-understandable lists. But, I'm not
sure of the raw-data structure that the c-program needs to
send through the socket in order for perl to understand:
@list = <SOCKET>;
So the basic question is...
if you did a raw dump of a list that looked like:
['mine', 'yours', 'his'] what would/should it look like?
In general what is the internal data structure for lists and hashes?
I suppose I could clunk around in some header files, but
its not nearly as nifty as posting to a newsgroup...
-bob
------------------------------
Date: Sat, 31 May 1997 20:49:14 -0300
From: Brian Freeze <webmaster@deltastar.nb.ca>
Subject: logging script status to a log file
Message-Id: <3390B8FA.78C4@deltastar.nb.ca>
Greetings
I was wondering how I can log an entire script to a log file such as
cpu state and ram usage throughout the whole script running process in
perl. I have this piece of code that logs to STDERR but I would like it
to log to file and monitor the whole script. Any ideas on how I could do
this?
# Start to log all processes generated from this script.
use GetOpt::Long;
sub warn_trap
{
print STDERR "$0-alpha<", localtime(time), ">$_[0]\n";
}
$SIG{__WARN__}= \&warn_trap;
$P_ERRS = 1;
$P_WARN = 2;
$T_ERRS = 3;
$T_WARN = 4;
$L_INFO = 5;
foreach $bit ($P_ERRS, $P_WARN, $T_ERRS, $T_WARN, $L_INFO)
{
vec($LOGGING, $bit, 1) = 1;
}
warn "P_ERRS Logging active\n" if vec($LOGGING,$P_ERRS,1);
warn "P_WARN logging active\n" if vec(LOGGING,$P_WARN,1);
warn "T_ERRS Logging active\n" if vec(LOGGING,$T_ERRS,1);
warn "T_WARN Logging active\n" if vec(LOGGING,T_WARN,1);
warn "L_INFO Logging vector is", unpack("b*",$LOGGING), "\n"
if vec(LOGGING,$L_INFO,1);
------------------------------
Date: 28 May 1997 19:20:10 -0700
From: mayer@mpactinc.com (Ron Mayer)
Subject: Re: Making a pool, but one man = one vote
Message-Id: <wywwojt3xh.fsf@tonga.mpactinc.com>
cberry@cinenet.net (Craig Berry), <5m2f8h$nkr$1@marina.cinenet.net>:
>David Podeur (podeurda@hpweb.utc.fr) wrote:
>: [...]
>: I have already make the form but what i need know is to be sure
>: that no student can vote twice (or more...).
>: [...]
>
>First, this might better have been addressed to the CGI newsgroup; it's
>not a Perl-specific problem.
Agreed, but there are possible answers specific to perl (see below).
>Second, there is no reliable way to accomplish what you're after in the
>general case other than to ask each student to provide her own username
>when she submits the form, and rely on the honor system. One can pretend
>to do more than this, but each possible method (HTTP data, cookies, and so
>forth) either fails for some clients and/or servers, is subject to trivial
>circumvention, or both.
Isn't "no reliable way" a bit of an overstatement?
.../CPAN/modules/00modlist.long.html
has a section named
"14) Authentication, Security and Encryption (see also Networking)"
which seems to provide the functionality he needs.
>... control what browser ... special features of this particular
>configuration ... HTTP environment variables ... cookies ... user
>can manually delete cookies from her client-side filesystem, and that
>spoofing usernames may not be all that hard either.
I know zip about CGI, so I don't know whether or not the restrictions
imposed by CGI would make authentication as impossible as you say, but
the existance of for-pay services on the net make me suspect the
easily spoofed approaches you mentioned aren't the only thing available.
Surely some sort of digital signature should work, and IMHO for perl
the best place to look is in the CPAN section I mentioned.
Ron
(Or even more trivially, but unrelated to perl, give each student a
unique random number between 1 and ten million and make them include
that number with their vote. As long as you have a secure way of
distributing those numbers the chances of someone voting twice are small.)
------------------------------
Date: 31 May 1997 16:58:22 -0700
From: Russ Allbery <rra@stanford.edu>
To: Doyle Tracy <doyle@teleport.com>
Subject: Re: More PERL questions
Message-Id: <m3enan2nz5.fsf@windlord.Stanford.EDU>
[ Posted and mailed. ]
Doyle Tracy <doyle@teleport.com> writes:
> 1. What are the expression evaluation rules for PERL? What are the
> operator precedences? Is left to right or right to left the direction
> among operators of equal precedence?
See the beginning of man perlop.
> Also, I am looking for an EBNF representation for these rules.
There is none; Perl's grammar isn't context-free.
> 2. Does PERL permit an unconditional branch into the block of statements
> executed under control of a conditional?
Yes. But it's generally considered to be bad programming style.
> 3. What types are permitted for the control expression of a case
> statement?
> 4. How does PERL react when an unspecified choice is evaluated for the
> expression controlling a case statement?
Didn't you read man perlsyn? If you're doing a research project on Perl
and aren't even reading the Perl documentation, that's rather... umm...
lazy of you.
Perl doesn't have case statements. There's an entire section in man
perlsyn about that.
> 5. Does PERL permit unconditional branching into or out of the body of
> an iteration?
Yes.
> 6. What is the value of the ICV (Iteration Control Variable) after the
> completion of an iteration?
Exactly what you'd expect it to be. It depends on your control structure
and your tests. Perl doesn't do anything strange, like make it undefined,
so use your common sense.
> 7. When is the final expression evaluated in a fixed-count iteration?
What's a fixed-count iteration? (Read man perlsyn. You're asking the
wrong questions.)
> 8. Does PERL permit in ICV to be of a real type?
> 9. Does PERL permit an iteration to have multiple exit tests?
> 10. Does PERL permit modification of the ICV in the body of a
> fixed-count iteration?
Read man perlsyn. You're asking the wrong questions. Perl isn't this
hard-nosed about things.
> 11. When is the index of an array checked against its domain type?
> 12. When is the domain of an array bound to the array?
It's not. Perl arrays dynamically grow and shrink. Read man perldata.
> 13. What types are permitted for the domain of an array?
Integers.
> 14. What types are permitted for the range of an array?
Anything.
> 15. Is array assignment permitted? How are arrays with different
> domains and the same cardinality handled?
No such thing. Read man perldata.
> 16. Is ordering defined in arrays? If so, how?
It's defined precisely how you'd expect it to be defined. Read man
perldata.
> 17. Is there a maximum length enforced on strings?
No.
> 18. If PERL has varient records, is the discriminant selection enforced?
> Is assinment permitted to components not currently activated by the
> discriminant?
Perl doesn't have records. Perl has a variety of other things. Read man
perldata.
> I realize there are alot of questions here. And I appreciate the
> patience everyone has with me. I've looked high and low for a book to
> find these answers in but I can only find books on programming PERL, not
> the specifics of the language.
This sounds good, but you've apparently not even looked at the
documentation that *comes* with Perl, so I find your statements rather
unlikely. You've apparently also not even done a web search on Perl,
which would have led you to http://www.perl.com/perl/ and the online HTML
version of all of the documentation, along with the FAQ.
If this is a research project, I'm frankly somewhat unimpressed by your
research skills. Hopefully all the pointers above will help you track
down the documentation you should have been looking at *first*, and then
I'm sure the readers of this group will be happy to clarify anything that
remains unanswered.
> In addition to these specific questions, I'm also looking for a little
> history on the language such as what platform was is designed for?
The introduction to Programming Perl, which should be available at any
good bookstore, has a lot of this information.
--
Russ Allbery (rra@stanford.edu) <URL:http://www.eyrie.org/~eagle/>
------------------------------
Date: Sat, 31 May 1997 22:35:57 -0400
From: Tom Oelke <tpo9617@rit.edu>
Subject: New FAQ question? Decimal -> Binary conversion
Message-Id: <5mqn2l$mb4$1@node2.frontiernet.net>
I've seen 3 separate threads (including my own) about doing
decimal / number conversion from decimal or hex string etc. to
output in binary form.
I'd suggest having this as a new FAQ question, as I couldn't find it in
the
FAQ when I was looking.
I have a few different methods that were suggested to me that I would be
happy
to repost or mail to the FAQ maintainer if requested.
(Or Tom C. could probably do a FMTEYWTK on this alone. :)
Tom Oelke
tpo9617@rit.edu
------------------------------
Date: 31 May 1997 23:44:02 GMT
From: Ronald.J.Kimball@dartmouth.edu (Chipmunk)
Subject: Re: Perl poems?
Message-Id: <5mqd42$ikq$1@dartvax.dartmouth.edu>
In article <5mn1du$hbr$1@canopus.cc.umanitoba.ca>
rahard@wine.ee.umanitoba.ca (Budi Rahardjo) writes:
> Long time ago I received the following perl script.
> It was runnable (with perl4). Some sort of animation ;-)
> Unfortunately it doesn't work with perl5.
> I don't know how to get in contact with the author.
> Any quick fix?
Here is a fixed version.
I changed two things:
First, in line 37, the second argument to read() needs to be a
variable, so references is now $references.
Second, in line 68, the word and is a keyword in perl5, so and is now
'and'.
Chipmunk
#!/usr/local/bin/perl
# Ode to My Thesis, a Perl Poem
<<birth
;
G
r
o
w
t
h
re-
birth
seek
(
enlightenment, knowledge, experience
);
goto MIT;
sleep "too little", study $a_lot,
wait, then
.
"B.S.",
leave. then, return to
;
MIT
:
now,
$done = 'a Ph.D.
">&2';
warn pop @mom, " I'll be here a while
\n";
study, study, do study;
push
(
myself, computers, experiments
),
read
(
data, $references, books
),
study,
write,
write,
write,
do more if time
;
redo if $errors
;
do more_work if questions_remain
;
$all_are_answered? yes.
now :
write,
chop if length $too_great
;
format
=
Thesis
.
tell all,
done, finally
.
now, do rest
.
shout.
'and'
.
hear
.
it
.
`echo
"
Now I am $done`
# Craig Counterman
# April 27, 1991
# Modified to work with perl5 by Ronald J. Kimball
------------------------------
Date: 31 May 1997 23:53:55 GMT
From: Ronald.J.Kimball@dartmouth.edu (Chipmunk)
Subject: Re: printf padding ...
Message-Id: <5mqdmj$ikq$2@dartvax.dartmouth.edu>
In article <000035250000332C@nashville.com>
christopher.greenup@nashville.com (Christopher Greenup) writes:
> The Camel Book mentions that printf "typically" pads strings too short for
> the format with the necessary number of spaces. Sooo ... how does one pad
> with something besides spaces (or zeros)?
Well my Camel book says:
printf
...
See print and sprintf. The descroption of sprintf includes the list of
acceptable format specifications.
...
sprintf
...
The various combinations are fully documented in the manual page for
printf(3)...
So, I'd suggest typing
man 3 printf
at your friendly neighborhood Unix prompt.
Chipmunk
------------------------------
Date: Thu, 29 May 1997 21:13:51 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: Slices of lists
Message-Id: <EAyoB3.C4n@bcstec.ca.boeing.com>
In article <339671cd.18396087@news.geccs.gecm.com>,
Brian Orpin <brian.orpin@gecmX.com> wrote:
> As a newcomer to Perl I have hit my first (apparently) insurmountable
> problem which on line help (The downloaded HTML man pages are broken
> but that's another thread) hasn't and is beyond 'Learning Perl' (what
> a great starter).
>
> I wish to replace a slice of an array.
>
> I used a grep to find if the item (string) exists in the array but
> could not find a function to tell me it's position other than by going
> through the array and incrementing a counter. Is there a better way?
Presuming your array is well behaved as far as start,end
item uniqueness, you could at least reduce the searches to
a couple of short one-liners:
$start++,$end++ until $old[$start] eq "start_string";
$end++ until $old[$end] eq "end_string";
>
> So I can find the start and end points of the slice I want to remove.
>
> @new = @old[$start..$end];
>
> However, how do I replace the slice with a different array e.g. or
> even delete those elements I have identified.
>
> @old = ("one", "two", "three");
> @new = ("twoa", "twob");
>
> to get an array ("one", "twoa", "twob", "three")
>
Then, you could just splice in the replacement:
splice(@old,$start,$end-$start+1,@new);
HTH,
--
Charles DeRykus
ced@carios2.ca.boeing.com
------------------------------
Date: Fri, 30 May 1997 20:42:20 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: Socket reading
Message-Id: <EB0HIL.4nu@bcstec.ca.boeing.com>
In article <naked-ya02408000R2905971940060001@news.sci.fi>,
Nuutti Kotivuori <naked@paivola.sci.fi> wrote:
>Ok... I have this problem. I have a socket that I want to read line by
>line... just one line at a time, but I can't just use <FILEHANDLE> because
>I need to get back to my program every second on the second. The more
>accurate the timing is the better. I looked up sirc:s sources and it has a
>buffer in wich it reads data and takes it line by line from there and
>selects the inputs. Is there a better way?
Hm, could you set an alarm, e.g,
my $alarm = "1 second alarm";
$SIG{ALRM} = sub { die $alarm };
READ: {
alarm 1;
eval { $read = <FILEHANDLE> };
if ($@ =~ /^$alarm/) {
.... # handle something in the program
} elsif ($@) { # unexpected error
die "unexpected eval error: $@";
} else { # beat alarm
alarm(0); # turn off alarm
.... # handle line read
redo READ; # or whatever...
}
}
HTH,
--
Charles DeRykus
ced@carios2.ca.boeing.com
------------------------------
Date: Thu, 29 May 1997 17:39:19 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: What does main' in sub main'routine do?
Message-Id: <EAyEDK.Kvr@bcstec.ca.boeing.com>
In article <5mj5u1$8sv@delphi.cs.ucla.edu>,
Dinh Le <dinh@yi.cs.ucla.edu> wrote:
>
>I am trying to debug a perl program that declared a subroutine as:
>
> sub main'routine {
> <BODY>
> }
>
>In a different file, the subroutine main'routine is referred to
>as &routine. Can someone tell me the purpose behind the prefix
>main'?
>
To force that subroutine into main. Otherwise, if that subroutine
definition were in the scope of a different package, say
package Other, you'd had to say &Other'routine or &Other::routine.
Also, the main' is a package qualifier more modernly written as
main:: but, since main is the default package, this could be
shortened to 'routine or ::routine.
Take a look at perlmod in the man pages or Chapter 5 in the
blue Camel.
HTH,
--
Charles DeRykus
ced@carios2.ca.boeing.com
------------------------------
Date: 31 May 1997 23:55:38 GMT
From: shaug@callamer.com (O'Shaughnessy Evans)
Subject: Re: What's perl equivalent to awk's $1, $2, etc.?
Message-Id: <5mqdpq$9ic$1@zinger.callamer.com>
In article <33907DAA.3B60@indiana.edu>,
"D.F. Parkhurst" <parkhurs@indiana.edu> writes:
...
> I have three books on perl, but can't find concepts like "field" or
> "parsing" in the index of any of them. Is there an equivalent concept
> to $1 (etc.) in perl, and if so, what is it called?
>
> Thanks for any enlightenment.
>
> Dave Parkhurst
If you have the newest version of "Programming Perl", check out the Awk
Traps section starting at p. 530 -- it describes some issues you might want
to be aware of when switching from awk to Perl. As far as splitting up
the lines of a file goes, try something straightforward like this to get a
feel for how split() works:
#!/bin/perl -w
while ($in = <>) {
@fields = split(' ', $in);
for ($i=0; $fields[$i]; $i++) {
print "$i: $fields[$i]\n";
}
print "\n";
}
--
- O'Shaughnessy Evans
- UNIX/Internet Systems Administrator, GST Call America; SLO, Ca
- "I'm about to write you a reality check..." -- The Tick
------------------------------
Date: Sat, 31 May 1997 17:43:20 -0700
From: Michael Schilli <mschilli@blacksun.com>
Subject: while(<>) and perl -e: B.. or feature?
Message-Id: <3390C5A8.260A@blacksun.com>
Hi,
I wonder why
perl -e 'while(<>) {...}'
doesn't process file names from the command line just as
#!/usr/bin/perl
while(<>) { ...
}
does but instead insists on input from STDIN. Any ideas?
--
Michael
------------------------------
Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.misc (and this Digest), send your
article to perl-users@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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 V8 Issue 551
*************************************