[7865] in Perl-Users-Digest
Perl-Users Digest, Issue: 1489 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Dec 17 16:18:05 1997
Date: Wed, 17 Dec 97 13:00:29 -0800
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, 17 Dec 1997 Volume: 8 Number: 1489
Today's topics:
Re: 6 elementary questions (Abigail)
A question for perl MASTERS not newbies <dafydd@gwe.co.uk>
Re: A question for perl MASTERS not newbies (brian d foy)
Re: Access Log <xxTony.Curtis@vcpc.univie.ac.at>
ANNOUNCE: C++/Perl to LaTeX converter (Chris Traxler)
Re: ANNOUNCE: Clean Feed 0.95, and new nnrp filter patc john@raleigh.ibm.com
Re: Beginner with a ? <rootbeer@teleport.com>
Re: foreach && references <ebohlman@netcom.com>
Re: Framework for building custom HTTP servers? <aas@sn.no>
Re: Framework for building custom HTTP servers? <merlyn@stonehenge.com>
help with hash error <nowick@awinc.com>
Re: help with hash error (Honza Pazdziora)
Re: HELP! How to use records in Perl? (Stephen P. Clouse)
HELP:Extension of Sybase::DBlib::DateTime package thru <pdcruz@japan.ml.com>
Re: How to base64 encode a file (brian d foy)
Re: How to base64 encode a file <eryq@zeegee.com>
Re: how to clear terminal screen <tchrist@mox.perl.com>
Re: How to get everything in between <pre>....</pre> ta <gary@ashton-jones.com.au>
Re: How to get everything in between <pre>....</pre> ta (Frank)
http socket programming G.Hood@iaea.org
Re: localtime() _is_ year-2000 compliant, right? (Michael Budash)
Re: localtime() _is_ year-2000 compliant, right? (M.J.T. Guy)
Re: LWP for Windows (Nathan V. Patwardhan)
Re: missing socket.ph (Honza Pazdziora)
Re: NEED: Fast, Fast string trim() <matkin@Owein.DoCS.UU.SE>
Re: newbie file input question <ebd@sunline.net>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 17 Dec 1997 18:52:37 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: 6 elementary questions
Message-Id: <slrn69g7uu.50c.abigail@betelgeuse.wayne.fnx.com>
Xah (xah@best.com) wrote on 1569 September 1993 in
<URL: news:678csr$75s$1@nntp1.ba.best.com>:
++
++ # Question: How to explicitly force a conversion between number and string?
++ (if there's way.)
$num = $string + 0;
$string = "$num";
But you very seldom need that.
++ # Question: Why does the following returns 4 and 5, not all 5?
++
++ @array = (0 .. 9);
++ %hash = @array;
++ print 0 + %hash, "\n";
++ print 0 + keys(%hash), "\n";
Because they mean something totally different!
Observe:
$ perl -wle '@array = (0 .. 9); %hash = @array; print scalar %hash'
4/8
Evaluating a hash in scalar context gives you a string with the number of
touched buckets and the total number of buckets in your hash, separated
by a slash. Now, if you try to use "4/8" as a number, perl treats it as 4,
giving you the answer of 4.
++ # Question: in the following code, it seems that the second argument of
++ foreach is automatically converted into an array. Is this behavior somewhere
++ in man page?
++
++ while (<>) {
++ foreach $word (m/(\w+)/g) {
++ # do something with $word here
++ }
++ }
Yes, it's in perlop, where m//g is described.
++ # Question: explain the behavior of the following code. i.e. What is the
++ context of @a in print and when is a separator added automatically?
++
++ @a = (1 .. 10);
++ print "@a\n";
++ print @a;
In both cases a separator is added. But not the same. $" is used when
stringifying an array, $, when printing. See perlvar.
++ # Question: Why the following two versions of code differ? one prints just
++ one line, the other prints the whole file.
++
++ print <FILE>;
++
++ $line = <FILE>;
++ print $line;
Context. In print <FILE>; <FILE> is evaluated in list context,
but it is evaluated in scalar context in $line = <FILE>;
++ # Question: Suppose I want to split a string, and get the second element,
++ split it again and get the last element. What's the appropriate perl style
++ code? For example, $str = 'GET /~xah/Curves_dir/Spc.html HTTP/1.0', and I
++ want to split it by a space, then split the second element by a slash, then
++ taking the last element 'Spc.html' as result.
++
++ If I'm working with a functional language, then I can nest them something
++ like
++
++ (split(m@/@, (split(m@ @, $str))[2]))[-1]
++
++ but such code doesn't work in perl. I could write a series of assignments,
++ but I'm looking for a good perl style code.
$var = (split m{/}, (split / /, $str) [1]) [-1];
Works for me.
Abigail
--
perl -wle 'print "Prime" if (1 x shift) !~ /^1?$|^(11+?)\1+$/'
------------------------------
Date: Wed, 17 Dec 1997 16:54:24 GMT
From: "Dafydd Richards" <dafydd@gwe.co.uk>
Subject: A question for perl MASTERS not newbies
Message-Id: <01bbeb5a$55bacc70$0801010a@carnedd>
An example of what I did in perl 5.003
use sigtrap;
$SIG{ALRM}=\&timeup;
...
...
...
...
alarm 3;
cond=1;
while($cond==1) {
read(FILE,$buffer,200);
}
sub timeup {$cond=0}
The point of doing this is that after 3 seconds the alarm breaks the read
and jumps into the loop again with $cond=0 and therefore breaks the loop.
In perl version 5.004 the function 'timeup' seems to return to the 'read'.
Is there anyway in perl 5.004 of breaking the wait on 'read' after a set
time???
Before people start telling me about EOF and all that, I'm not reading a
normal file, it may be a named pipe, or a device etc, even a socket.
Dafydd Richards
------------------------------
Date: Wed, 17 Dec 1997 12:33:23 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: A question for perl MASTERS not newbies
Message-Id: <comdog-ya02408000R1712971233230001@news.panix.com>
In article <01bbeb5a$55bacc70$0801010a@carnedd>, "Dafydd Richards" <dafydd@gwe.co.uk> wrote:
>An example of what I did in perl 5.003
>
>use sigtrap;
>$SIG{ALRM}=\&timeup;
>...
>alarm 3;
>cond=1;
>while($cond==1) {
>read(FILE,$buffer,200);
>}
>sub timeup {$cond=0}
>In perl version 5.004 the function 'timeup' seems to return to the 'read'.
>Is there anyway in perl 5.004 of breaking the wait on 'read' after a set
>time???
perhaps you want your subroutine to return to a specific place? this
works for me in 5.004_01:
#!/usr/bin/perl -w
use strict;
use sigtrap;
use vars qw($test);
#close your eyes - it gets a bit scary.
$SIG{'ALRM'} = sub { local $^W = 0; $test = 0; next LOOP };
#okay, you can open them now. you didn't see anything
#resembling a goto. repeat after me... ;)
$test = 1;
LOOP: while( $test == 1 )
{
alarm 3;
read STDIN, $_, 5;
print;
alarm 0
}
exit(0);
__END__
--
brian d foy <comdog@computerdog.com>
NY.pm - New York Perl M((o|u)ngers|aniacs)* <URL:http://ny.pm.org/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
------------------------------
Date: 17 Dec 1997 11:13:59 +0100
From: Remove xx <xxTony.Curtis@vcpc.univie.ac.at>
To: hvanlint@lodestar.be
Subject: Re: Access Log
Message-Id: <7xen3ctgyg.fsf@vcpc.univie.ac.at>
Re: Access Log, Hans <hvanlint@lodestar.be> said:
Hans> I get the following error: ../logs/access_log:
Hans> Permission denied
Hans> But I'm sure access_log can be read by everyone:
Hans> -rw-r--r-- (owner peabody - if I was the owner it
Hans> would be dbintein)
Hans> And when I try to read it with joe access_log it
Hans> works!
Hans> Why can't perl read it with open();??
It's probably the directory (or parent) which can't be
accessed.
I assume from your description that the perl script is
actually a CGI? In this case of course, it is probably
running as user "nobody" - and this user may not have
permission to get down the directories to the access_log.
hth,
tony
------------------------------
Date: 17 Dec 1997 13:26:30 GMT
From: christoph.t.traxler@theo.physik.uni-giessen.de (Chris Traxler)
Subject: ANNOUNCE: C++/Perl to LaTeX converter
Message-Id: <678ju6$ukc@c4.hrz.uni-giessen.de>
I'd like to make an announcement of a C++/Perl->LaTeX
converter (that produces beautiful program listings).
It has many configurable features that allow you to use
LaTeX formulas and even include EPS pictures in program comments.
You can download the script at
ftp://krabat.physik.uni-giessen.de/pub/traxler/listing.tgz
Try it! (to see its main features, try it on itself). You'll love it.
To use all of its features, you need LaTeX (with makeindex and psfig),
dvips, xdvi, and psnup running on your system. And, of course, Perl.
Uh, I should not forget to mention that this software is still beta.
Regards,
Chris
work: Theor. Physik, Raum 314, Heinr.-Buff-Ring 16, D-35392 Giessen,
0641/7022802. home: Ammerweg 3, D-35435 Wettenberg, 0641/9805921
----
"What's nice with GUI is that you see what you manipulate, but
what's bad about GUI is that you can only manipulate what you see."
------------------------------
Date: Wed, 17 Dec 1997 11:19:41 -0500
From: john@raleigh.ibm.com
Subject: Re: ANNOUNCE: Clean Feed 0.95, and new nnrp filter patch
Message-Id: <3497FB9D.5C1C@raleigh.ibm.com>
Reposting into 2 more likely groups...
john@raleigh.ibm.com wrote:
>
> Piers Cawley wrote:
> > I've been messing with one of the precursors of this and, whilst I'm
> > sure that the spam detection is reasonably good, I'm more than a
> > little worried about it catching false positives and wanted to add a
> > checksum of the message body to make sure.
> >
> > To that end I've been messing with lib/perl.c and config.data so that
> > you can now use dynamically loaded modules. As well as applying the
> > patch you'll also have to fiddle with PERL_LIB in config.data.
>
> Has anyone managed to get this working under AIX? perl 5.004_04,
> MD5 works OK from the command line, but seg-faults under both INN and
> a patched interp.c from perlembed.pod.
--
John Payne | VM: JOHN at RTP
IBM Global Services NS | email: john@raleigh.ibm.com
OpenNet Services (EMEA) | Intranet http://w3.irc.ibm.com/jpayne
------------------------------
Date: Tue, 16 Dec 1997 23:02:57 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: "Diran A." <entrpneur@earthlink.net>
Subject: Re: Beginner with a ?
Message-Id: <Pine.GSO.3.96.971216225900.19797J-100000@user2.teleport.com>
On Tue, 16 Dec 1997, Diran A. wrote:
> Subject: Beginner with a ?
Please check out this helpful information on choosing good subject
lines. It will be a big help to you in making it more likely that your
requests will be answered.
http://www.perl.com/CPAN/authors/Dean_Roehrich/subjects.post
> I'm writing perl scripts on my NT server. They seem to run fine with
> all the web browsers that I use, except Microsoft Internet Explorer
> 4.0.
If you're following the standards, the bug is in IE. If you're not
following the standards, the bug is in your code. If you haven't read the
standards, you should. If you've read the standards, but you're still not
sure, then you may ask in a newsgroup about the protocol you're using.
(Probably HTTP, but maybe CGI, HTML, or something else. Almost always, the
newsgroup's name includes the name of the protocol. There's no protocol
named 'perl'. :-)
Hope this helps!
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
Ask me about Perl trainings!
------------------------------
Date: Wed, 17 Dec 1997 08:46:11 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: foreach && references
Message-Id: <ebohlmanELBsCz.M6r@netcom.com>
Ken Holm <rets@meta3.com> wrote:
: print "[@{$c{test}}]\n\n"; # help
: foreach $d (@{$c{test}}) { # help
: I am still going through the Panther (Advanced Perl Programming). It
: explains complex data structures, which the above appears to be.
: Perhaps you get something out of this.
>From p.249 of the Camel: "The dereferencing of the scalar variable
happens before any array or hash lookups."
IOW, "@$c{test}" is interpreted as "take whatever is in the scalar $c and
treat it as a reference to an array. Then index this array by {test}."
Of course, that won't work (there's no scalar called $c and an array
can't be subscripted with braces).
The actual place where the reference is stored is in the test'th element
of the hash %c. We need to get it out of there before we can do anything
else, so we need to write some code to do that and then tell Perl that we
want to get the array referred to by the reference. The general way of
doing this is to write "@{block of code that gives reference}" so in this
case we write "@{$c{test}}."
The thing that's confusing to beginners here is that {something} has two
different meanings in Perl, depending on where it occurs. In our case,
the outer pair of braces means "inside me is a block that returns a
value" but the inner pair means "inside me is the key to the hash that
was named before me."
------------------------------
Date: 17 Dec 1997 09:04:36 +0100
From: Gisle Aas <aas@sn.no>
Subject: Re: Framework for building custom HTTP servers?
Message-Id: <m3lnxkxunf.fsf@furu.g.aas.no>
Dave Sill <dsill@sws5.ctd.ornl.gov> writes:
> Is there a module or recipe for creating small special-purpose HTTP
> servers in perl?
The HTTP::Daemon class that comes with libwww-perl should be a good
starting point.
--
Gisle Aas
------------------------------
Date: 17 Dec 1997 06:13:54 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: Gisle Aas <aas@sn.no>
Subject: Re: Framework for building custom HTTP servers?
Message-Id: <8chg88w1rh.fsf@gadget.cscaper.com>
>>>>> "Gisle" == Gisle Aas <aas@sn.no> writes:
Gisle> Dave Sill <dsill@sws5.ctd.ornl.gov> writes:
>> Is there a module or recipe for creating small special-purpose HTTP
>> servers in perl?
Gisle> The HTTP::Daemon class that comes with libwww-perl should be a good
Gisle> starting point.
And in fact, I've already illustrated that class in one of my
well-received Web Techniques Perl columns, archived online at:
http://www.stonehenge.com/merlyn/WebTechniques/
Look for "anonymous proxy server". The column I just submitted
(appearing in a few months both online and in print) shows another
use of this very handy class. (Thanks, Gisle!)
print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,990.69 collected, $186,159.85 spent; just 258 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details
--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@ora.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me
------------------------------
Date: Wed, 17 Dec 1997 01:12:54 +0800
From: Nowick Gray <nowick@awinc.com>
Subject: help with hash error
Message-Id: <3496B696.78A6@awinc.com>
Hello,
I have a strange problem appearing with a cgi script I've used without
problems at my website...suddenly the form response in the browser
window gives the following error message:
"Odd number of elements in hash list at /home/cougarww/cgi-bin/swift.cgi
line 110..."
It goes on to name the "chunks," 1-20, with the error message repeated
each time (except for chunk 10). Interspersed in the error lines are
the lines that are supposed to appear, from my send.htm page.
I'm afraid to say I know next to nothing about cgi scripts. I plugged
this one in to my website and it worked, now it doesn't. I tried
recopying the original to my website and still get the same error now.
Any ideas?
If I knew which line was 110 I would quote it here.
The script tested okay for syntax both with the perl -c command via
Telnet and with the automatic script checker at my web server.
Advice or explanation would be appreciated! Please reply by e-mail.
--
Nowick Gray
mailto:nowick@awinc.com
Cougar WebWorks--a webzine of alternatives
http://www.he.net/~cougarww/
------------------------------
Date: Wed, 17 Dec 1997 09:49:10 GMT
From: adelton@fi.muni.cz (Honza Pazdziora)
Subject: Re: help with hash error
Message-Id: <adelton.882352150@aisa.fi.muni.cz>
Nowick Gray <nowick@awinc.com> writes:
[...]
> If I knew which line was 110 I would quote it here.
In vi, you do it ESC 110 G.
You probably assign array to hash somewhere and the array seems to
have odd number of elements, which is not a good thing for hash. So
you should change the code to come out with even number of elements in
the array.
Hope this helps,
--
------------------------------------------------------------------------
Honza Pazdziora | adelton@fi.muni.cz | http://www.fi.muni.cz/~adelton/
I can take or leave it if I please
------------------------------------------------------------------------
------------------------------
Date: Wed, 17 Dec 1997 05:14:56 GMT
From: stephenc@granddesign.com (Stephen P. Clouse)
Subject: Re: HELP! How to use records in Perl?
Message-Id: <349a5ca9.20153782@news.kc.net>
Hash: SHA1
On Wed, 17 Dec 1997 11:30:02 +0800 in message <<677h06$o1d$1@enyo.uwa.edu.au>
comp.lang.perl.misc>, "Greg Roberts" <gregr@ee.uwa.edu.au> wrote:
>Hi. I'm having some trouble at the moment trying to emulate a Pascal record
>structure in Perl. What I want is something like this:
>
>machine_record {
> hostname,
> IP,
> group,
> traffic,
> cost
>}
>
>So for machine X, I want to be able to go:
>
> machine_record(X).hostname = "wahey";
I'd say you're looking to build a complex data structure. Assuming that you
want a hash of named machine records, it'd look something like this:
Say we'll add a record for my Linux boxen, mercury.granddesign.com. We'll call
its record mercury.
$machine_record{'mercury'}->{'hostname'} = "mercury.granddesign.com";
$machine_record{'mercury'}->{'IP'} = "207.239.192.128";
$machine_record{'mercury'}->{'group'} = "GDI";
$machine_record{'mercury'}->{'traffic'} = "Not a whole lot :)";
$machine_record{'mercury'}->{'cost'} = "A few thousand bucks";
So this creates a hash %machine_record with a key called "mercury" and the value
being a reference to another anonymous hash with the five data keys inside. To
match up to your example, I'd use:
$machine_record{'X'}->{'hostname'} = "wahey";
And then you can extract that data back out by just using
$machine_record{'X'}->{'hostname'}. In a print command you'd have to separate
the data access call from the string (Perl doesn't seem to like interpreting the
dereference arrow inside a string), so you'd use something like:
print "Hostname: ", $machine_record{'X'}->{'hostname'}, "\n";
print "IP: ", $machine_record{'X'}->{'IP'}, "\n";
etc.
And you could easily write a subroutine or an object to handle all of this.
Of course, I'm trying to give you as good an answer as possible without
reinventing the wheel...this is all covered in perldoc perldsc. It's got lots
of other weird nested data structures that you may want to look at as well.
- --
Stephen P. Clouse
stephenc@granddesign.com -- steve@warpcore.org -- UIN 135012
Grand Design, Inc. (http://www.granddesign.com) -- Quality Business Web Design
The Warp Core (http://www.warpcore.org) -- The Web's Premier Descent Site
PGP-Encrypted E-Mail Preferred (Key available at www.granddesign.com/~stephenc)
Fight Spam/UCE -- http://www.cauce.org
Version: PGP for Business Security 5.5
iQA/AwUBNJdfymOLD55Fj/ZkEQLrNACgorg/BJnjDxPQc2ccQpJZ/Sirg/oAoOWc
zPTiU2u1ntccXxpILmCoitZ/
=RGmb
-----END PGP SIGNATURE-----
This article was posted from <A HREF="http://www.slurp.net/">Slurp Net</A>.
------------------------------
Date: Wed, 17 Dec 1997 15:32:31 -0800
From: D'Cruz Prem <pdcruz@japan.ml.com>
Subject: HELP:Extension of Sybase::DBlib::DateTime package thru Inheritance.
Message-Id: <3498610F.1139@japan.ml.com>
I'm trying to extend the Sybase::DBlib::DateTime package available
as an extension in "DBlib.pm" at site-perl/Sybase, to provide
a method to return date as a string in different formats viz.
"D/M/Y", "YYYYMMDD" etc. In order to do that I have written a package
SybDate.pm which is inherited from the base class
"Sybase::Dblib::DateTime" via the ISA mechanism in perl5. The create
method in this package makes a call to "newdate()" method in the base
class which returns a Sybase::DBlib::DateTime object that is blessed
as SybDate and returned, however when the "withFormat" method
invokes "crack()" perl5 gives an error "Invalid valp". I have
included the code below and any suggestions to do this in a clean
way would be highly appreciated.
Cheers
Prem
SybDate.pm
---------------------------------------------------------------
#
------------------------------------------------------------------------------
package SybDate;
# imports
----------------------------------------------------------------------
use Sybase::DBlib;
use Exporter;
@ISA = qw(Sybase::DBlib::DateTime );
# package globals
--------------------------------------------------------------
@months = (Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec);
@week = (Sun, Mon, Tue, Wed, Thu, Fri, Sat);
use vars qw( @months, @week );
#
------------------------------------------------------------------------------
# Interface/Implementation
-----------------------------------------------------
#
------------------------------------------------------------------------------
sub withFormat
{
my ( $self, $format, $date );
my ( $class, %dateArr, @formatStr, $dateAsString, $char );
$self = shift;
$format = shift;
$class = ref($self) || $self;
@formatStr = split(//,$format);
($dateArr{'Y'}, $dateArr{'M'}, $dateArr{'D'}, $dateArr{'y'},
$dateArr{'w'},
$dateArr{'h'}, $dateArr{'m'}, $dateArr{'s'}, $dateArr{'i'},
$dateArr{'z'}
) = crack();
$dateArr{'M'}++;
foreach $char ( @formatStr )
{
if (( $dateArr{$char} eq "" )
&& ( $char ne "O" ) && ( $char ne "O" ))
{
$dateAsString .= $char;
}
elsif ( $char eq "O" )
{
$dateAsString .= $months[$dateArr{'M'} - 1];
}
elsif ( $char eq "w" )
{
$dateAsString .= $week[$dateArr{'w'}];
}
else
{
$dateAsString .= sprintf("%02d", $dateArr{$char});
}
}
return $dateAsString;
}
#
------------------------------------------------------------------------------
#
------------------------------------------------------------------------------
sub create
# returns SybDate object with date/time as passed in dateAsString
parameter.
{
my ( $self, $dateAsString );
my ( $app, $dbProc, $date, $class );
$self = shift;
$class = ref($self) || $self;
$dateAsString = shift;
$dbProc = new Sybase::DBlib "cobra","hiss","MODZILLA","TestApp";
$date = $dbProc->newdate($dateAsString);
bless($date, $class);
return $date;
}
#
------------------------------------------------------------------------------
use SybDate;
$date = SybDate->create("Jan 1, 1900");
$date->withFormat("M-Y-D");
------------------------------
Date: Wed, 17 Dec 1997 02:37:50 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: How to base64 encode a file
Message-Id: <comdog-ya02408000R1712970237500001@news.panix.com>
In article <34972ACE.6EA9@aol.com>, TheGayCafe@aol.com wrote:
>I'd like to know how to convert an open file to base64 ASCII encoding.
have you seen the MIME::Base64 module?
--
brian d foy <comdog@computerdog.com>
NY.pm - New York Perl M((o|u)ngers|aniacs)* <URL:http://ny.pm.org/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
------------------------------
Date: Wed, 17 Dec 1997 13:04:53 -0500
From: Eryq <eryq@zeegee.com>
To: TheGayCafe@aol.com
Subject: Re: How to base64 encode a file
Message-Id: <34981445.32D9@zeegee.com>
Gay Cafe wrote:
>
> I'd like to know how to convert an open file to base64 ASCII encoding.
>
> I get the feeling that this is ridiculiously simple, but I tend to make
> these things difficult, so I thought I'd make use of UseNet and ask.
Use MIME::Base64 if you want to have a lot of control
over the process. Or...
If you're sending email and want to do binary attachments,
look at MIME::Lite; much of the work is done for you, and
you can generate entire messages with one Perl command.
However, this module currently likes to process files,
not filehandles.
Hope that helps,
--
___ _ _ _ _ ___ _ Eryq (eryq@zeegee.com)
/ _ \| '_| | | |/ _ ' / President, Zero G Inc.
| __/| | | |_| | |_| | "Talk is cheap. Let's build." - Red Green.
\___||_| \__, |\__, |___/\ Visit STREETWISE, Chicago's newspaper by/
|___/ |______/ of the homeless: http://www.streetwise.org
------------------------------
Date: 17 Dec 1997 15:09:24 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: how to clear terminal screen
Message-Id: <678pv4$oam$1@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
clay@panix.com (Clay Irving) writes:
:Tony Sanders and Term::Cap don't appear in CPAN anymore.
I think because it's now standard.
--tom
--
Tom Christiansen tchrist@jhereg.perl.com
Real programmers can write assembly code in any language. :-)
--Larry Wall in <8571@jpl-devvax.JPL.NASA.GOV>
------------------------------
Date: Wed, 17 Dec 1997 20:19:57 +1100
From: Gary Ashton-Jones <gary@ashton-jones.com.au>
Subject: Re: How to get everything in between <pre>....</pre> tags in html
Message-Id: <3497993D.1F7C66B0@ashton-jones.com.au>
Michael Budash wrote:
> In article <343E8927.26E1@nt.com>, Daniel Lortie <dlortie@nt.com>
> wrote:
> >>
> >> I have an HTML file that I read from the internet, but I want
> >> to parse the file I receive to only keep the text between the
> >> <pre> and </pre> tags. Is there a quick way to do this?
> >>
>
> If you've only got one such occuring pair of <pre>'s, this should do
> it:
>
> open (FILENAME) or die("oops!"); # open the file (duh!)
> @lines = <FILENAME>; # get all the records at once
> close (FILENAME); # close the file
> $lines = join ('', @lines); # make one big scalar
> $lines = lc($lines); # make it lower case
> $tokeep = $1 if ($lines =~/<pre>(.*)<\/pre>/); # find the pair and
> only
> save what's between 'em
>
> You get to keep any newlines...
>
> If there's more than one pair of <pre>'s, it' be harder, considering
> the
> possibilites of things like:
>
> <pre>Here's some pre-text
> and some more.</pre><hr><pre>Here's some more pre-text without
> starting
> a new line.
> Darn! That makes it harder...</pre>
>
Use a 'greedy search' qualifier to find the first of multiple
occurences e.g.
$tokeep = $1 if ($lines =~/<pre>(.*?)<\/pre>/); # find the pair and
only
(Note the question mark (?). It causes the RE engine to return the
shortest match.)
Or put the pattern match inside a loop to process all the occurrences
e.g.:
while ($lines =~ s/<pre>(.*?)<\/pre>//) { #removes one occurrence each
pass through the loop
print $1; #or whatever you want to do
}
------------------------------
Date: Wed, 17 Dec 1997 18:51:30 GMT
From: FHeasley@chemistry.com (Frank)
Subject: Re: How to get everything in between <pre>....</pre> tags in html
Message-Id: <349b1daf.9959843@news.halcyon.com>
On 16 Dec 1997 15:16:24 GMT, mjtg@cus.cam.ac.uk (M.J.T. Guy) wrote:
>In article <hl0176.cs.ln@localhost>, Tad McClellan <tadmc@metronet.com> wrote:
>>That is an inefficient way to get an entire file into a string.
>>
>>I would stick with the conventional idiom:
>>
>>undef $/;
>>$lines = <FILENAME>; # slurp
>
>Or better, to avoid wrecking the input in the rest of your program:
>
> { local $/; $lines = <FILENAME> };
>
>
Why not:
while (<FILENAME>){
$lines .= $_
}
?
Frank
Frank
------------------------------
Date: Wed, 17 Dec 1997 11:40:12 +0100
From: G.Hood@iaea.org
Subject: http socket programming
Message-Id: <cATapIAEAlSGM1-971217104012Z-28449@sgm1.iaea.or.at>
I need to find out if certain files (listed in a database) really exist
on our web server and came up with the following code. I'm a bit out of
my depth though and don't understand why I can't pick up the http header
for a different file on each loop. Is it simply that I need to close and
re-open the socket on each loop?
$proto = getprotobyname('tcp');
$paddr = sockadd_in(80, inet_aton('www.mysite.com'));
socket(SOCK, PF_INET, SOCK_STREAM, $proto) or die "socket: $!";
connect(SOCK, $paddr) or die "connect: $!";
select(SOCK); $|=1; select(STDOUT);
# run a database query to get file list
while (@row = $dbh->dbnextrow) {
$filename = $row[0];
print SOCK "HEAD $filename HTTP/1.0\n\n";
$line = <SOCK>;
if ($line =~ /200/) {
print STDOUT "File &filename exists";
}
}
close(SOCK);
TIA for any help
Graeme Hood
IAEA
Vienna, Austria
------------------------------
Date: Tue, 16 Dec 1997 23:13:37 -0700
From: mbudash@sonic.net (Michael Budash)
Subject: Re: localtime() _is_ year-2000 compliant, right?
Message-Id: <mbudash-1612972313370001@d150.pm11.sonic.net>
In article <Pine.GSO.3.96.971216215725.19797E-100000@user2.teleport.com>,
Tom Phoenix <rootbeer@teleport.com> wrote:
>> On Tue, 16 Dec 1997, Michael Budash wrote:
>>
>> > As you probably know, the camel book mentions that localtime can take an
>> > argument, but it only mentions what happens if you _don't_ pass it!
>>
>> The camel book is, to an extent, derived from the manpages. If you'd like
>> to submit a patch to the manpages, that would be welcome! (Use the perlbug
>> program, supplied with Perl, to submit it.)
>>
>> > Could you please tell me where the FAQ is?
>>
>> (Doesn't everybody get that information in response to their first posting
>> to c.l.p.misc anymore?) Well, the FAQ comes along free with any recent
>> Perl. Or you can find it directly on CPAN.
>>
>> http://www.perl.com/CPAN/doc/manual/html/pod/perlfaq.html
>>
>> Enjoy!
>>
OK, folks, first take a lesson from Mr. Phoenix here, and be helpful.
Then, take a lesson from me and don't come to this newsgroup unless you've
done your homework. This is a rough room!
BTW - I got my answer from the FAQ, thank you.
Michael
--
Michael Budash, Owner * Michael Budash Consulting
mbudash@sonic.net * http://www.sonic.net/~mbudash
707-255-5371 * 707-258-7800 x7736
------------------------------
Date: 17 Dec 1997 18:21:42 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: localtime() _is_ year-2000 compliant, right?
Message-Id: <67957m$r3e$1@lyra.csx.cam.ac.uk>
Tom Phoenix <rootbeer@teleport.com> wrote:
>On Tue, 16 Dec 1997, Michael Budash wrote:
>
>> As you probably know, the camel book mentions that localtime can take an
>> argument, but it only mentions what happens if you _don't_ pass it!
>
>The camel book is, to an extent, derived from the manpages. If you'd like
>to submit a patch to the manpages, that would be welcome! (Use the perlbug
>program, supplied with Perl, to submit it.)
The man page already covers this satisfactorily, IMHO.
perldoc -f localtime:
Converts a time as returned by the time function to a 9-element array
with the time analyzed for the local time zone. Typically used as
follows:
# 0 1 2 3 4 5 6 7 8
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
localtime(time);
All array elements are numeric, and come straight out of a struct tm.
In particular this means that $mon has the range 0..11 and $wday has
the range 0..6 with sunday as day 0. Also, $year is the number of
years since 1900, that is, $year is 123 in year 2023.
[etc]
( And incidentally, there is a bug in the Camel p185, no doubt causing
Michael's difficulties. Compare the camel text with the above. )
Mike Guy
------------------------------
Date: 17 Dec 1997 15:27:34 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: LWP for Windows
Message-Id: <678r16$lhr@fridge.shore.net>
Yuksel Aslandogan (aslan@dbis.eecs.uic.edu) wrote:
: Is the LWP module available for Win95 or NT?
I'm pretty sure that it's bundled with Sarathy's 5.004_0x port.
--
Nathan V. Patwardhan
please don't send spam to pres@whitehouse.gov
------------------------------
Date: Wed, 17 Dec 1997 08:10:17 GMT
From: adelton@fi.muni.cz (Honza Pazdziora)
Subject: Re: missing socket.ph
Message-Id: <adelton.882346217@aisa.fi.muni.cz>
"William R. Mattil" <wrmattil@ix.netcom.com> writes:
> Hello all,
>
> I recently installed perl 5.004_4 on a risc6k using the smit installable
> archive from www.bull.de. However, the socket.ph file is missing, and
> there may be others. At this point compiling from the sources is not an
> option. Can anyone tell me where I can find this file ??? It doesn't
> apprear to be in the source distribution either.
Man h2ph.
Hope this helps,
--
------------------------------------------------------------------------
Honza Pazdziora | adelton@fi.muni.cz | http://www.fi.muni.cz/~adelton/
I can take or leave it if I please
------------------------------------------------------------------------
------------------------------
Date: 17 Dec 1997 17:24:01 +0100
From: Matz Kindahl <matkin@Owein.DoCS.UU.SE>
Subject: Re: NEED: Fast, Fast string trim()
Message-Id: <yf51zzcvsym.fsf@Owein.DoCS.UU.SE>
Chipmunk <rjk@coos.dartmouth.edu> writes:
> Aaron Harsh wrote:
> >
> > Aaron Harsh wrote in message <676mfm$hl3$1@brokaw.wa.com>...
> > >Is it cheating to do some of it outside a regex? Here's my entry, which is
> > >about four times faster than Andrew's (to run, not to type :-):
> > >
> > >$_ = join(" ", /\S+/g);
> >
> > Hmm.. This can be optimized for the likely case of lots of words with
> > single-spaces between them, which doubles the speed on the original test:
> >
> > $_ = join(" ", /\S+(?: \S+)*/g);
> >
> > and has the side effect of making the line a little less legible
>
> This appears to be at least as fast as either of your solutions:
>
> $_ = join(" ", split);
>
> Chipmunk
Maybe I've misunderstood something, but if you don't have to use
regular expressions, I'd write something along the following lines.
$_ = " $_ "; tr/ \n\r\t/ /s; substr($_,0,1) = substr($_,-1,1) = "";
I belive it's faster than splitting into a list and then joining the
list.
--
Mats Kindahl ! matkin@docs.uu.se
Department of Computer Systems ! matkin@acm.org
Box 325 ! Tel +46 18 18 10 66
S-751 05 Uppsala ! Fax +46 18 55 02 25
SWEDEN ! URL http://www.docs.uu.se/~matkin/
PGP Key fingerprint = 92 5C FC 39 32 A8 7F 91 01 56 A0 D3 9C A9 6C 81
PGP key available under finger matkin@kay.docs.uu.se
"People do strange things when you give them money."
-- Simple Minds
------------------------------
Date: Wed, 17 Dec 1997 02:31:14 -0500
From: "E. Brian Depenbrock" <ebd@sunline.net>
Subject: Re: newbie file input question
Message-Id: <677v0p$e3r@snews1.zippo.com>
The easiest way to read in a file, if this will work for you, is to include
it on the command line.
foo.pl infile
that makes it the default infile "STDIN"
Pete Hurd wrote in message <3495AE44.7B82866A@teleport.com>...
>Hello World,
>
>I'm having a frustrating time getting started with perl, I've got the
>llama and the FAQs, but...
>
>I cannot seem to read in a file, composed of lines (records) of
>space-separated words (fields),
>I want to access these words as items in a list, one list per line,
>something like awk's
>$1 through $NF.
>
>Now I've been trying things like:
>
>open(INFILE,"./foo.bar") || die "blah blah $!";
>while (@line = qw(<INFILE>)) {
> $first=$line[0];
>...
>
>and
>
>open(INFILE,"./foo.bar") || die "blah blah $!";
>while ($linein = <INFILE>) {
> @line=qw($linein);
> $first=$line[0];
>...
>
>to no avail.
>
>Surely this must be a very frequent operation, but I cannot find it in
>the FAQs, or the llama book.
>
>Please help, TIA.
>
>
>--
>Peter L. Hurd,
>phurd@BOGUSteleport.com <- remove BOGUS to reply
>http://toaster2.zool.su.se/pete.html
>
>
------------------------------
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 1489
**************************************