[12879] in Perl-Users-Digest
Perl-Users Digest, Issue: 289 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jul 28 22:07:39 1999
Date: Wed, 28 Jul 1999 19:05:10 -0700 (PDT)
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, 28 Jul 1999 Volume: 9 Number: 289
Today's topics:
Re: Any Suggestions? <emschwar@rmi.net>
Re: Beginner needs help with a function (Abigail)
Re: Beginner needs help with a function (Abigail)
Re: Beginner needs help with a function (Abigail)
Re: Beginner-friendly group as cultural adaptation? (Alan Stewart)
Re: Easy way to emulate Unix's "sort" command? <emschwar@rmi.net>
Re: Easy way to emulate Unix's "sort" command? (Eric Bohlman)
Re: eval (Abigail)
Re: eval (Abigail)
Re: File maintenance algorithm required (Abigail)
Re: Find::File -- skipping a directory? (Neko)
Re: help running Perl Scripts in win95 <cassell@mail.cor.epa.gov>
Re: help w/command line argument (Abigail)
Re: help with vars (elephant)
Re: help with vars <tfiedler@ptd.net>
Re: help with vars <laurens@bsquare.com>
Re: help with vars (Steven Smolinski)
Re: help with vars <warish@concentric.net>
Re: How to find first occurance of white space... (Abigail)
Modules, How? vitanut@my-deja.com
Re: Modules, How? <cassell@mail.cor.epa.gov>
Re: Newbie Q: Replacing a string by an array (Abigail)
Parsing \t delimited <asquith@macconnect.com>
Re: Parsing \t delimited (Eric Bohlman)
Perl Question kaz@eudoramail.com
Re: perl to excel makarand_kulkarni@my-deja.com
Re: Q: compare two arrays (Abigail)
Re: Reading the binary files in Perl <cassell@mail.cor.epa.gov>
Re: ref() return value... (Neko)
Re: reg expression (Steven Smolinski)
Re: Selecting files by permisions (Abigail)
substitute fcntl for flock (Phil)
Re: Using regular expressions in $\ (Eric Bohlman)
Win32::ODBC error <cpelkey@mindspring.com>
Digest Administrivia (Last modified: 1 Jul 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 28 Jul 1999 19:46:20 -0600
From: Eric The Read <emschwar@rmi.net>
Subject: Re: Any Suggestions?
Message-Id: <xkfiu74jkib.fsf@valdemar.col.hp.com>
revjack <revjack@radix.net> writes:
> It's funny - while looking for something else on the perl.com "Perl and
> CGI FAQ" a few minutes ago, I noticed this:
>
>
> Q2.1: Should I use the Perl CGI modules to code all
> my CGI scripts? Isn't it easier to do it myself?
>
> It really depends on what you are trying to do. The
> CGI modules should generally be used for heavy-duty
> CGI scripts. For simple scripts, its is far easier
> and quicker to roll your own or use CGI Lite (current
> version is v1.62). If you really want, you can even
> use the old Perl 4 cgi-lib.pl library.
>
>
> "easier and quicker to roll your own". Hm.
*IF* you know what you're doing. As has been demonstrated umpteen
bazillion times on this very 'froup, most people who do their own CGI
decoding do not. I venture to say that most people don't care that much
about the overhead involved in CGI.pm or CGI::Lite.pm, and those that do
are better off, generally, using mod_perl.
I'd suggest an amendment to the FAQ. Before submitting the diff, lemme
try this on you guys for size (critique at will):
It really depends on what you are trying to do. The
CGI and CGI::Lite modules should generally be used for
most CGI purposes. If you still feel, after testing
the above, that you want to use your own module, then
be sure to read the documentation for CGI, available
at <URL:http://www.w3.org/CGI/>.
> Of course, you're right that the above cargo-cult code chunk has
> many flaws.
Yes, and having read that bit of the FAQ (never needed to before), I'm
concerned that the FAQ is undermining all the work we do here to get
people using standardized modules. The rule of thumb I use is: Use a
module first. If that doesn't work, only *then* try to roll your own.
-=Eric
------------------------------
Date: 28 Jul 1999 19:52:35 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Beginner needs help with a function
Message-Id: <slrn7pv9dl.4oo.abigail@alexandra.delanet.com>
Alec Kelingos (akelingos@petrosys-usa.com) wrote on MMCLVII September
MCMXCIII in <URL:news:01bed909$73961020$7637ebcf@psusa6.petrosys-usa.com>:
\\
\\ and trim the string if inclosed by the specified character, otherwise leave
\\ it alone? Perhaps some niffty regular expression.
Perhaps. Did you bother looking at the regex manpage? Did you try writing
any code? Did you look at the FAQ, that explains how to do this for spaces?
Or are you just looking for someone who gives you the answer, without you
doing anything?
Abigail
--
package Just_another_Perl_Hacker; sub print {($_=$_[0])=~ s/_/ /g;
print } sub __PACKAGE__ { &
print ( __PACKAGE__)} &
__PACKAGE__
( )
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: 28 Jul 1999 19:58:33 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Beginner needs help with a function
Message-Id: <slrn7pv9oq.4oo.abigail@alexandra.delanet.com>
Tobias Galitzien (tg@channel-one.de) wrote on MMCLVII September MCMXCIII
in <URL:news:7nn8vv$gnf$1@news.is-europe.net>:
[] I R A Darth Aggie <fl_aggie@thepentagon.com> wrote:
[]
[] > + I need a function to trim the first/last characters off a string if and
[] > + only if these characters are a user defined character.
[]
[] I assume "c" is your character you want to strip.
[]
[] So do a
[] $string =~ s/^c+//g;
[] to strip the c's at the beginning, and a
[] $string =~ s/c+$//g;
[] to strip them at the end.
[]
[] Maybe there is a way to do this with only one command, I would be glad to
[] hear about it.
*boggle* I find this unbelievable.
Darth was referring to the faq. The faq that has exactly the above code,
except it's using whitespace instead of "c". And, in the same section,
*preceding* the 2 regex solution, gives you a single regex. It also
explains why the single regex shouldn't be used.
Abigail
--
perl5.004 -wMMath::BigInt -e'$^V=Math::BigInt->new(qq]$^F$^W783$[$%9889$^F47]
.qq]$|88768$^W596577669$%$^W5$^F3364$[$^W$^F$|838747$[8889739$%$|$^F673$%$^W]
.qq]98$^F76777$=56]);$^U=substr($]=>$|=>5)*(q.25..($^W=@^V))=>do{print+chr$^V
%$^U;$^V/=$^U}while$^V!=$^W'
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: 28 Jul 1999 20:05:58 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Beginner needs help with a function
Message-Id: <slrn7pva6p.4oo.abigail@alexandra.delanet.com>
Larry Rosler (lr@hpl.hp.com) wrote on MMCLVII September MCMXCIII in
<URL:news:MPG.1208c86f8b557b8b989d60@nntp.hpl.hp.com>:
--
-- #!/usr/local/bin/perl -w
-- use strict;
--
-- print trim_char("|foo\nbar|", '|'), "\n";
--
-- sub trim_char {
-- my ($string, $char) = (shift, quotemeta shift);
-- $string =~ s/^$char(.*)$char\z/$1/s;
-- $string
-- }
-- __END__
--
And here's a non-regex solution:
sub trim_char {
$_ [1] eq substr ($_ [0], 0, 1) &&
$_ [1] eq substr ($_ [0], -1, 1) ? substr ($_ [0], 1, -1) : $_ [0];
}
Abigail
--
sub f{sprintf'%c%s',$_[0],$_[1]}print f(74,f(117,f(115,f(116,f(32,f(97,
f(110,f(111,f(116,f(104,f(0x65,f(114,f(32,f(80,f(101,f(114,f(0x6c,f(32,
f(0x48,f(97,f(99,f(107,f(101,f(114,f(10,q ff)))))))))))))))))))))))))
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: Thu, 29 Jul 1999 01:07:34 GMT
From: astewart@spawar.navy.mil (Alan Stewart)
Subject: Re: Beginner-friendly group as cultural adaptation?
Message-Id: <379fa671.1662618909@news.pwy1.sdca.home.com>
On Tue, 27 Jul 1999 09:39:06 GMT, bart.lateur@skynet.be (Bart Lateur)
wrote:
. . .
>
>Hah!
>
>How about "off topic" questions, then? This newsgroup is very intolerant
>with regards to what it considers off-topic. It's not just CGI, although
>that is quite a typical example. "How do I run a Perl script on a
>regular basis", or "Why can I not create a file in this directory?", are
>other examples.
>
The regulars are only very intolerant of off-topic discussions when
they are initiated by newbies. If a topic wanders off (or starts) on
some arcane discussion of English grammar or poetry or corrected
quotations from Shakespeare, the regulars chime in with glee.
I believe that the regulars encourage newbies to break rules by
setting bad examples for them. If they can burn bandwidth on non-Perl
subject, why can't the newbie waste bandwidth on something that is (in
his mind) at least relevant to Perl.
As one of those normally silent people, who read the books, read the
news, and normally solve their own problems, I find it easier to
filter newbies than to distinguish between the good stuff that certain
regulars put out from the routine bitching and intellectual
fan-dancing.
I make this criticism because I value highly the Perl wisdom of some
people here, but neither Perl nor the perl groups are the primary
focus of my life, and noise control would make reading more efficient.
I find that to avoid missing interesting bits, my time is equally
wasted by newbies and gurus.
------------------------------
Date: 28 Jul 1999 18:22:42 -0600
From: Eric The Read <emschwar@rmi.net>
Subject: Re: Easy way to emulate Unix's "sort" command?
Message-Id: <xkflnc0jodp.fsf@valdemar.col.hp.com>
"Paul Glidden" <paul.glidden@unisys.com> writes:
> Somebody else, whose attribution he snipped, wrote:
> >Doh! I'll certainly peruse the FAQs next time; I didn't think the
> >help was that elaborate!
>
> Don't be too upset about it, I hate reading those things, sometimes the
> explanations are just not up to snuff, that's where a book like the camel
> comes in handy.
Not up to snuff how? The FAQs are going to be up-to-date and have
current information; even the most recent Camel is still several
revisions out of date. The FAQs are also free, and come with Perl. The
Camel, while a good book (and it was worth the money I paid for it) costs
money.
BTW, please put your replies *after* the text you're replying to; human
minds don't work like a game of Jeopardy.
-=Eric
------------------------------
Date: 29 Jul 1999 00:41:30 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: Easy way to emulate Unix's "sort" command?
Message-Id: <7no7vq$dd@dfw-ixnews6.ix.netcom.com>
Jim Hutchison (jimhutchison@metronet.ca) wrote:
: On 28 Jul 1999 13:17:51 -0600, Eric The Read <emschwar@rmi.net> wrote:
:
: >jimhutchison@metronet.ca (Jim Hutchison) writes:
: >> Newbie question here...
: >
: >Next time you feel yourself about to type this, read the FAQ, because
: >your answer's probably in there. As it is this time.
:
: Doh! I'll certainly peruse the FAQs next time; I didn't think the
: help was that elaborate!
You've just discovered one of Perl's biggest strengths. Can you think of
*any* other language where the default installation comes with such a
complete set of *free* documentation? One that can teach you far more
than a $1000 seminar could?
------------------------------
Date: 28 Jul 1999 20:11:14 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: eval
Message-Id: <slrn7pvagk.4oo.abigail@alexandra.delanet.com>
renorum@my-deja.com (renorum@my-deja.com) wrote on MMCLVII September
MCMXCIII in <URL:news:7nna98$38d$1@nnrp1.deja.com>:
&& I am trying to use eval to call a certain subroutine depending on the
&& value of a given variable:
&&
&& eval($action());
&&
&& where $action could be either "add" or "delete" or "edit". I have
&& written the subroutines add(), delete() and edit().
&&
&& Am I using this correctly? (because it doesn't seem to be working) Is
&& this not what eval is used for? Is there some better way to effect
&& this result (other than the obvious
&& if ($action eq "add") { add(); }
&& elsif ($action eq "delete") { delete(); } ...etc, etc.)
No, that's not correct, but you don't need the if/elsif chain either.
If you want to use eval, you've got to use a string:
eval "$action()";
But, you can also do:
&$action ();
but that's not allowed under "strict refs", which you should enable.
You can do:
$action = \&add; # Or \&delete; or \&edit;, etc.
...
&$action (); # Or:
$action -> ();
I'd use the latter variant.
Abigail
--
perl -wlne '}print$.;{' file # Count the number of lines.
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: 28 Jul 1999 20:18:54 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: eval
Message-Id: <slrn7pvav0.4oo.abigail@alexandra.delanet.com>
Larry Rosler (lr@hpl.hp.com) wrote on MMCLVII September MCMXCIII in
<URL:news:MPG.1208d9e71ff68648989d64@nntp.hpl.hp.com>:
::
:: #!/usr/local/bin/perl -w
:: use strict;
::
:: my %subs = ( add => \&add, delete => \&delete, edit => \&edit );
::
:: sub add { 'add' } sub delete { 'delete' } sub edit { 'edit' }
::
:: my $action = 'add';
::
:: print &{$subs{$action} || die "No sub '$action'\n"};
Why this extra level of indirection?
#!/opt/perl/bin/perl -w
use strict;
sub add { 'add' } sub delete { 'delete' } sub edit { 'edit' }
my $action = \&add;
print & {$action || die "No sub '$action'\n"};
print do {$action || die "No sub '$action'\n"} -> ();
Abigail
--
perl -e '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %;
BEGIN {% % = ($ _ = " " => print "Just Another Perl Hacker\n")}'
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: 28 Jul 1999 20:20:30 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: File maintenance algorithm required
Message-Id: <slrn7pvb20.4oo.abigail@alexandra.delanet.com>
Roger Musson (roger@wheelpro.co.uk) wrote on MMCLVII September MCMXCIII
in <URL:news:379f3b06.3798475@nntp.netcomuk.co.uk>:
~~ I need to add a line of data to the front of a file (i.e. not
~~ appending). The file is several thousand lines long and about 5mb file
~~ size.
~~
~~ I am using the following at the moment (psuedo code shown)
~~
~~ create TEMP
~~ print new line to TEMP
~~ while (<DATA>)
~~ print to TEMP
~~ rename TEMP, DATA
~~
~~ Is there a better, faster method?
No, unless you want to use something else than "flat" files.
But you might want to rethink why you want to add lines in the front.
Abigail
--
package Just_another_Perl_Hacker; sub print {($_=$_[0])=~ s/_/ /g;
print } sub __PACKAGE__ { &
print ( __PACKAGE__)} &
__PACKAGE__
( )
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: 29 Jul 1999 00:33:58 GMT
From: tgy@chocobo.org (Neko)
Subject: Re: Find::File -- skipping a directory?
Message-Id: <7no7hm$3u5$0@216.39.141.200>
On Wed, 28 Jul 1999 18:47:54 -0400, planb@newsreaders.com (J. Moreno) wrote:
>Am, I missing something or is there no way to skip a directory when
>using Find::File?
>
>Please, someone tell me I'm missing something...
use File::Find; # Not Find::File.
find sub {
return if -d $File::Find::name; # Skip all directories.
print;
}, '/foo/bar';
--
Neko | tgy@chocobo.org | Will hack Perl for a moogle stuffy! =^.^=
------------------------------
Date: Wed, 28 Jul 1999 17:31:40 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: help running Perl Scripts in win95
Message-Id: <379FA0EC.3DF5A894@mail.cor.epa.gov>
Lauren Smith wrote:
> [snip]
> use God::Omniscience;
> &WhatIsGoingOn($no_clue_as_to_what_is_supposed_to_happen);
>
> output:
> I have no idea.
>
> *sigh* Not all problems can be solved, it seems.
Well then, try the PSI::ESP module, which occasionally works
for me.. as long as no one uses their PSI::ESP module to block
me [parapsychology in-joke].
Hmmm... let's see... the clouds are parting... Oh.
He's probably clicking on files ending with .pl, and win95
is trying to execute them. A DOS command window flashes
on-screen and then vanishes.
Mark will have to read the docs and learn that Perl is not
a pre-compiled executable, but a real programming language
in which one writes code, then runs it.. usually from an
open Command Prompt window or from another program. He
should start with the Perl On-line Documentation shortcut
that is sitting on his Start Menu [unless his install was
botched]. This will pop up an HTML document that he can
browse and learn from.
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: 28 Jul 1999 20:23:02 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: help w/command line argument
Message-Id: <slrn7pvb6p.4oo.abigail@alexandra.delanet.com>
sn0brdr@yahoo.com (sn0brdr@yahoo.com) wrote on MMCLVII September MCMXCIII
in <URL:news:7nne5g$62q$1@nnrp1.deja.com>:
.. hi,
..
.. i'm a (perl) newbie w/a question re: command line argument.
..
.. what should i use to do:
.. progname arg(s)
..
.. i was able to use Getopt::Std, but i'm trying to make this proggie
.. easier for the end users so they don't have to memorize the switches.
Then I would write my program such that it doesn't take switches!
.. the ability to see output and error would be great.
To do that, I would upgrade my users with "Eye Patch VI".
.. what is your suggestion?
Well.... what is your question?
Abigail
--
srand 123456;$-=rand$_--=>@[[$-,$_]=@[[$_,$-]for(reverse+1..(@[=split
//=>"IGrACVGQ\x02GJCWVhP\x02PL\x02jNMP"));print+(map{$_^q^"^}@[),"\n"
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: Thu, 29 Jul 1999 10:09:52 +1000
From: e-lephant@b-igpond.com (elephant)
Subject: Re: help with vars
Message-Id: <MPG.120a46d0eab72b84989b9d@news-server>
ted fiedler writes ..
<code gone>
>i have this reading a file that looks like this:
>
>name joe blow
>name john q public
>account 123456
>account 123456
>balance 234.56
>balance 3456.78
I'm guessing that the output you're after is this ??
joe blow, 123456, 234.56
john q public, 123456, 3456.78
in which case .. no - your code doesn't even come close
>what am i doing wrong? this doesnt work...
well - apart from forgetting to close the second 'if' statement and using
a really WEIRD regex construct ([\S\s\w]*) ?????? .. \s and \S are
compliments of each other .. so you've just said everything including the
newline .. you might just want (.*) which will exclude the newline
so - apart from that - the while(<FILEHANDLE>) construct loops through
the file .. on each iteration it sets $_ to the value of the record
(usually a newline delimited record - but this is actually dependant on
$/)
so basically you're looping 6 times .. and each time through the loop $_
is set to the text on each one of the lines .. hence you will get six
outputs .. none of them being what you want
to be honest I can't think of any simple way of doing what you want .. if
there's not much data then you could read each set of lines into a
separate array and loop over those
if there is heaps of data then that might be too memory hungry .. I'd
split the files up into separate temporary files .. and then iterate over
those all at once
this is probably something that someone else has dreamed up an excellent
solution for .. if you're lucky
--
jason - remove all hyphens for email reply -
------------------------------
Date: Thu, 29 Jul 1999 00:57:02 GMT
From: "ted fiedler" <tfiedler@ptd.net>
Subject: Re: help with vars
Message-Id: <yFNn3.43$Q8.7657@nnrp1.ptd.net>
what im actually trying to do is come up with an output that looks something
like this
joe public, 12345, 27.65
jonh anon, 14565, 22.33
my file doesnt have to look like
>name joe blow
>name john q public
>account 123456
>account 123456
>balance 234.56
>balance 3456.78
i can have these in separate files
but i need to have all fields named as variables and later output...
the file im pulling from looks like this:
008
PAGE 1
015 JOHN DOE
1 1108 WATSON ST.
1 SOMEWHERE PA 19994-0000
1 03/22/99 005673-1
200.00
2 96 1
2 YOUR MINIMUM MONTHLY PAYMENT AMOUNT IS... 50.00
027 07/06/90 BALANCE FORWARD 848.00 I: 440.00-
65.00
1 5-1203 -JEC OFFICE P: 343.00-
1 DUE FROM PATIENT, INS. A/R AT LEAST 04 MTHS OLD.
2 02/06/91 OFFICE/OUT-PT.SERVICE,LTD 45.00
45.00
1 5-1303 -JEC 90050 820.09 OFFICE
1 02/06/91 X-RAY HIP, COMP. MIN 2 VI 90.00
90.00
1 5-1303 -JEC 73510 820.09 OFFICE
061 *** *** *** *** ***
2 .00 .00 .00 200.00 200.00
im kinda screwed cause my boss is expecting some results and im a little
over my head
------------------------------
Date: Wed, 28 Jul 1999 18:24:25 -0700
From: "Lauren Smith" <laurens@bsquare.com>
Subject: Re: help with vars
Message-Id: <7noagp$o45$1@brokaw.wa.com>
ted fiedler wrote in message ...
>what im actually trying to do is come up with an output that looks
something
>like this
>joe public, 12345, 27.65
>jonh anon, 14565, 22.33
Sounds like a job for <insert fanfare> 'print()'.
>my file doesnt have to look like
>>name joe blow
>>account 123456
>>balance 234.56
But there must be some way to differentiate between different fields.
>the file im pulling from looks like this:
>008
>PAGE 1
>015 JOHN DOE
> 1 1108 WATSON ST.
> 1 SOMEWHERE PA 19994-0000
> 1 03/22/99 005673-1
>200.00
> 2 96 1
> 2 YOUR MINIMUM MONTHLY PAYMENT AMOUNT IS... 50.00
>027 07/06/90 BALANCE FORWARD 848.00 I: 440.00-
etc.
Now, there's a lot of information here. Take it slow and figure out which
fields you need to extract.
1) $name. The customer name is on line 015. Is it always on 015? How do
you know you're looking at a name when reading the file? Once you know how
to find the field, put the contents of the field into $name.
2) $account. Do the same thing as #1.
3) $balance. Do it again for this field.
4) print "$name, $account, $balance";
>
>im kinda screwed cause my boss is expecting some results and im a little
>over my head
sorry to hear...
Lauren
------------------------------
Date: 29 Jul 1999 01:36:48 GMT
From: sjs@yorku.ca (Steven Smolinski)
Subject: Re: help with vars
Message-Id: <slrn7pv7np.gu.sjs@frisco.gulch.com>
ted fiedler <tfiedler@ptd.net> wrote:
[...snip code...]
=i have this reading a file that looks like this:
=
=name joe blow
=name john q public
=account 123456
=account 123456
=balance 234.56
=balance 3456.78
=
=what am i doing wrong? this doesnt work...
I gave it a shot. It works on my 2.2.5 linux system with perl 5.005_02
when the data file's name is "testfile" and is in the same directory as
the script. I might not be as robust as you'd like, but oh well:
------------------------8<---------------------------------
#!/usr/bin/perl -w
use diagnostics;
use strict;
use vars qw|@names @accounts @balances $index|;
open( HEADER, "testfile" ) or die "Couldn't open testfile: $!";
while ( <HEADER> ) {
chomp;
if ( s/^\w*name +//i ) { push @names , $_ }
elsif ( s/^\w*account +//i ) { push @accounts, $_ }
elsif ( s/^\w*balance +//i ) { push @balances, $_ }
elsif ( /^\w*$/ ) { }
else { print STDERR "Error: Corrupt testfile\n"; }
}
close( HEADER ) or die "Couldn't Close testfile??\n$!";
for ( 0 .. $#names ) {
$index = $_;
write;
}
format STDOUT_TOP =
NAME ACCOUNT # BALANCE
------------------- --------- ----------
.
format STDOUT =
@<<<<<<<<<<<<<<<<<< @>>>>>>>> @######.##
$names[$index], $accounts[$index], $balances[$index]
.
--------------8<----------------------------------------
Steve
------------------------------
Date: 28 Jul 1999 18:58:49 PDT
From: "Warren Bell" <warish@concentric.net>
Subject: Re: help with vars
Message-Id: <7nocgp$f12@journal.concentric.net>
ted fiedler wrote in message ...
>#!/usr/bin/perl
>open(HEADER,"< oput/marriage");
>while(<HEADER>) {
> if( /name ([\S\s\w]*)/) {
> $name=$1;
> }
> if( /account (\S*)/) {
> $account=$1;
> if( /balance (\S*)/) {
> $balance=$1;
> }
> print"$name,$account,$balance\n";
>}
>
>
>i have this reading a file that looks like this:
>
>name joe blow
>name john q public
>account 123456
>account 123456
>balance 234.56
>balance 3456.78
>
>what am i doing wrong? this doesnt work...
>
>
>
>thanks
>ted
>
>
>
Here is how I would do it.
Set you file up like this if it is not too big:
joe blow|123456|234.56
john q public|123456|3456.78
Write your code like this:
open(HEADER,"< oput/marriage");
while(<HEADER>) {
chomp;
($name,$account,$balance) = split(/\|/,$_);
print"$name,$account,$balance\n";
}
close(HEADER);
Hope this helps.
------------------------------
Date: 28 Jul 1999 20:24:37 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: How to find first occurance of white space...
Message-Id: <slrn7pvb9o.4oo.abigail@alexandra.delanet.com>
cramey@my-deja.com (cramey@my-deja.com) wrote on MMCLVII September
MCMXCIII in <URL:news:7nngf9$7kq$1@nnrp1.deja.com>:
{} i have a string that i would like to shorten to the data before the
{} first space,
{}
{} ex.
{}
{} 123456 don't want any of this text in string
{} ^^^^^^
{} need this
Well, could you show use some code that you tried, and indicate
what went wrong? Or are you looking for someone to write the
code for you?
Abigail
--
perl -we 'print split /(?=(.*))/s => "Just another Perl Hacker\n";'
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: Wed, 28 Jul 1999 23:59:39 GMT
From: vitanut@my-deja.com
Subject: Modules, How?
Message-Id: <7no5h8$lo1$1@nnrp1.deja.com>
I am interested in learning how to use Perl modules. I have some
experience with Perl, little experience with UNIX and barely understand
what object oriented programming is.
Any suggestions? books? sites? other resources?
Or do I need to broaden my knowledge base before I attempt to
understand modules.
Any help will be greatly appreciated.
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: Wed, 28 Jul 1999 17:47:33 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Modules, How?
Message-Id: <379FA4A5.D9086D88@mail.cor.epa.gov>
vitanut@my-deja.com wrote:
>
> I am interested in learning how to use Perl modules. I have some
> experience with Perl, little experience with UNIX and barely understand
> what object oriented programming is.
Start with 'perlmod'. Read it using perldoc or man or the
HTML pages in win32, or whatever you like.
> Any suggestions? books? sites? other resources?
There's more resources at perl.com [oddly enough]. But first
determine whether the info in perlmod is more advanced than you
want. If so, you can start with other perl doc sections.
The order given when you type:
perldoc perl
is a pretty effective way to work through the docs.
> Or do I need to broaden my knowledge base before I attempt to
> understand modules.
You may not need to broaden your knowledge base to *use*
Perl modules. They're very convenient. But if you want to
write Perl modules, you may need a bit more background..
like the perlmodlib section for example.
> Any help will be greatly appreciated.
HTH,
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: 28 Jul 1999 20:51:14 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Newbie Q: Replacing a string by an array
Message-Id: <slrn7pvcrl.4oo.abigail@alexandra.delanet.com>
Andrew Fry (andrewf@beausys.demon.co.uk) wrote on MMCLVII September
MCMXCIII in <URL:news:kCkLqCAxIun3Ew5R@beausys.demon.co.uk>:
==
==
== However, when I find the line and do the replacement, using a
== statement of the form s/$tag/@B/, and then print the new
== (modified) array A, it appears that each line in array B of the
== form xxx\n comes out as xxx\n FOLLOWED BY A SPACE.
== Why is this, and how can I get rid of this extra space ?
That's because you're interpolating an array. Look up what the $"
variable does. You can fix it by either setting $", or putting the
text you want in a scalar instead of an array.
Abigail
--
%0=map{reverse+chop,$_}ABC,ACB,BAC,BCA,CAB,CBA;$_=shift().AC;1while+s/(\d+)((.)
(.))/($0=$1-1)?"$0$3$0{$2}1$2$0$0{$2}$4":"$3 => $4\n"/xeg;print#Towers of Hanoi
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: Wed, 28 Jul 1999 18:37:31 -0500
From: "Asquith" <asquith@macconnect.com>
Subject: Parsing \t delimited
Message-Id: <7no4nl$1qre@enews3.newsguy.com>
I have file in following (ignore spaces):
COLUMN1 \t COLUMN2 \t SPECIALCODE\n
10/10/1998 \t 123 \t \n
10/11/1998 \t 213 \t EST\n
I am file reading through
$_ = <FH>;
chomp
@columns = split("\t", $_);
$ncol = scalar(@columns);
while(<FH>) {
chomp;
@line = split("\t",$_);
if($ncol ne scalar(@line)) {
die "Num. columns not equal\n");
}
# DO STUFF
}
There are obviously three columns on first line and the third, but
on the second line, @line = ( '10/10/1998', 123) instead of
@line = ( '10/10/1998', 123, undef);
Thus program die's. I need to capture the undef or null field value too,
but want to retain the column number check in an effort to trap inconsistent
files from the user.
Any suggestions?
-wha
------------------------------
Date: 29 Jul 1999 01:22:28 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: Parsing \t delimited
Message-Id: <7noack$dd@dfw-ixnews6.ix.netcom.com>
Asquith (asquith@macconnect.com) wrote:
: There are obviously three columns on first line and the third, but
: on the second line, @line = ( '10/10/1998', 123) instead of
: @line = ( '10/10/1998', 123, undef);
: Thus program die's. I need to capture the undef or null field value too,
: but want to retain the column number check in an effort to trap inconsistent
: files from the user.
:
: Any suggestions?
Your problem is that, by default, split() strips trailing null fields. A
visit to the documentation (perldoc -f split) will show you how to
override this behavior.
------------------------------
Date: Thu, 29 Jul 1999 01:18:48 GMT
From: kaz@eudoramail.com
Subject: Perl Question
Message-Id: <7noa5j$omv$1@nnrp1.deja.com>
Please someone tell me the difference between ".*" and ".*?"
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: Thu, 29 Jul 1999 00:23:29 GMT
From: makarand_kulkarni@my-deja.com
Subject: Re: perl to excel
Message-Id: <7no6tr$mq7$1@nnrp1.deja.com>
--
You can put data (tab delimited) in a file with
extension .xls. When excel tries to open ( import)
this file it will recognize this as a tab-delimited
file and with newline as a record separator and imports
it properly.
I think that Excel even has the capability to
import entire HTML tables.
---
In article <379EE7E9.BC93C4C2@swisslife.ch>,
Herger Peter <peter.herger@swisslife.ch> wrote:
> Hello
>
> I've extracted some datas from MIB tables using an perl script. Now
I've
> wrote this datas to an *txt File. How can I write this datas directly
to
> an Excel Sheet???
>
> Thanks
>
> Peter Herger
>
>
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: 28 Jul 1999 20:52:29 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Q: compare two arrays
Message-Id: <slrn7pvcu0.4oo.abigail@alexandra.delanet.com>
milan andric (m-andric@students.uiuc.edu) wrote on MMCLVII September
MCMXCIII in <URL:news:Pine.GSO.4.10.9907281321200.25364-100000@ux11.cso.uiuc.edu>:
%%
%% I'm a little baffled on how to compare two arrays and print the
%% elements that exist in both.
I'm a little baffled why you didn't read the FAQ.
Abigail
--
perl -e '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %;
BEGIN {% % = ($ _ = " " => print "Just Another Perl Hacker\n")}'
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: Wed, 28 Jul 1999 17:35:42 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Reading the binary files in Perl
Message-Id: <379FA1DE.AB1B2FBD@mail.cor.epa.gov>
bidyut@yahoo.com wrote:
>
> Hi there,
> I have a problem here. I have to use Perl to read a binary file ( that
> is produced by a C program) and parse the data out of it. Also to
> mention that I know the length of each record.
> So what I do is I read one record and use unpack() to parse the data.
> The problem is I am able to get all the string data, but unable to get
> any integer or float or short etc.
Are you using the correct template to get those integers and
floats out of the record? Probably not, according to my
PSI::ESP module.
But we can't help you further until you post a line or two of
code illustrating how you parse the record, with perhaps a record
or two of illustrative data.
> When i was going through Java FAQ, I found out that Java reads it
> differently than the C program. So i am curious whether is there a
> similar case in Perl or what. If so, then how to get around it and if
> not, then why am I having problem in reding numeric data types.
Perl does have one additional highlight: on win32 systems,
you'll want to binmode() your filehandle before you read in
a binary file. Otherwise, the OS may do heinous things.
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: 29 Jul 1999 00:38:56 GMT
From: tgy@chocobo.org (Neko)
Subject: Re: ref() return value...
Message-Id: <7no7r0$3u5$1@216.39.141.200>
On Wed, 28 Jul 1999 23:17:13 GMT, bhaskaracharya@my-deja.com wrote:
>$ref = ref (\( 1, 2, 3)); ## returns SCALAR
>
>why is the ref() considering the array as in scalar context???
>can some body explain this?
Array? What array? I see a list. I see you taking a reference to each item
in the list. I see the last item in the list returned in scalar context. It
would have been easier to do like so:
$ref = ref \3;
--
Neko | tgy@chocobo.org | Will hack Perl for a moogle stuffy! =^.^=
------------------------------
Date: 29 Jul 1999 01:44:32 GMT
From: sjs@yorku.ca (Steven Smolinski)
Subject: Re: reg expression
Message-Id: <slrn7pv89d.gu.sjs@frisco.gulch.com>
Eric Bohlman <ebohlman@netcom.com> wrote:
[...an excellent post. This part is about why it is bad to let FAQ posters
go away with incorrect answers...]
=But the failures caused by the use of "street knowledge" in production
=Perl code tend to make Perl look bad in the eyes of PWPH (People With
=Pointy Hair) [...]
But come on, what sort of fool is writing production code in Perl, and at
the same time asking FAQs in newsgroups? Is it *that* easy to get a
programming job nowadays?
Steve
------------------------------
Date: 28 Jul 1999 19:14:36 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Selecting files by permisions
Message-Id: <slrn7pv76f.4oo.abigail@alexandra.delanet.com>
Keith Lee (leejk@cat.com) wrote on MMCLVII September MCMXCIII in
<URL:news:7nn9ks$l99$1@ns1.cat.com>:
==
Replies go there ---------+
== |
== > Actually, I just realize|my answer was wrong. It should be:
== > +---+
== > unless|(((stat $file) [2] & 07777) == 00644) { ... }
== > +-+
== > And leave off one 7 if|you don't care about suid, gid or sticky bits.
|
v
== Thanks, that works fine. I cannot use a chmod * because commands like cp,
== rm, and such cannot handle more than 2000 or so files at a time, unless you
== go in and tweak the kernel parameters a little, which is not an option for
That's why there's xargs.
== me. Just one more question; what is the meaning of '&'. I can't find it
== anywhere in my books. I see '&&', but this seems different.
As for &, that's explained in the manual. If your books doesn't explain
it, bring back your books and demand your money back.
Abigail
--
%0=map{reverse+chop,$_}ABC,ACB,BAC,BCA,CAB,CBA;$_=shift().AC;1while+s/(\d+)((.)
(.))/($0=$1-1)?"$0$3$0{$2}1$2$0$0{$2}$4":"$3 => $4\n"/xeg;print#Towers of Hanoi
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: Thu, 29 Jul 1999 01:22:57 GMT
From: phil.j@btinternet.com (Phil)
Subject: substitute fcntl for flock
Message-Id: <379fac8b.13554035@news.demon.co.uk>
My isp doesn`t support flock but does support fcntl, anyone know how
to insert fcntl into a perl script and is it a good substitute for
flock functions.
Thanks
Phil
------------------------------
Date: 29 Jul 1999 00:55:00 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: Using regular expressions in $\
Message-Id: <7no8p4$dd@dfw-ixnews6.ix.netcom.com>
mgcesar@my-deja.com wrote:
: Does any body know how (or if) regular expression can be used as an
: INPUT_RECORD_SEPERATOR ($\)? I have a file to parse where the 'RS' in
: Awk would be defined as "\\\xB3{1,4}" (ie 1 to 4 hex B3s).
: Any ideas?
See the suggestions in perlfaq6.
------------------------------
Date: Wed, 28 Jul 1999 18:23:29 -0400
From: "Charles Pelkey" <cpelkey@mindspring.com>
Subject: Win32::ODBC error
Message-Id: <7no6lg$nvd$1@nntp6.atl.mindspring.net>
I am having a few problems with INSERT INTO using Win32::ODBC. I am running
Apache 1.3.4 on Windows NT with ActivePerl 509. The ODBC module is the
current (9702xx) build.
<ERROR>
sql statement: "INSERT INTO topic (Date, Summary) VALUES ($date,
'$subject')"
Error: "-3502[Microsoft][ODBC MS Access 97 Driver] Syntax error in INSERT
INTO statement.10"
</ERROR>
My question is: What the heck is wrong with the syntax??? From everything I
have read regarding SQL and ODBC, the syntax is correct.
The error # 3502 in access talks about "Design master" and "Replica"... I
have no clue what that stuff means, but the sql error has a minus sign in
front, which makes me think it is not the same error code.
Any help would be appreciated.
===================================================================
Charles E. Pelkey
pelkeyc@geocities.com cpelkey@mindspring.com
ICQ: 8294384 AOL IM: SgtPelkey
http://shadow-web.ddns.org/ <- Personal server, after 2135 Eastern
http://www.geocities.com/TimesSquare/Alley/2920/
====================================================================
------------------------------
Date: 1 Jul 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 1 Jul 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.
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 V9 Issue 289
*************************************