[13639] in Perl-Users-Digest
Perl-Users Digest, Issue: 1049 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Oct 12 12:05:30 1999
Date: Tue, 12 Oct 1999 09:05:12 -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: <939744311-v9-i1049@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 12 Oct 1999 Volume: 9 Number: 1049
Today's topics:
Accessing MS Access Database from Unix (AcCeSsDeNiEd)
Re: Advanced text substitution in FILEHANDLES <aqumsieh@matrox.com>
DBI/DBD and Oracle Explain Plan <ken.chesak@dhs.state.tx.us>
Re: DESTROY method: can't get to data? (M.J.T. Guy)
ERROR WITH NET::FTP, FILE::LISTING <craig@mathworks.com>
Re: Forcing Javascript to be on when a user uses a Perl <gellyfish@gellyfish.com>
Re: how to generate a hash name dynamically (M.J.T. Guy)
Re: Processing a comma delimited file (M.J.T. Guy)
Re: Remote Document Timestamps Continued... (Bill Moseley)
Re: Sending mail with Perl? <ewas@dds.nl>
Re: serching flat file database <gellyfish@gellyfish.com>
Re: setting passwords <jtribbeck@argogroup.com>
Slideshow script jongunn@my-deja.com
Re: Standard Error and NT <gellyfish@gellyfish.com>
system() and snmpwalk or other dos executables (r)
Re: tell() works incorrectly in windows (M.J.T. Guy)
Re: Using Perl to add line nums? <aqumsieh@matrox.com>
Re: Using Perl to add line nums? (Larry Rosler)
Re: Using Perl to add line nums? <sariq@texas.net>
using the 'foreach' loop to split a string (Pfash1)
Re: Where can I find the module GD for Windows servers? <gellyfish@gellyfish.com>
Re: Where can I find the module GD for Windows servers? <sjohns17@uic.edu>
Re: Why's 'mailx' complaining? <suaai@csv.warwick.ac.uk>
Re: Y2K update for ctime.pl <rhomberg@ife.ee.ethz.ch>
Re: Y2K update for ctime.pl <sariq@texas.net>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 12 Oct 1999 16:03:04 GMT
From: dillon_rm@magix.com.sg (AcCeSsDeNiEd)
Subject: Accessing MS Access Database from Unix
Message-Id: <3803590f.268081@news.magix.com.sg>
I have perl running on Unix
Is there anyway I can access a MS Access database?
The Access database can be hosted either on a Win32 or the Unix
machine itself.
I think this is not possible but I just need to be sure.
Thanks!
To e-mail me, remove "_rm"
PGP Key on Keyservers
Key ID: 0x27D16A6F
Fingerprint: 8B3E DEF8 216E 04BD C12E 53AC 86F3 BCD6 27D1 6A6F
------------------------------
Date: Tue, 12 Oct 1999 09:13:43 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: Advanced text substitution in FILEHANDLES
Message-Id: <x3yk8os7md4.fsf@tigre.matrox.com>
"PB" <22pb22@excite.com> writes:
> This is the original LIST.TXT that I want to clean, and the CLEANED.TXT
> output that I am looking for:
>
> --- list.txt --------
> user is john
> Dept is TEST
> Above user is in group
>
> user is doe
> Dept is TEST
> Above use is not in group
>
> user is blow
> Dept is TEST
> Above use is in group
>
> user is mike
> Dept is TEST
> Above name is not in group
>
> user is mike doe
> Dept is TEST
> Above name is in group
> ------ end list.txt --------------
>
> ------- cleaned.txt ---------
> JOHN
> BLOW
> ----- end cleaned.txt ----------
Someone might have already given you a solution, but I can't see it in
my newsfeed. So here we go.
open LIST, "list.txt" or die "Couldn't read list.txt: $!\n";
local $/ = ''; # paragraph mode
while (<LIST>) {
if (/Above user is in group/) {
my ($name) = /user is (\S+)/;
print uc $name, "\n";
}
}
__END__
JOHN
BLOW
Note that this makes a distinction between "Above user is in group"
and "Above name is in group". The latter is ignored since that is the
impression I got from your current post (your original post is also
missing from my newsfeed). It would be trivial to change the program
to suit your needs.
HTH,
--Ala
------------------------------
Date: Tue, 12 Oct 1999 10:46:14 -0500
From: "Ken Chesak" <ken.chesak@dhs.state.tx.us>
Subject: DBI/DBD and Oracle Explain Plan
Message-Id: <7tvl81$c9p$1@news.tdh.state.tx.us>
I am running Perl 5.005_02 on NT with Oracle 7.3. I have the current
dbi/dbd modules. I am trying to set up the explain plan to check out some
sql. Is this the best way to tune SQL? Does some one have an example that
works. After the explain plan, I plan to use TKPROF.
First problem I ran into was log_msg in Oracle.pm. All those values have
been changed to trace_msg.
My current error occurs on the first SQL with explain plan, this is the
trace log information. I have execute the SQL in SQLPlus and it works fine.
When using EXPLAIN PLAN does the SQL actually execute?
-> prepare for DBD::Oracle::db (DBI::db=HASH(0xe062cc)~0xe38c24 'EXPLAIN
PLAN
SET STATEMENT_ID = 'strip1' for
insert into t_rate
select distinct resident_internal_id
from assessment
where effective_date <= ?')
dbd_preparse scanned 1 distinct placeholders
<- prepare= DBI::st=HASH(0xde4e24) at tune_strip.pl line 235.
-> DESTROY for DBD::Oracle::st (DBI::st=HASH(0xe39180)~INNER)
<- DESTROY= undef at tune_strip.pl line 241.
-> execute for DBD::Oracle::st (DBI::st=HASH(0xde4e24)~0xe391d4
'01/01/1998'
bind :p1 <== '01/01/1998' (type 0)
bind :p1 <== '01/01/1998' (size 10/11/0, ptype 4, otype 1)
!! ERROR: 1036 'ORA-01036: illegal variable name/number (DBD: obndra
failed)
<- execute= undef at tune_strip.pl line 242.
-> errstr in DBD::_::common for DBD::Oracle::db
(DBI::db=HASH(0xe062cc)~0xe3
c24)
Thanks
Ken Chesak
ken.chesak@dhs.state.tx.us
------------------------------
Date: 12 Oct 1999 15:10:27 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: DESTROY method: can't get to data?
Message-Id: <7tvj13$dn3$1@pegasus.csx.cam.ac.uk>
Martien Verbruggen <mgjv@comdyn.com.au> wrote:
>
>Maybe there's a little teenie bug in 5.005_02? I don't have a 5.005_02
>available, otherwise I would test it for you. looking through the
>Changes file of the distribution, I don't see anything pertinent, but
>there's a lot of stuff there.
Well, it works for me on both 5.005_02 and 5.005_03 (Solaris 2.6).
So it's worth checking if it fails on your platform with 5.005_03.
Was 'make test' clean when the perl5.005_02 was installed?
Mike Guy
------------------------------
Date: Tue, 12 Oct 1999 11:49:30 -0400
From: Craig Ciquera <craig@mathworks.com>
Subject: ERROR WITH NET::FTP, FILE::LISTING
Message-Id: <38035889.C352CEA1@mathworks.com>
Hello,
I have the following in my code:
eval {
@dir = parse_dir($ftp->dir($directory),
$offset);
};
And receive the following in $@:
Bad arg length for Socket::unpack_sockaddr_in, length is 0, should be 16
at /usr/local/lib/perl5/sol2-solaris/5.00404/Socket.pm line 249.
Any ideas how I could be receiving this error????
Thanks in advance
-Craig
------------------------------
Date: 12 Oct 1999 16:41:47 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Forcing Javascript to be on when a user uses a Perl script
Message-Id: <380356bb_2@newsread3.dircon.co.uk>
Craig <craig@free-inter.net> wrote:
> Hello All,
>
> I know it is possible, because I have been to Web Sites which say I
> need my Javascript on to continue to thier site.
>
> Would some one be able to tell me the code to put in a Perl script, so
> when a user uses a Perl script, they will get prompted to turn it on
> if the user has it off.
>
It cant be done and it has nothing to do with Perl.
/j\
--
"Pat was wondering if he could put his massive tool in my box" - Mrs
Doyle, Father Ted
------------------------------
Date: 12 Oct 1999 15:30:33 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: how to generate a hash name dynamically
Message-Id: <7tvk6p$eur$1@pegasus.csx.cam.ac.uk>
In article <7tulaf$6sp$1@nnrp1.deja.com>, <cheecheng@my-deja.com> wrote:
>Hi,
>
>I have a question on how to generate a hash name
>dynamically. For example, I have an array
>@a = (1,2,3) and I need to make a hash out of it.
>I would like to have the following:
>$hashname1{2}=3
>
>I tried some variations of
>$hashname$a[0]{$a[1]}=$a[2]
>but nothing works.
You don't want to do that. For the reasons why not, and what you
should do instead, see
http://www.plover.com/~mjd/perl/varvarname.html
http://www.plover.com/~mjd/perl/varvarname2.html1
and also the perlfaq7 entry: How can I use a variable as a variable name?
( N.B. This FAQ entry hasn't got into the latest Perl release yet, nor
can it be found at www.perl.com yet. But it *is* amongst the
FAQs which are posted to this group at regular intervals.
)
Mike Guy
------------------------------
Date: 12 Oct 1999 15:39:07 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Processing a comma delimited file
Message-Id: <7tvkmr$f9t$1@pegasus.csx.cam.ac.uk>
In article <x3yhfk76s89.fsf@tigre.matrox.com>,
Ala Qumsieh <aqumsieh@matrox.com> wrote:
>
>ebohlman@netcom.com (Eric Bohlman) writes:
>
>> What you really want to do is use a hash keyed by the field titles. You
>> can set it up very easily by using hash slices:
>>
>> while (<DB>) {
>> my @fields{@vars} = parse_csv($_);
>
>The above will generate a compile-time error:
>
> Can't declare hash slice in my at - line x, near "} ="
>
>You have to actually do it in two steps:
>
> my %fields;
> @fields{@vars} = parse_csv($_);
>
>I made this error multiple times in the past. But, I was never able to
>guess why this error is necessary. Why shouldn't I be able to declare
>a hash slice in my()? Anybody with a good reason?
That wouldn't be consistent with existing valid Perl constructs. Compare
local @fields{@vars} = parse_csv($_);
which is *not* the same as
local %fields;
@fields{@vars} = parse_csv($_);
And since lexicalisation is an operation on names rather than variables,
you can't have *part* of a hash (or array) being lexical.
Mike Guy
------------------------------
Date: Tue, 12 Oct 1999 08:49:07 -0700
From: moseley@best.com (Bill Moseley)
Subject: Re: Remote Document Timestamps Continued...
Message-Id: <MPG.126cf8536d1153c39897fa@nntp1.ba.best.com>
Alligator (alligator333@my-deja.com) seems to say...
> I'm trying to get the "last-modified" date of a document on a remote
> server.
>
> Is it normal for so few servers to return a modification date? If so,
> how do web browsers and search engines consistently retrieve the
> timestamps of web pages? If not, what should I do differently?
You can only get it if they send it.
--
Bill Moseley mailto:moseley@best.com
pls note the one line sig, not counting this one.
------------------------------
Date: Tue, 12 Oct 1999 17:46:12 +0200
From: Ewald Wasscher <ewas@dds.nl>
Subject: Re: Sending mail with Perl?
Message-Id: <380357C4.1483167@dds.nl>
David Amann wrote:
<CUT>
> For Windows, the easiest way I can think of is to use the Mail::Mailer
> module and use the 'smtp' option.
>
<CUT>
Good, that's what I'm looking for too. I use a slightly modified version
of your script, but the script takes a long time and no mail is sent.
See the modified script and the mailserver's log below. Got any idea
what causes my problem? The same problem occurs when I use another
mailserver.
Oct 12 17:13:58 catv6216 postfix/smtpd[701]: connect from
catv6216.extern.kun.nl[131.174.116.216]
Oct 12 17:13:58 catv6216 postfix/smtpd[702]: connect from
localhost[127.0.0.1]
Oct 12 17:13:58 catv6216 postfix/smtpd[702]: disconnect from
localhost[127.0.0.1]
Oct 12 17:13:58 catv6216 postfix/smtpd[701]: A9691506C:
client=catv6216.extern.kun.nl[131.174.116.216]
Oct 12 17:13:58 catv6216 postfix/smtpd[701]: lost connection after DATA
from catv6216.extern.kun.nl[131.174.116.216]
Oct 12 17:13:58 catv6216 postfix/smtpd[701]: disconnect from
catv6216.extern.kun.nl[131.174.116.216]
Oct 12 17:13:58 catv6216 postfix/cleanup[703]: A9691506C:
message-id=<19991012151358.A9691506C@catv6216.extern.kun.nl>
#!perl -w -T
# Author: David Amann
# Version: 1.0
use strict; # Always use strict
use Mail::Mailer; # Import the Mail::Mailer module
my $smtp_server = "catv6216.extern.kun.nl";
my $from = "nijsac\@catv6216.extern.kun.nl";
my $to = "ewald\@catv6216.extern.kun.nl";
my $subject = "Testing A Mail Program";
my $body = "This is the body\n";
my $mailer = new Mail::Mailer ("smtp", Server => $smtp_server);
$mailer->open({ From => $from,
To => $to,
Subject => $subject,
})
or die "Can't open: $!\n";
print $mailer $body;
$mailer->close();
TIA,
Ewald
------------------------------
Date: 12 Oct 1999 16:22:32 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: serching flat file database
Message-Id: <38035238_2@newsread3.dircon.co.uk>
Craig <craig@free-inter.net> wrote:
> There is a Perl CGI script @ CGI-Resources.com called SearchQuotes
> under the section Misc.
>
> http://cgi-resources.com/Programs_and_Scripts/Perl/
>
I'm not sure how this answers the original posters question - still less
how it addresses Dave Cross' post ...
/J\
--
"The Tory Party is like a wonky shopping trolley - it pulls to the
left, it pulls to the right, but you just can't get it to go forward"
- John Prescott
------------------------------
Date: Tue, 12 Oct 1999 17:39:15 +0100
From: Jason P Tribbeck <jtribbeck@argogroup.com>
Subject: Re: setting passwords
Message-Id: <38036433.E487353E@argogroup.com>
paolo wrote:
>
> hello everybody,
> does someone know how can I set a password for a NEW system user:
> -I have a file with a user-password list
> -I want to create the user and set his password with a script, without
> prompting!
>
> thanks in advice to everybody!
Here's a fragment that I use under FreeBSD:
$legal="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$salt=substr($legal,int(rand(length($legal))),1).
substr($legal,int(rand(length($legal))),1);
$dpass=crypt($password,$salt);
system "chpass -a
\"$user:$dpass:$uid:1002::0:0:$full:$userdir:$shell\"";
where:
$user is username
$password is password
$uid is the UID I want to give for the user
$full is the user's fullname
$userdir is the user's directory
$shell is the user's shell
Of course, this may not work on other OSses - for example, under Solaris
2.5
system "useradd -u $uid -g 1002 -d $userdir -c \"$full\" -s $shell
$user"
would create the user, but there's no (obvious) way to set the password.
chpass is also available under NetBSD, but I don't know if it's
available
under Linux.
--
Jason Tribbeck Argo Interactive
ltd
Senior Design Engineer 7 Dukes Court,
Chichester
West Sussex, PO19
2FX
Tel: +44 1243 815 815 Fax: +44 1243 815 805
England
------------------------------
Date: Tue, 12 Oct 1999 15:52:42 GMT
From: jongunn@my-deja.com
Subject: Slideshow script
Message-Id: <7tvlg2$u8k$1@nnrp1.deja.com>
Hi, I want to make a script that displays text/images slideshow in
netscape (text and images links come from database quary).
How can I make Netscape(NS) show one page at a time of the slideshow.
How can I clear the first page so I can write next page In netscape
I have the following script nph-test.pl
#!/usr/bin/perl
# -I/usr/local/lib/perl5
$| = 1; #don't buffer output
$count=1;
while($count<=10){
print('HTTP/1.0 200 OK');#NS only uses this the first time
print "Content-type: text/html\n\n";
print "<HTML><HEAD><TITLE>test</TITLE></HEAD>
<BODY bgcolor='FFFFFF'>
<h2>Test $count</h2>
</body></html>";
$count++;
sleep(1);
}
How can I do this, or use perl to make slideshow
or do I have to write all pages first and use
<META HTTP-EQUIV="Refresh" CONTENT="2; URL=NextPage.html"> to do the
slideshow?
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 12 Oct 1999 16:48:53 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Standard Error and NT
Message-Id: <38035865_2@newsread3.dircon.co.uk>
Craig <craig@free-inter.net> wrote:
> On Mon, 11 Oct 1999 23:50:26 -0500, Adrian Mink
> <akmink@worldnet.att.net> wrote:
>
>>Can someone tell me how to redirect standard error to a file under NT
>>from a perl script? I'm running
>>Active state Perl build 517. I running nslookup from the script and have
>>tried using 2>&1 with nslookup as one of my books suggest, but have had
>>no luck. Any ideas? Thanks.
>>
> META TAG redirect, is this what you want?
>
> <META HTTP-EQUIV=\"Refresh\" CONTENT=\"0; URL=yourpage.htm\">
>
No that is patently not what he wants and whats more it has nothing to
do with Perl.
Please explain to me what you thing that HTML stuff has to do with the
standard error output of a program. I dont even think the original
poster suggested he was doing anything slightly wwwish ...
/j\
--
"Nourishes at the root and penetrates right to the tip" - Pantene
Advertisement
------------------------------
Date: Tue, 12 Oct 1999 16:52:49 +0100
From: sr@asd.com (r)
Subject: system() and snmpwalk or other dos executables
Message-Id: <MPG.126d69ad6f6c1318989680@news.virgin.net>
Hi
I have a number of DOS based executables that will display information on
the screen.
They can be piped to a file in DOS ok.
What I want to do is to use PERL to do similar things, and more.
the main dos executable is snmpwalk.exe and there are 2 variable
arguments that follow the command.
so the Dos line would be;
snmpwalk.exe $host1 $snmpvar
I would like to pipe to a file but am unsure as to how to do this.
I have tried the following but, whilst it goes to the screen, it does not
go to the file.
print "Enter host: ";
chomp($host1=<STDIN>);
print "Enter SNMP variable: ";
$snmpvar=<STDIN>;
$info="snmpwalk $host1 $snmpvar > c:\info.txt";
system($info);
Any help would be gratefully received.
Russ Parker
------------------------------
Date: 12 Oct 1999 15:16:45 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: tell() works incorrectly in windows
Message-Id: <7tvjct$dv6$1@pegasus.csx.cam.ac.uk>
Joe Seigh <jseigh@bbnplanet.com> wrote:
>Why does tell() try to guess the file offset based on the
>length of prior reads plus 2 for the CR+NL for each line?
tell() doesn't do anything of the sort. It just reports the current
byte offset as held by stdio.
Mike Guy
------------------------------
Date: Tue, 12 Oct 1999 09:01:10 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: Using Perl to add line nums?
Message-Id: <x3yln987my2.fsf@tigre.matrox.com>
lr@hpl.hp.com (Larry Rosler) writes:
> In article <4287-380290B4-1@storefull-214.iap.bryant.webtv.net> on Mon,
> 11 Oct 1999 21:36:52 -0400 (EDT), KernelKlink@webtv.net
> <KernelKlink@webtv.net> says...
> > Is it possible to write a Perl script that will add line numbers to an
> > existing script by using the existing script as an argument? I would
> > want even the blank lines to be numbered, not just the lines with text
> > on them.
> >
> > Will Perl do this?
>
> Perl will do just about anything. In one line. :-)
>
> For Windows/DOS:
>
> perl -pe "printf '%3d ', $." foo.txt
>
> For Unix:
>
> perl -pe 'printf "%3d ", $.' foo.txt
Larry, haven't you ever written a Perl program that is more than a
thousand lines long? I am sure a lot of people have done so, so why
put that limit on your little snippet? (Especially that you
use printf() to get a nicer format than print()).
perl -pe 'printf "%8d ", $.' foo.txt
Now, if you ever write a functional Perl program that is more than
10^8 lines long, then you need therapy :-)
--Ala
------------------------------
Date: Tue, 12 Oct 1999 08:49:14 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Using Perl to add line nums?
Message-Id: <MPG.126cf8514763c92998a07f@nntp.hpl.hp.com>
In article <x3yln987my2.fsf@tigre.matrox.com> on Tue, 12 Oct 1999
09:01:10 -0400, Ala Qumsieh <aqumsieh@matrox.com> says...
> lr@hpl.hp.com (Larry Rosler) writes:
...
> > perl -pe 'printf "%3d ", $.' foo.txt
>
> Larry, haven't you ever written a Perl program that is more than a
> thousand lines long? I am sure a lot of people have done so, so why
> put that limit on your little snippet? (Especially that you
> use printf() to get a nicer format than print()).
I have written Perl programs that are several thousand lines long, but
*never* in one file. NEVER! The number '3' in the format didn't come
out of a random-number generator.
> perl -pe 'printf "%8d ", $.' foo.txt
With five extra leading blanks, the right end of some of the lines that
I write will end up off an 80-column printout.
> Now, if you ever write a functional Perl program that is more than
> 10^8 lines long, then you need therapy :-)
s/program/file/;
tr/8/3/;
But I might need therapy anyhow. :-)
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Tue, 12 Oct 1999 10:42:16 -0500
From: Tom Briles <sariq@texas.net>
Subject: Re: Using Perl to add line nums?
Message-Id: <380356D8.40D79F62@texas.net>
Ala Qumsieh wrote:
>
> lr@hpl.hp.com (Larry Rosler) writes:
>
> > In article <4287-380290B4-1@storefull-214.iap.bryant.webtv.net> on Mon,
> > 11 Oct 1999 21:36:52 -0400 (EDT), KernelKlink@webtv.net
> > <KernelKlink@webtv.net> says...
> > > Is it possible to write a Perl script that will add line numbers to an
> > > existing script by using the existing script as an argument? I would
> > > want even the blank lines to be numbered, not just the lines with text
> > > on them.
> > >
> > > Will Perl do this?
> >
> > Perl will do just about anything. In one line. :-)
> >
> > For Windows/DOS:
> >
> > perl -pe "printf '%3d ', $." foo.txt
> >
> > For Unix:
> >
> > perl -pe 'printf "%3d ", $.' foo.txt
>
> Larry, haven't you ever written a Perl program that is more than a
> thousand lines long?
I'd bet that he has...
> I am sure a lot of people have done so, so why
> put that limit on your little snippet? (Especially that you
> use printf() to get a nicer format than print()).
>
> perl -pe 'printf "%8d ", $.' foo.txt
There is no limit. The digit is a minimum field length. But then, I'm
sure Ala knew that, given sufficient supply of caffeine.
acme$ wc -l foo.txt
3173 foo.txt
acme$ perl -pe 'printf "%3d ", $.' foo.txt
1 "-","115","0","323"
2 "12061977","7","0","1"
3 "121","35","0","1"
...
3171 "zyn","69","0","1"
3172 "zzz_ht_hoo","8","0","1"
3173 "zzz_topicssr","1","0","1"
Personally, I'd use:
perl -pe 'print "$.\t"' foo.txt
But that's just a preference.
- Tom
------------------------------
Date: 12 Oct 1999 16:00:00 GMT
From: pfash1@aol.com (Pfash1)
Subject: using the 'foreach' loop to split a string
Message-Id: <19991012120000.27645.00000204@ng-fi1.aol.com>
Hi,
I am trying to read a text file that is separated into records (separated by
the dotted line indicated at the beginning of the code) and split each record
apart (on the blank spaces between the words) and put these parts (words) into
an array.
I am able to separate each record and put it into its own element in an array
but when I use the 'foreach' loop to split each one of those records (elements)
on the blank space it only fills the new array with the last record split on
the blank space. (I presume it is erasing the previous split record when it
fills the array with the next split record)
How do I read all these dotted line separated records off of one text file and
(I need them in their own array so I can treat them individually) then split
each record on the blank space? Thanks for any help you could give. Paul
(pfash@umich.edu)
Here is how far I got:
#!perl-w
my @eachrecord;
open (FH, 'demo.db');
while (<FH>)
{
$/ = "-----------------------";
chomp;
s/\n[ \t]+/ /g;
push @records, $_;
}
close (FH);
foreach $record(@records)
{
@string = split(/ /, $record);
}
print @string;
#########
Here is the demo database ('demo.db') file it is reading from:
To: Steve
Sender's Name: Jody
Hello, Steve: here is my message.
-----------------------
To: frank
Sender's Name: frankssender
Hello, frank:: here is my message
-----------------------
to: pete
Sender's Name: petessender
Hello, pete::here is my message
-----------------------
------------------------------
Date: 12 Oct 1999 16:18:52 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Where can I find the module GD for Windows servers?
Message-Id: <3803515c_2@newsread3.dircon.co.uk>
Craig <craig@free-inter.net> wrote:
> Anyone know where I could find GD for Win32?
>
If you have Activestate perl then you can just do :
PPM install GD
At the command prompt.
/J\
--
"Tony Blair is reported to be detained indefinitely under plans unveiled
by the Home Secretary" - Corrupt Teletext Page
------------------------------
Date: Tue, 12 Oct 1999 10:07:37 -0500
From: Seth David Johnson <sjohns17@uic.edu>
Subject: Re: Where can I find the module GD for Windows servers?
Message-Id: <Pine.A41.4.10.9910121004460.328628-100000@tigger.cc.uic.edu>
On Tue, 12 Oct 1999, Craig wrote:
> Anyone know where I could find GD for Win32?
You probably want to familiarize yourself with ppm.pl, a package
installation/query script that comes with the ActivePerl distribution, and
probably the easiest way in which to install the GD extension (and all
other extensions, for that matter) on a Win32 machine.
-Seth
www.pdamusic.com
------------------------------
Date: Tue, 12 Oct 1999 16:34:41 +0100
From: MTW <suaai@csv.warwick.ac.uk>
Subject: Re: Why's 'mailx' complaining?
Message-Id: <Pine.GSO.4.10.9910121630050.7711-100000@mimosa.csv.warwick.ac.uk>
On Mon, 11 Oct 1999, Alan J. Flavell wrote:
> On Sun, 10 Oct 1999, MTW wrote:
>
> > Hi - I'm about 72 hours into learning perl, and I've got quite far (for
> > me, anyhow :) but have come up against this brick wall:
> >
> > I'm writing a simple mail rebroadcasting service for the members of my
> > society (see .sig :-)
>
> With respect, I'd counsel you that you are being over-ambitious.
> Writing a mail exploder is a far from trivial task, especially guarding
> against mail loops, "open relay" situations and other kinds of chaos.
> Believe me, I've done that, long before packages like majordomo etc.
> were available, and I've got the old scars from trying to rescue my
> system from the resulting meltdown, and having to apologise to the
> subscribers...
Thanks for that - I'll take it on board :). However, the relatively small
number of ppl on the list (<50) and the standardised, 'safe' environment
provided by the IT services of our university mean that I'm pretty
confident I can manage it. I've only had one 'meltdown' so far, which
envolved mailing myself (as the test subscriber) about 50 megs of data but
I won't be doing _that_ again:
$line=<STDIN>;
while ($line) {
print MAIL $line;
}
<ahem> :-)
> If you take my advice, look into one of the respected mail distributor
> packages (go to an appropriate group to investigate what they are), and
> practice your Perl skills on something else. Don't take this as general
> discouragement, just as honest practical advice for this specific (and
> relatively high-risk if you get it wrong) situation.
No budget! I'm running this for a small theatrical society, with 0 money
to spare :(
> good luck
I don't need LUCK!!
I need . . . . a MIRACLE!
jC
Music Theatre Warwick
write: c/o Music Centre, University of Warwick, Coventry CV4 7AL, England
mailto:mtw@warwick.ac.uk
http://www.warwick.ac.uk/society/mtw/
------------------------------
Date: Tue, 12 Oct 1999 17:18:59 +0200
From: Alex Rhomberg <rhomberg@ife.ee.ethz.ch>
To: Matt King <mattking@techie.com>
Subject: Re: Y2K update for ctime.pl
Message-Id: <38035163.5C1743A4@ife.ee.ethz.ch>
Matt King wrote:
>
> Hi, I have seen several small items where people have either mentioned or
> asked about Y2K issues with PERL scripts. This got me wondering if I might
> be using a non-Y2K date script. After checking my scripts, I beleive that
> I'm using a non-Y2K date script. The script is included in the Active Perl
> installation in the lib dir called ctime.pl (line 46 ($year += 1900) . Is
> there an update to this script somewhere that makes it Y2K? Or does someone
> have a better solution as that this one is rather large. I'd like to solve
> this before the real problems start. =)
What makes you think that this line breaks on Y2K?
localtime manpage says "Also, $year is the number of years since 1900,
that is, $year is 123 in year 2023"
So by adding 1900, you'll get the correct years for christian
calculation. By adding about 2444, you'd get the years for buddhist
calculation. (How much you have to add depends on the date)
The non - Y2K compliant code looks like:
BEGIN BROKEN CODE
$year = "19$year" #this is called the year 19100 problem around here
END BROKEN CODE
- Alex
------------------------------
Date: Tue, 12 Oct 1999 10:17:46 -0500
From: Tom Briles <sariq@texas.net>
Subject: Re: Y2K update for ctime.pl
Message-Id: <3803511A.9A43D2C@texas.net>
Matt King wrote:
>
> After checking my scripts, I beleive that
> I'm using a non-Y2K date script. The script is included in the Active Perl
> installation in the lib dir called ctime.pl (line 46 ($year += 1900) .
And the problem with this is...?
You could, of course, just use localtime() yourself.
- Tom
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V9 Issue 1049
**************************************