[6813] in Perl-Users-Digest
Perl-Users Digest, Issue: 438 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue May 6 05:07:27 1997
Date: Tue, 6 May 97 02:00:25 -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 Tue, 6 May 1997 Volume: 8 Number: 438
Today's topics:
Re: a question on striping characters (Mark Mills)
Re: adding to an array within a while(<>) <dbenhur@egames.com>
Re: Complex Data Structure help: How can I do a push?? <seay@absyss.fr>
Re: composing a key out of 2 fields (Craig Berry)
How to safely and properly update an ASCII text databas Martin Mathis
Re: Inserting list item into HTML bullet list.... (Mark Mills)
Re: Loosing clpm regulars (was Re: Perl auto-replier) <seay@absyss.fr>
Re: LWP::Socket <c.evans@clear.net.nz>
Re: Modifying D-Base fields with PERL. (Clay Irving)
Re: Object IDs are bad (was: Ousterhout and Tcl lost th <ludemann@inxight.com>
Re: Perl auto-replier <usenet-tag@qz.little-neck.ny.us>
Re: Perl auto-replier (Zach Baker)
Re: Perl auto-replier <seay@absyss.fr>
Re: PERL Editor (Clay Irving)
Re: program for perl? (Christopher Masto)
Re: program for perl? <ajohnson@gpu.srv.ualberta.ca>
Re: Reading data from a file and outputting to another (Tad McClellan)
Re: Singles and doubles (Honza Pazdziora)
unpack, $_, -w, and "uninitialized variable" (David Combs)
when moved from unix to nt breaks.....counting items in (David Schultz)
Word 97 OLE broken? doug@sitewerks.com/nospam
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 06 May 1997 06:39:36 GMT
From: mark@ntr.net (Mark Mills)
Subject: Re: a question on striping characters
Message-Id: <336ed108.3124478@news.ntr.net>
On 5 May 1997 04:57:03 GMT, Ronald.J.Kimball@dartmouth.edu (Chipmunk)
wrote:
>In article <dwwpixaw0.fsf@s3i.com>
>Clark Dorman <dorman@s3i.com> writes:
>
>> #!/home/dorman/bin/perl -w
>>
>> $bar = $foo = "I_LIKE_THE_NUMBER_9_AND_THE_NUMBER_12";
>> $bar =~ s/[^\d]+/ /g;
>> @baz = split(' ',$bar);
>> print " ($foo) ($bar) (@baz) ($#baz)\n";
>>
>> Note the space in the substitution for split to work on. I'm still
>> learning this stuff so feel free to correct it.
>
>Clever idea with the space there. One problem I see is that @baz will
>contain a null value if $bar begins or ends with non-digits. That
>won't matter for the print statement, but could be significant if other
>things are being done to the array.
>One way to solve that problem would be to add:
>$bar =~ s/^ | $//g;
>after the original substitution.
>
>BTW, the first argument to split should be a regexp: split(/ /, $bar);
>
>Chipmunk
Actually, I think that the space WAS a CLEVER idea. So did the man
page authors :> Perl was gonna do the right thing. Automagical as
all heck huh?
FROM PERLFUNC:
As a special case, specifying a PATTERN of space (' ') will split on
white space just as split with no arguments does. Thus,
split(' ') can be used to emulate awk's default behavior, whereas
split will give you as many null initial fields as there are
leading spaces. A split on /\s+/ is like a split(' ') except that any
leading whitespace produces a null first field.
--
[Hopper, Dennis]: There's mines over there, there's mines over
there, and watch out those goddam monkeys bite, I'll tell ya.
==Apocalypse Now==
------------------------------
Date: Mon, 05 May 1997 15:02:50 -0700
From: Devin Ben-Hur <dbenhur@egames.com>
To: sdm <sdm@red.seas.upenn.edu>
Subject: Re: adding to an array within a while(<>)
Message-Id: <336E590A.1B54@egames.com>
[mail&post]
sdm wrote:
> Is there a way to easily add to an @array each pass through a while() loop,
> without the next pass obliterating what was there on the previous pass?
> Everything I find in my books seem to bypass/overlook this.....
I think you have some fundamental misconception about
how arrays are manipulated or how while works.
Look up the functions push() and unshift() for convenient
ways to extened an array (at either end).
HTH
--
Devin Ben-Hur <dbenhur@egames.com>
eGames.com, Inc. http://www.egames.com/
eMarketing, Inc. http://www.emarket.com/
"No, I'm not going to explain it. If you can't figure it out,
you didn't want to know anyway..." --Larry Wall
------------------------------
Date: Tue, 06 May 1997 10:10:59 +0100
From: Douglas Seay <seay@absyss.fr>
Subject: Re: Complex Data Structure help: How can I do a push??
Message-Id: <336EF5A3.15081DDB@absyss.fr>
Ratty wrote:
>
> I've used data structures a lot but never really got
> comfortable with them and have had to futz around and tweak
> to get them to work, never really understanding what I was
> doing. The program I'm writing now uses a fairly complex
> data structure and I've gotten it to work using array subscripts
> but I'd prefer to implement it using push instead. It bugs me
> that I can't figure out how to do this.
>
> The program reads an sgml file, extracts attribute information
> from selected tags, and uses this to print rows of small
> thumbnail gifs to a web page. The data structure I've chosen
> is an array of hashes of arrays of hashes:
>
> @thumbrows contains hashes called %row. Each %row contains (among
> other things) an array called @thumbs. @thumbs is an array
> containing a hashes called %img. What follows is first the test
> code that builds the struct, followed by a short loop to print
> out selected values. Can anyone tell me how to eliminate the
> subscripts and do all of this with push and foreach?
<snip>
> for $i (0..$#thumbrows) {
> for $j (0..$ThumbRowNum) {
> print "$thumbrows[$i]->{thumbs}[$j]->{caption}\.\n";
> }
> }
foreach $thumb ( @thumbrows )
{
foreach $img ( @{ $thumb->{thumbs} } )
{ print $img->{caption}, "\.n"; }
}
plus or minus any silly syntax errors.
- doug
------------------------------
Date: 6 May 1997 06:44:41 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: composing a key out of 2 fields
Message-Id: <5kmk0p$7ef$1@marina.cinenet.net>
Shawn (srf@ultranet.ca) wrote:
:
: I plan to have a comma delimeted file for recording hours worked week
: by week with the following format
:
: project number, start date, end date, Sun hrs, Mon hrs, .. sat hrs,
: total hrs
:
: Each contractor has their own file. Since someone may be working on
: several projects at once, I need both the project number and the start
: date to identify unique records.
:
: I would like to set the file up as a hash of arrays with the key being
: a composite of the project number and the start date.
:
: Is there any way to do a sort on composite keys, say if the keys were
: something like 541_5/5/1997
I would suggest creating a composite textual key as from the data, and
using it as your hash key.
: What's the best format for the date?
I'm partial to YYYYMMDD, with MM and DD zero-padded for single-digit
values. So, e.g., July 4 1997 would be 19970704. This avoids year-2000
problems, and lets you sort dates lexically.
For a composite key of the type you're after, I'd need to know more about
your project numbers. If they're (say) simple nonnegative integers less
than or equal to six digits in length, I might suggest an encoding like
this:
$key = sprintf("%04d%02d%02d_%06d", $yr, $mo, $dy, $proj);
So project 123 starting on July 4 1997 would become the key:
19970704_000123
If you sort on these lexically, you'll end up with a sort by start date,
then by proj number within each date.
Hope this helps!
---------------------------------------------------------------------
| Craig Berry - cberry@cinenet.net
--*-- Home Page: http://www.cinenet.net/users/cberry/home.html
| Member of The HTML Writers Guild: http://www.hwg.org/
"Every man and every woman is a star."
------------------------------
Date: 5 May 1997 22:42:01 -0700
From: Martin Mathis
Subject: How to safely and properly update an ASCII text database?
Message-Id: <336eb307.6084921@news.primenet.com>
Hi all,
I'm learning PERL with a bunch of books at my hands. However, I can't
seem to find an answer to the following task:
I have an ASCII text database with e.g. addresses for an example, one
record per line. Each record contains an "active" flag ("Y" or "N").
Based on some criteria I want to change some flags from Y to N.
In a single user environment I would read the file, determine the new
flags and output to a temporary file, when done rename to database
again.
However, I'm in a multi-user environment (Web site) and want to make
sure there is a flock or similar on the database while the flag update
is running. Since read/write-to-temp and rename are two steps, I'd
lose the flock when closing the first step (assuming I can't safely
rename before the filehandles are closed).
Is my only option to manually write out a lock file for the update
duration and hope that no one cancels the script before the lock file
can be removed again?
Or should I determine the flag on the fly from my criteria each time
rather than bother to write a status flag?
How is a simple ASCII text database commonly and safely being updated?
TIA and best,
-Martin
______________________________________________________________
mmathis@primenet.com
------------------------------
Date: Tue, 06 May 1997 07:00:54 GMT
From: mark@ntr.net (Mark Mills)
Subject: Re: Inserting list item into HTML bullet list....
Message-Id: <336fd59f.4299378@news.ntr.net>
On Sun, 04 May 1997 19:57:44 -0800, "Jeff Keller" <jakeller@ucsd.edu>
wrote:
>What I'm trying to do is write a Perl script to automatically add
>and delete people from the high school alumni list I've kept for
>the past several years..
>
>I can get it to delete people just fine.. but when I want to add
>someone's entry, I want it to go in the right spot alphabetically..
>but I can't even think of a logical way to do it, let alone use
>Perl to do it <grin>
>
>An example of the page I'd want to add an entry to is:
>http://lostworld.pair.com/smhs/years/1994.html
>
>Say I want to have the script put in "Bob Jones '96 (and all that
>follows)" -- it needs to go in the right place!
>
>So if anybody can help, or if you need more info, don't hesitate
>to write me at jakeller@ucsd.edu -- if you post publicly here be
>sure to copy me in on the message too..
>
>Jeff Keller
If I were you I'd write *2* scripts. One that adds and deletes from a
simple database (comma separated would be fine I'd say) and one that
builds the webpages from a template and the DB.
Then you'd be able to do all kinds of sorting and stuff...
Let us know if ya need help once you've taken a stab at the code.
--
[Hopper, Dennis]: There's mines over there, there's mines over
there, and watch out those goddam monkeys bite, I'll tell ya.
==Apocalypse Now==
------------------------------
Date: Tue, 06 May 1997 10:13:31 +0100
From: Douglas Seay <seay@absyss.fr>
Subject: Re: Loosing clpm regulars (was Re: Perl auto-replier)
Message-Id: <336EF63B.67F02DE3@absyss.fr>
Mike Stok wrote:
>
> In article <fl_aggie-ya02408000R0505970944190001@news.fsu.edu>,
> I R A Aggie <fl_aggie@hotmail.com> wrote:
>
> >+ I wish people would just learn to use www.dejanews.com.
> >
> >I wish people would just learn to read the man pages.
>
> So all we need is some way of applying a patch to human nature...
I'm all for this, as long as I get to decide what goes in the patch.
- doug
------------------------------
Date: 06 May 1997 18:48:38 +1200
From: Carey Evans <c.evans@clear.net.nz>
Subject: Re: LWP::Socket
Message-Id: <87enblxfi1.fsf@psyche.evansnet>
dirk@icon.co.za writes:
[snip]
> #!/usr/local/bin/perl
> push(@INC,"/perl/lib");
This does nothing in your program.
> use LWP::Socket;
> $socket = LWP::Socket;
You should really be using IO::Socket, but that's not the problem.
[snip]
> Anyone know what's wrong or how to fix ?
You didn't use "-w" and "use strict".
BTW, you need to say something to a web server before it replies, so
your program would appear to hang once you did get it running.
--
Carey Evans <*> c.evans@clear.net.nz
"Encryption renamed to Encode to avoid US regulation problems"
- include/linux/wireless.h in Linux 2.0.30 kernel
------------------------------
Date: 6 May 1997 00:17:45 -0400
From: clay@panix.com (Clay Irving)
Subject: Re: Modifying D-Base fields with PERL.
Message-Id: <5kmbd9$a90@panix.com>
In <862862948.23367@dejanews.com> Jeremy_Fuller@rocketmail.com writes:
>I was wondering if anybody could help me out on a database question
>pertaining to the PERL programming language. What I want to do is MODIFY
>a Database field when a link is followed or clicked.
>This is an Example:
>name|address|city|state|phone|fax|CODE
>Jeremy Fuller|123 Vr. Lane|Ogden|CA|85560|555-6672|555-7894|RED
>I would like to MODIFY CODE "RED" to CODE "BLUE". How can I accomplish
>this using Perl? Any information you can supply would be appreciated.
open FOO, ">filename" or die "Ack: $!"; # open the file
while (<FOO>) { # for each line in the file
chomp; # remove the newline
# split on |
($name,$address,$city,$state,$phone,$fax,$code) = split /\|/;
if ($code eq "RED") { # if code is "RED"
$code = "BLUE"; # change it to "BLUE"
}
}
close FOO; # close the file descriptor
>If you can, Please e-mail me at Jeremy_Fuller@rocketmail.com (I don't
>check Usenet very often).
Shame on you.
[ mailed and posted ]
--
Clay Irving See the happy moron,
clay@panix.com He doesn't give a damn,
http://www.panix.com/~clay I wish I were a moron,
My God! Perhaps I am!
------------------------------
Date: 05 May 1997 19:50:14 -0700
From: Peter Ludemann <ludemann@inxight.com>
Subject: Re: Object IDs are bad (was: Ousterhout and Tcl lost the plot with latest paper)
Message-Id: <wujyb9txqjd.fsf@wistaria.i-have-a-misconfigured-system-so-shoot-me>
ark@research.att.com (Andrew Koenig) writes:
> Exactly. They are two different objects with the same value.
>
> Whether or not that is an easy concept to live with seems to depend
> on the local culture.
>
> Which is the main point I was trying to make.
And your point is...?
As I don't belong to your local culture, such beliefs are irrelevant
to our discussion, which is a bit more about Truth & Beauty rather
than local culture or lack thereof.
There are "local cultures" where anything not mentioned in the Bible
is disallowed (e.g., electricity and motor cars); other "local
cultures" believe that discrimination based on skin color is good.
These beliefs are irrelevant to any discussion about the merits of
electricity and racial discrimination.
So ...
If there are two different objects with the same value there must be
some reason for that. Otherwise it is easy to become confused and
update the wrong object (there's no way to tell them apart ... they
look the same). A particularly nasty version of this is when the
compiler quietly creates a copy of a parameter during a function call.
[Not that updating-in-place is a good idea, if it can be avoided. But
that's a separate issue, which other people are happily discussing
very well without my help or hindrance.]
It seems that you live in a culture that thinks two different objects
with exactly the same value are OK. So, please tell my *why* you
think this is a good thing. After all, the people who live without
electricity have their reasons ... but I have not yet heard your
reasons for not wanting what my experience has taught me is a
wonderful thing: referential transparency.
--
Peter Ludemann +1.415.813.6806 (fax: +1.415.813.7499)
Software Architect ludemann@inxight.com
InXight Software, Inc. http://www.inxight.com
PAHV 105, 3400 Hillview Ave., Palo Alto, CA 94304
------------------------------
Date: 6 May 1997 04:08:03 GMT
From: Eli the Bearded <usenet-tag@qz.little-neck.ny.us>
Subject: Re: Perl auto-replier
Message-Id: <eli$9705052331@qz.little-neck.ny.us>
Chipmunk <Ronald.J.Kimball@dartmouth.edu> wrote:
>Douglas Seay <seay@absyss.fr> writes:
>> I don't want to say that rudeness is the only way, but the hordes of
>> unread newbies grows old quick.
>And I ask again, will being rude solve the problem?
Doug didn't say it would.
>No, it won't. No matter how rude you are, we will continue to have
>newbies asking foolish questions. As I see it, being rude gets you
>nothing.
I'm often (by my standards) curt when answering obvious questions.
Yet there have been times that I have gotten "Thank You"s from these
that specifically mentioned how polite I was compared to other
people responding. My idea of curt is often something down the lines
of "RTFM getsockname(2)." with no further elaboration. Generally I
reply by email for simple answers (so if your email address is too
much work to use, I just won't answer, tough luck).
A rude response, particularly in public, *that answers the question*
I think may help to reduce newbies from posting questions. Whether
this is good or bad I'm not sure. Rude responses that do not answer
the question are bad. Then there are some determined-to-remain-clueless
posters who need lots of abuse, like the guy in alt.unix.wizards who
recently flamed Andrew Gierth for giving the right answer to the 'How
do I delete a "-Rf" file?' while maintaining the correct answer is
'rm "-Rf"'.
There are certain rules, of thumb really, that apply to using Usenet
effectively. Those who cannot bother to learn them should not be
unfailingly protected from their folly. It is pretty hard to ask a
question to simple to be appropriate for Usenet, but it is also very
easy to ask that question in the wrong way.
Compare:
Why won't this work?
#!/usr/local/bin/perl
print "Hiya planet";
--
HOW TO SOLVE THE POPULATION PROBLEM -by 3l33+ R()|>
1 Glock 19
1 finger
1 sense of direction
1 bullet
inhale here
pull this |
back -----> 8888o.o.o.o.ooooooo00||00oooooooooooooooooooo88o |
88:8:8:8:8:888888800||0088888888888888888888888: <--'
88:8:8:8:8:888888888888888888888888888888888888:
Y88:8:8:8:8:8888888888888888888oooooooooooooooP"
`"8oooooooooooooooooooooooooo"""""""""""""""
bullets .88888888888.`::: 8
go in here 88888888888Yo `` * 8 *pull this thingy here.
| .88888888888 `oooooooood8o ( <- this way <- )
`----> 88888888888'
.88888888888
88888888888'
.88888888888
98888888888'
``""YY888P <-- release clip here
(point bullet -> this way -> )
- release the long rectangular thing inside the handle (clip).
- put one (1) bullet in clip.
- stick the clip back into the handle.
- pull back on the handle until it clicks, then let go.
- put knobby thing into your mouth.
- breathe in.
- pull the pointy thing that sticks down (see *).
With this:
I copied this out of a book, saved it as test and did a chmod
on it yet I still get it to work. What am I doing wrong?
--------------cut here--------------------
#!/usr/local/bin/perl
print "Hiya planet";
--------------cut here--------------------
advTHANKSance
--
Chris J User chuser@host.fqn.tld 'Iroquoise' on irc
http://www.host.fqn.tld/~chuser
I think it is a safe bet that Chris gets a better answer than Rod.
Both of them left out lots of information that could help. The
obvious answer is a conflict between /bin/test and the script, but
if it was invoked as "./test" that would not be an issue, and it
could be that the path to perl is wrong or some other simple error.
Elijah
------
both Chris and Rod need to be corrected to have a \n in the print statement
------------------------------
Date: 6 May 1997 06:26:20 GMT
From: zbaker@venom.st.hmc.edu (Zach Baker)
Subject: Re: Perl auto-replier
Message-Id: <5kmiuc$85j$1@cinenews.claremont.edu>
In article <3369EC59.34E18A7F@absyss.fr>, Douglas Seay <seay@absyss.fr> wrote:
>comp.lang.perl.misc is mostly just a question and answer session, I
>don't see the advantage of turning it into a questions only session.
I was fancying the idea of a comp.lang.perl.questions with all manner
of questions about perl, and a moderated comp.lang.perl.answers that
had FAQs and pointers like other .answers groups, *plus* answers to
general or specific questions seen in .questions as well. After all,
posters with questions don't want to read questions either; they're
looking for answers, so give them a place to find what they want, even
it's in a (whoa!) FAQ. To discourage answers in the .questions group,
automail could be sent to posters of followups, explaining that it's
not for answers or discussions (unless perhaps they use the magic RE
/clarif/ in their followup).
---
Zach Baker <zbaker@venom.st.hmc.edu>
"Best of everything, we go to that."
------------------------------
Date: Tue, 06 May 1997 10:25:57 +0100
From: Douglas Seay <seay@absyss.fr>
Subject: Re: Perl auto-replier
Message-Id: <336EF924.62E9EFB6@absyss.fr>
Zach Baker wrote:
>
> In article <3369EC59.34E18A7F@absyss.fr>, Douglas Seay <seay@absyss.fr> wrote:
> >comp.lang.perl.misc is mostly just a question and answer session, I
> >don't see the advantage of turning it into a questions only session.
>
> I was fancying the idea of a comp.lang.perl.questions with all manner
> of questions about perl, and a moderated comp.lang.perl.answers that
> had FAQs and pointers like other .answers groups, *plus* answers to
> general or specific questions seen in .questions as well. After all,
> posters with questions don't want to read questions either; they're
> looking for answers, so give them a place to find what they want, even
> it's in a (whoa!) FAQ. To discourage answers in the .questions group,
> automail could be sent to posters of followups, explaining that it's
> not for answers or discussions (unless perhaps they use the magic RE
> /clarif/ in their followup).
No, I don't think this would work. Nice idea to have an answers digest,
but the FAQ and deja news already do something of the sort and they
aren't utilized. And I don't know about the others, but I wouldn't read
a questions only group, I would just read the answers. In today's
setup, I read most everything from those I consider well informed and I
skim the rest (both questions and answers). The people that interest me
would only be on the answer group (when was the last time Randal posted
a question?) so that is what I'd read.
- doug
------------------------------
Date: 5 May 1997 23:53:18 -0400
From: clay@panix.com (Clay Irving)
Subject: Re: PERL Editor
Message-Id: <5km9ve$5dh@panix.com>
In <5kl5fa$fnb@uwm.edu> mjb1@alpha3.csd.uwm.edu (Michael James Braunstein) writes:
>Kyzer wrote:
>: Dick Barker of dickb@eskimo.com wrote in comp.lang.perl.misc:
>: : Real perl programmers use cat >fname to write their stuff.
>: Actually they use emacs.pl :)
>:
>emacs.pl, where can i get it, or is this just a euphemism for somthing
>else?
Turn around. Let me pull your other leg...
--
Clay Irving See the happy moron,
clay@panix.com He doesn't give a damn,
http://www.panix.com/~clay I wish I were a moron,
My God! Perhaps I am!
------------------------------
Date: 5 May 1997 17:47:02 GMT
From: exidor@superior.net (Christopher Masto)
Subject: Re: program for perl?
Message-Id: <5kl6em$nn8@snews2.zippo.com>
In article <8cu3kmuhqm.fsf@gadget.cscaper.com>,
Randal Schwartz <merlyn@stonehenge.com> wrote:
>>>>>> "Suzanne" == Suzanne L <suzanne@intrepid.axess.com> writes:
>
>Suzanne> Is there a program that is needed to write in perl or can they be
>Suzanne> written in any text editor?
>
>Any text editor will do. My favorite is:
>
> $ cat >myscript
> #!/usr/bin/perl
> ... [rest of script]
> ...
> ^D
> $ chmod +x myscript
> $ ./myscript
> [runs perfectly]
> $
Hmm... now doesn't this qualify for the "useless use of cat" award?
Certainly it would be much more effecient to just use:
$ /usr/bin/perl
... [script]
...
^D
I'm shocked, simply shocked at this needless verbosity. Randal, you
should know better.
:-)
--
Christopher Masto . . . .
chris@masto.com . . . . . Masto Consulting: info@masto.com
perl -e 'map{vec($x,$_>$}?$_+$y:$_+($y+=8),1)=1;$}=$_}split//,"12360123".
------------------------------
Date: Tue, 06 May 1997 02:15:33 -0500
From: Andrew Johnson <ajohnson@gpu.srv.ualberta.ca>
Subject: Re: program for perl?
Message-Id: <336EDA95.60C00173@gpu.srv.ualberta.ca>
Christopher Masto wrote:
! Randal Schwartz <merlyn@stonehenge.com> wrote:
! >>>>>> "Suzanne" == Suzanne L <suzanne@intrepid.axess.com> writes:
! >
! >Suzanne> Is there a program that is needed to write in perl or can they be
! >Suzanne> written in any text editor?
! >
! >Any text editor will do. My favorite is:
! >
! > $ cat >myscript
! > #!/usr/bin/perl
! > ... [rest of script]
! > ...
! > ^D
! > $ chmod +x myscript
! > $ ./myscript
! > [runs perfectly]
! > $
!
! Hmm... now doesn't this qualify for the "useless use of cat" award?
! Certainly it would be much more effecient to just use:
!
! $ /usr/bin/perl
! ... [script]
! ...
! ^D
!
! I'm shocked, simply shocked at this needless verbosity. Randal, you
! should know better.
of course Randal's version actually creates the program so
you don't have to type it all in to run it each time.
However, why not use the perl IDE to enter, create, and run
your perl programs?
[prompt]$ perl
$script=<<'END_SCRIPT';
#!/usr/bin/perl -w
$string="\nHello World\n";
print $string;
END_SCRIPT
$scriptname="myscript.pl";
open(SCRIPT,">$scriptname")||die "can't do it $!";
print SCRIPT $script;
close SCRIPT;
chmod 0755, $scriptname;
system($scriptname);
^D
Hello World
[prompt]$ ./myscript.pl
Hello World
[prompt]$
:-)
regards
andrew
------------------------------
Date: Mon, 5 May 1997 20:42:46 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Reading data from a file and outputting to another file
Message-Id: <ma2mk5.cm1.ln@localhost>
Gaylon Stockman (stockman@rdbewss.redstone.army.mil) wrote:
: Disclamier - I am trying to learn Perl.
: I have the Camel and LLama books - been there, done that on trying
: to extract from the examples.
: I am trying to write a Perl script to extract data from an input
: file and output the required info to another file. I have had
: some success to date - but not much. Could someone lend a hand ??
: Possibly provide a small example ??
OK.
: Here is what I have.
: I have a input file that follows a loosely formatted structure.
^^^^^^^^^^^^^^^^^
That will, of course, be problematic, as the format is what is
keyed on to indentify fields...
: I should be able to key off some of the "descriptions" that are
: on the same line as the data. I would like to extract certain
: records and output those records as one line in a output file.
: The input file structure is as follows:
: records not needed
: START_VEHICLE_PARAMS is the start of the data
But you don't really need to match against it if 'ENUMERATION TYPE'
is always present to tell you when to output what you have so far.
: next 3 lines need to extract data or key off of the descriptions
: on the right hand side. This way if the format changed the
: descriptions would remain the same (??)
: search for ENUMERATION TYPE and get data at the front of that record
: output extracted info to a file
: start over by looking for START_VEHICLE_PARAMS again and get data
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Your example showed that these lines are formatted differently.
If you can get them to be a constant string, then you may want to
look into the "input record separator" (set via $/ variable) in the
perlvar man page.
: until end of file is reached
: I can write this in a higher level language w/o a problem, but I
^^^^^^^^^^^^^^^^^^^^^
What did you mean here? I would say that 'C', for instance, is a
_lower_ level language than Perl...
: believe this should be something that is very easily well suited for
: Perl. Maybe I am making it more difficult than it really is.
Perl was created for just this sort of thing.
: Below is a sample input file and sample output file of what I am
: looking for. Can someone provide an example of something that will
: do this or something along the same lines ?? I probably am just
: missing something on syntax.
[ snip data, it's repeated in my example script ]
: ** output file **
: Number Index Descrption Class Enumeration
: 1 1 'BIG_CAR' 'CADDY' 1 1 222 1 1 0 0
: 2 2 'BIG_TRUCK' 'F150' 1 2 225 3 1 4 0
I can't generate that output from that input. There is part of the
second record missing (it never gets to 'ENUMERATION TYPE').
I can generate only one line of table, 'cause I only had one
(complete) input record.
: Any help or pointers are greatly appreciated.
This should get you started:
-----------------------------
#!/usr/bin/perl -w
$record = 1;
while (<DATA>) {
$index = $1 if /^\s+(\d+).*'TYPE INDEX'/;
$desc = $1 if /^\s+'([^']+)'.*'VEHICLE DESCRIPTION'/;
$class = $1 if /^\s+'([^']+)'.*'VEHICLE CLASS DESCRIPTION'/;
if ( /^\s+([\d ]+\d)\s+'ENUMERATION TYPE'/) {
printf("%-5d %-5d %s %s %s\n", $record++, $index, $desc,
$class, $1);
}
}
__DATA__
..
..
..
!--------- START_VEHICLE_PARAMS --------
1 'TYPE INDEX'
'BIG_CAR' 'VEHICLE DESCRIPTION'
'CADDY' 'VEHICLE CLASS DESCRIPTION'
'BOSE_RADIO' 'COMM DEVICE DESCRIPTION'
1 'NUMBER OF RADIOS ON VEHICLE'
'BRIGHT_BEAM' 'HEADLIGHT TYPE(S) ON VEHICLE'
..
..
..
F,T,F 'YES,NO,MAYBE'
1 1 222 1 1 0 0 'ENUMERATION TYPE'
..
..
..
F,T,T 'YES,NO,MAYBE'
-----------------------------
--
Tad McClellan SGML Consulting
Tag And Document Consulting Perl programming
tadmc@flash.net
------------------------------
Date: Tue, 6 May 1997 07:17:14 GMT
From: adelton@fi.muni.cz (Honza Pazdziora)
Subject: Re: Singles and doubles
Message-Id: <adelton.862903034@aisa.fi.muni.cz>
christopher <mrchristopher@inorbit.com> writes:
> How can I define a string that contains stuff to be evaluated so that it
> isn't evaluated the first time it's defined but rather when it's used
> inside double quotes..
>
> So if anyone can tell me how to make this idea work..
>
> $stuff='$this+$that';
> $that=5;
> while <FILE> {
Does this work for you? --> while (<FILE>)
> $this++;
> $theanswer="10+$stuff";
> }
What will this give you? It will make a string in which the first part
will be '10+' and the second part, that comes grom $stuff, will be
'$this+$that', giving us 10+$this+$that. And you want this string to
be evaluated and in perl there is eval for that. So
$theanswer = eval "10+$stuff";
Will produce the correct answer.
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: Tue, 6 May 1997 05:56:55 GMT
From: dkcombs@netcom.com (David Combs)
Subject: unpack, $_, -w, and "uninitialized variable"
Message-Id: <dkcombsE9qwIv.MGu@netcom.com>
When I use "-w", 11 times I get this error:
Use of uninitialized value at uudecode.pl line 23, <> chunk N.
(where N is 2 through 11),
on the "unpack" line,
on this program (uudecode.pl, from book "perl-5 how-to":
$Found = 0;
while (<>) {
if (/^begin\s+(\d+)\s+(.*)/) {
$Mode = $1;
$FileName = $2;
$Found = 1;
last;
}
}
$Found || die "No begin line\n";
open (OUT,">$FileName") || die "Can't open $FileName\n";
while (<>) {
/^\s*$/ && next;
length() > 2 || next;
/^end$/ && last;
$Line = unpack("u",$_);
defined($Line) || die "Invalid uuencoded string\n";
print OUT $Line;
}
close(OUT);
chmod oct($Mode), $FileName;
On this input file:
begin 644 uu.pl
M)$9O=6YD(#T@,#L*=VAI;&4@*#P^*2.
M;R!B96=I;B!L:6YE7&XB.PH*;W!E;B`H3U54+"(^)$9I;&5.86UE(BD@?'P@
M9&EE(")#86XG="!O<&5N("1&:6QE3F%M95QN(CL*"G=H:6QE("@\/BD@>PH@
M("`@+UY<<RHD+R`F)B!N97AT.PH@("`@;&5N9W1H*"D@/B`R('Q\(&YE>'0[
M"B`@("`O7F5N9"0O("8F(&QA<W0["B`@("`D3&EN92`]('5N<&%C:R@B=2(L
M)%\I.PH@("`@9&5F:6YE9"@D3&EN92D@?'P@9&EE("));G9A;&ED('5U96YC
M;V1E9"!S=')I;F=<;B(["B`@("!P<FEN="!/550@)$QI;F4["GT*"F-L;W-E
D*$]55"D["F-H;6]D(&]C="@D36]D92DL("1&:6QE3F%M93L*
`
end
(which is that program itself, uuencoded).
I can't figure out what it is that is uninitialized.
I search the faq (which i got on 11mar97) for
uninitialized and unpack, saw nothing relevant.
I saw something in this group from Tom Phoenix about
a similar question, but that had to do with
a $backref from a regexp -- not this problem at all.
If not really anything wrong, how do I turn off
the -w for that one statement?
Thanks!
------------------------------
Date: Mon, 5 May 1997 23:30:29 -0000
From: david@zsi.com (David Schultz)
Subject: when moved from unix to nt breaks.....counting items in array
Message-Id: <MPG.dd87dedde06bb9c989682@newshost.waymark.net>
All,
I have a simple question.
I am simply trying to count the number of items in an array...on
unix...the following works..
$counter = @mylist;
Of course once moved to the nt machine..it fails to give any non zero
values.
Any Ideas??
David@zsi.com
------------------------------
Date: Mon, 05 May 1997 22:51:18 -0700
From: doug@sitewerks.com/nospam
Subject: Word 97 OLE broken?
Message-Id: <5kmh8o$h5h$1@brokaw.wa.com>
I'm having trouble using OLE with Word8 (Word 97).
I can't seem to get the application to be visible, the FileConverters
collection is empty and SaveAs doesn't want to work. The application
starts, I can open a file (I think, at least the Count goes up when I
do) and I can quit the application, but I can't seem to do any useful
stuff.
Here is an example in Perl, anyone have some working Perl or C code,
or had similar problems or successes?
Build 8.0.3514 of Word
NT 4.0
Any help would be appreciated
Thanks,
Doug
XPosted to microsoft.public.word.programming and comp.lang.perl.misc
P.S. remove the trainling /nospam to respond
--------------------------------------
use OLE;
$application = CreateObject OLE 'Word.Application.8' || die $!;
# none of the following or other atttemps to make the
# application visible worked, similar thing worked
# with word95, and MS-Project.
$application{'Visible'}="True";
sleep 4;
$application{'Visible'}=True;
sleep 4;
$application{'Visible'}=0;
sleep 4;
$application->Visible(True);
# This comes back empty
$fileconverters = $application->$FileConverters();
print "[fileconverters]", $fileconverters, "\n";
#The following line gives an error because FileConverters is empty
$numConverters = $application->FileConverters->Count();
$documents = $application->documents();
$aDoc = $documents->Open("C:\\junk.doc");
#This seems to work
$numDocs = $documents->Count();
print "[numDocs]", $numDocs, "\n";
# This gives the correct response
print "[FullName]", $aDoc->FullName(), "\n";
print "[SaveFormat]", $aDoc->SaveFormat(), "\n";
$aDoc->Activate();
# this doesn't fail but it doesn't work either :(
$application->ActiveDocument->SaveAs("c:\\junk2.doc");
$application->Quit();
------------------------------
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 438
*************************************