[24917] in Perl-Users-Digest
Perl-Users Digest, Issue: 7167 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Sep 22 14:06:53 2004
Date: Wed, 22 Sep 2004 11:05:17 -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, 22 Sep 2004 Volume: 10 Number: 7167
Today's topics:
Re: "RFC": re [un]pack() <bik.mido@tiscalinet.it>
$\ on Win2k and WinXP (Jonas)
Exclusive file access (Yash)
Re: Exclusive file access <jgibson@mail.arc.nasa.gov>
Re: Help with my brute force method (Larry Felton Johnson)
Re: Help with my brute force method (krakle)
Re: How is this Perl Script encrypted? <1usa@llenroc.ude.invalid>
Re: In search of elegant code: Combining two statements (Heinrich Mislik)
Re: new commands written in perl <nospam@bigpond.com>
Re: new commands written in perl <tzz@lifelogs.com>
Re: new commands written in perl <rob_gamble99@hotmail.com>
Re: new commands written in perl <emschwar@pobox.com>
parse_html_string reports error (AR John)
Re: parse_html_string reports error <spamtrap@dot-app.org>
perl newsgroup question <nospam@nospam.com>
Re: perl newsgroup question <mritty@gmail.com>
Re: perl newsgroup question <nospam@nospam.com>
Perl script to clean up file -- Dont know if it can be <laura.hradowy@NOSPAM.mts.caaaaa>
Re: Perl script to clean up file -- Dont know if it can <cciquera@mathworks.com>
Re: Perl script to clean up file -- Dont know if it can <thundergnat@hotmail.com>
Re: Perl script to clean up file -- Dont know if it can <laura.hradowy@NOSPAM.mts.caaaaa>
Printing an array of hash refs (Tony N.)
Re: Printing an array of hash refs <mritty@gmail.com>
Re: Printing an array of hash refs <mark.clements@kcl.ac.uk>
Re: run a sub referenced in hash. <nobull@mail.com>
Re: space deliminated to comma delinated with varried a <laura.hradowy@NOSPAM.mts.caaaaa>
Strange timeout with LWP::Simple::get <find_my_real_address@CL4.org>
translating code to 'mixed' case <friendly@yorku.ca>
what module could easiely load all files to a @array fr <end@dream.life>
Re: what module could easiely load all files to a @arra <mritty@gmail.com>
Re: what module could easiely load all files to a @arra (Randal L. Schwartz)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 22 Sep 2004 16:36:27 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: "RFC": re [un]pack()
Message-Id: <8533l09hsk3mkn08ohlu1g6sqskvdpb9fl@4ax.com>
On Tue, 21 Sep 2004 20:23:52 +0000 (UTC), Ilya Zakharevich
<nospam-abuse@ilyaz.org> wrote:
>[A complimentary Cc of this posting was sent to
>Michele Dondi
><bik.mido@tiscalinet.it>], who wrote in article <gb71k0ls58i0rjjjjuk0otgq0cg8t7fti1@4ax.com>:
Please, don't!
>> Coming to the point, it often happens to resort to "cascaded"
>> [un]pack()s. In my specific case I have
>My opinion on this construct is very contrary to what other posters
>suggest. Actually, this construct is a part of my pack()-megapatch of
>a couple of years ago.
Dear Ilya, I must say that at first your post seemed so much above the
top of my head that it took me some effort even to understand wether
after all you were agreeing or disagreeing with me! ;-)
So it seems that, unlike me and the other poster who responded, you
are *not* the kind of guy who finds [un]pack()'s "correct" patterns by
trial and error...
However, now that I've read it carefully a few times (and I'm ready to
read it again a few more!) I must say that I find it both interesting
and valuable.
As a side note, even if I've never had any training on specific
functional languages (apart a minimal amount of exposure to sml), it
seems that personally I have, say, an inclination at least for some
typical contructs of them. In this sense you may find interesting a
discussion held on the p6l mailing list that started with a message of
mine on a topic (loosely) related to that of this thread. I may give
you some reference if interested...
Misha
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: 22 Sep 2004 06:16:16 -0700
From: jonas.berling@knowit.se (Jonas)
Subject: $\ on Win2k and WinXP
Message-Id: <95db9f5c.0409220516.66ca6cc7@posting.google.com>
I've got a fairly straightforward Perl script that does a RegEx match
over whole files, i.e. it matches things even if they are on separate
rows. I do this by undefining $\ and it works great on Win2k using
ActivePerl 5.8.4.810. But using the same script and the same version
of ActivePerl on a WinXp Professional machine does not work though,
unless I specify a -0777 command line parameter to the Perl
interpreter. Does anybody know of this problem and if so, is there a
solution?
Regards,
Jonas B
------------------------------
Date: 22 Sep 2004 08:51:34 -0700
From: yashgt@yahoo.com (Yash)
Subject: Exclusive file access
Message-Id: <5a373b1d.0409220751.337b55ce@posting.google.com>
Our perl program, running with Active Perl on Windows 2000, spawns
multiple processes. Each process works on a large set of files
assigned to it
and operates on records read from them. In between the processing,
each process has to read a common text file, and update it
exclusively. So we
need to open a file for writing, update it and close it. When it has
been opened for writing, the other sibling processes that try to open
it should get blocked automatically, and resume once it has been
closed.
Can you tell me exactly which functions to use, and with what
parameter options, to make this possible.
Thanks
------------------------------
Date: Wed, 22 Sep 2004 10:20:55 -0700
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: Exclusive file access
Message-Id: <220920041020558204%jgibson@mail.arc.nasa.gov>
In article <5a373b1d.0409220751.337b55ce@posting.google.com>, Yash
<yashgt@yahoo.com> wrote:
> Our perl program, running with Active Perl on Windows 2000, spawns
> multiple processes. Each process works on a large set of files
> assigned to it
>
> and operates on records read from them. In between the processing,
> each process has to read a common text file, and update it
> exclusively. So we
>
> need to open a file for writing, update it and close it. When it has
> been opened for writing, the other sibling processes that try to open
> it should get blocked automatically, and resume once it has been
> closed.
> Can you tell me exactly which functions to use, and with what
> parameter options, to make this possible.
See the advice in 'perldoc -q lock'.
------------------------------
Date: 22 Sep 2004 03:58:59 -0700
From: larryj@gsu.edu (Larry Felton Johnson)
Subject: Re: Help with my brute force method
Message-Id: <4ae7bf57.0409220258.37cf90c8@posting.google.com>
"Jeff" <jeff.gilbertson@gmail.com> wrote in message news:<1095715793.375034.285720@k17g2000odb.googlegroups.com>...
> I have a file (DM.txt) that has the following lines:
>
>
> spool cr04 ip11 rm22
> http web01 web02 web03
> mail mail01 mail03
>
>
> I want to create a variable ($Dis) that looks like this:
>
> cr04|ip11|rm22
>
If this file is always going to be this short efficiency isn't a
big concern, and for something this straightforward readability of
the code isn't really an issue, so I usually go with whatever my
fingers pound out, which was
use strict;
my $infile = "DM.txt";
open INFILE, "$infile" or die "Can't open $infile: $!\n";
my $Dis;
while (<INFILE>) {
if (/spool\s+(\w+)\s+(\w+)\s+(\w+)$/) {
$Dis = $1 . '|' . $2 . '|' . $3;
}
}
print "$Dis\n";
------------------------------
Date: 22 Sep 2004 07:54:30 -0700
From: krakle@visto.com (krakle)
Subject: Re: Help with my brute force method
Message-Id: <237aaff8.0409220654.6025a8e4@posting.google.com>
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message news:<ciovbp$11j$1@mamenchi.zrz.TU-Berlin.DE>...
> That is potentially inefficient. <f> in list context reads the
> whole file into memory
<f>? Are you sure there's an <f> even in the script...
------------------------------
Date: 22 Sep 2004 12:29:19 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: How is this Perl Script encrypted?
Message-Id: <Xns956C5659DF5DBasu1cornelledu@132.236.56.8>
i6033162556-signup1@yahoo.com.cn wrote in
news:23d1674e.0409211901.3d08325e@posting.google.com:
> Tim Hammerquist <tim@vegeta.ath.cx> wrote in message
> news:<slrncl1c1i.o4r.tim@vegeta.saiyix>...
>> I suggest examining the last line of code. It will tell
>> you how to encode your own scripts without ever needing
>> to decode the script above.
...
> Yes, I did unpack them, but it is still not working. I changed the
> final line to
> $b=unpack("u",$s);
> print $b;
Ahem ...
print unpack("u",$s);
> I got the file, but still can not find how they use a key to verfy the
> lisence of the script. Also, once I made some change to the file then
> change it back, it does not work. It has some self destruction feature
> that once the script is changed, it is not working.
You might want to look at the key_isValid and key_isValid_simple
subroutines.
Your time working on this is wasted.
perldoc -q hide
Sinan.
------------------------------
Date: 22 Sep 2004 14:16:19 GMT
From: Heinrich.Mislik@univie.ac.at (Heinrich Mislik)
Subject: Re: In search of elegant code: Combining two statements into one (DBI)
Message-Id: <41518932$0$25116$3b214f66@usenet.univie.ac.at>
In article <e4c916dd.0409211544.23499977@posting.google.com>, IneverReadAnythingSentToMe@hotmail.com says...
>
>
>(I'm gonna use a DBI query as an example, but this question is really
>a Perl syntax inquiry (how to add elegance to a bit of code), not a
>database question).
>
>Suppose I have a database table "department" with a simple structure
>such as:
>
> id integer primary key #might not be sequential because of
>deletes
> name varchar
>
>I want to build a hash (%dept) from the database such that (for
>example) $dept{2} eq "Accounting".
This is form perldoc DBI and should do what you want:
# get array of id and name pairs:
my $ary_ref = $dbh->selectcol_arrayref("select id, name from table", { Columns=>[1,2] });
my %hash = @$ary_ref; # build hash from key-value pairs so $hash{$id} => name
cheers
--
Heinrich Mislik
Zentraler Informatikdienst der Universitaet Wien
A-1010 Wien, Universitaetsstrasse 7
Tel.: (+43 1) 4277-14056, Fax: (+43 1) 4277-9140
------------------------------
Date: Wed, 22 Sep 2004 21:39:27 +1000
From: Gregory Toomey <nospam@bigpond.com>
Subject: Re: new commands written in perl
Message-Id: <2rd6jhF18jmuvU1@uni-berlin.de>
Abigail wrote:
> Of course, the shell has much
> cooler strings than Perl has.
>
> Abigail
Why do you say that. I don't know where I'd be without
" ...@{[subcall()]} ..." (or japhs for that matter).
gtoomey
------------------------------
Date: Wed, 22 Sep 2004 10:27:52 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: new commands written in perl
Message-Id: <4nacviv0nr.fsf@lifelogs.com>
On Tue, 21 Sep 2004, emschwar@pobox.com wrote:
> ioneabu@yahoo.com (wana) writes:
>> I named my command 'into'. It just appends a string to a file from
>> the command line.
>
> You mean, like
>
> $ echo "some quick note" >> file
>
> or
>
> $ cat >>file
> some multi-line
> text
> ^D
>
> ?
No, it's NOT the same thing. His program doesn't use the shell. It
may be trivial, but it's not useless.
In addition, note the default behavior is to append to ~/.into when no
file name is given.
Ted
------------------------------
Date: Wed, 22 Sep 2004 11:22:09 -0400
From: Robert Gamble <rob_gamble99@hotmail.com>
Subject: Re: new commands written in perl
Message-Id: <pan.2004.09.22.15.22.05.751720@hotmail.com>
On Wed, 22 Sep 2004 10:27:52 -0400, Ted Zlatanov wrote:
> On Tue, 21 Sep 2004, emschwar@pobox.com wrote:
>
>> ioneabu@yahoo.com (wana) writes:
>>> I named my command 'into'. It just appends a string to a file from
>>> the command line.
>>
>> You mean, like
>>
>> $ echo "some quick note" >> file
>>
>> or
>>
>> $ cat >>file
>> some multi-line
>> text
>> ^D
>>
>> ?
>
> No, it's NOT the same thing. His program doesn't use the shell. It
> may be trivial, but it's not useless.
Of course his program uses the shell, what do you think is calling the
program and passing it the parameters? This could be done from another
program without the shell, but in the examples provided, the shell plays
as much a role as it does in the above examples.
It may not be totally useless but the point is that this functionality
already exists with trivial shell operations which addresses the question
the OP asked.
> In addition, note the default behavior is to append to ~/.into when no
> file name is given.
Maybe there should be a complementing utility called "outof" that will
read from ~/.into by default to justify using it over cat...
> Ted
Rob Gamble
------------------------------
Date: Wed, 22 Sep 2004 10:53:46 -0600
From: Eric Schwartz <emschwar@pobox.com>
Subject: Re: new commands written in perl
Message-Id: <etosm9ab5yd.fsf@wilson.emschwar>
Abigail <abigail@abigail.nl> writes:
> No, no, no. As a general principle, use single quotes if your string
> contains (or may contain in the future) quotes, or a dollar or @ sign
> you don't want to interpolate. Otherwise, use double quotes.
As I said, opinions differ, and I don't particularly care either way--
If I worked where the local style was different, I would adjust easily.
> You'll notice that means you will have to change quotes far less often
> than if your default is single quotes.
It all depends on what you're saying. My style says, "I'm calling
your attention to when I want to interpolate something," yours calls
attention to when you DON'T want to interpolate. That's fine, too.
> Besides, using double quotes make feel C programmers more at ease.
It's been quite a while since that was a big problem for me. :)
-=Eric
--
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
-- Blair Houghton.
------------------------------
Date: 22 Sep 2004 03:07:20 -0700
From: arjohn7681@yahoo.com (AR John)
Subject: parse_html_string reports error
Message-Id: <c0e1de67.0409220207.5d0ad5c3@posting.google.com>
Hi,
Can anybody help me to solve a problem about parsing using LibXML?
In a machine parse_html_string() is used to parse a HTML file. It
works fine. No error. When I deploy the program in another machine -
there, it is showing errors like:
Entity: line 111: error: htmlParseEntityRef: expecting ';'
Can somebody tell me the fix?
In advance, thanks for the solution provider.
AR
------------------------------
Date: Wed, 22 Sep 2004 10:47:53 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: parse_html_string reports error
Message-Id: <3-udnYwjMIgEDczcRVn-hQ@adelphia.com>
AR John wrote:
> Entity: line 111: error: htmlParseEntityRef: expecting ';'
>
> Can somebody tell me the fix?
From reading the error message, it sounds to me like there's an error
on line 111 of the HTML. Specifically, there's an entity that's missing
the ';' - i.e. "&" instead of "&".
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
------------------------------
Date: Wed, 22 Sep 2004 12:24:50 -0400
From: "daniel kaplan" <nospam@nospam.com>
Subject: perl newsgroup question
Message-Id: <1095870327.623321@nntp.acecape.com>
not perl related, but related.
yesterday i meant to REPLY TO GROUP, hit wrong button and sent a NEW post to
this group with the subject of thanks, and all that was in the body of my
post was my default signature.....full real name, phone number, email (oh no
spammers!!!!)
and before realizing my error, sent it....and later conrimed it went
out....here i was dreaded the SLEW of spam i was about to get hit with, and
the post never showed up, never! the other post i made afterwards did!
so two things....is there a moderator to this group that actually saw the
post and deleted it! and if so.....THANK YOU SOOOOOO VERY MUCH!!!!
really
------------------------------
Date: Wed, 22 Sep 2004 16:33:34 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: perl newsgroup question
Message-Id: <yPh4d.2186$Pz3.1454@trndny01>
"daniel kaplan" <nospam@nospam.com> wrote in message
news:1095870327.623321@nntp.acecape.com...
> not perl related, but related.
>
> yesterday i meant to REPLY TO GROUP, hit wrong button and sent a NEW
post to
> this group with the subject of thanks, and all that was in the body of
my
> post was my default signature.....full real name, phone number, email
(oh no
> spammers!!!!)
>
> and before realizing my error, sent it....and later conrimed it went
> out....here i was dreaded the SLEW of spam i was about to get hit
with, and
> the post never showed up, never! the other post i made afterwards
did!
Funny. I saw it. Dated Wed, 22 Sep 2004 05:31:14 -0400.
> so two things....is there a moderator to this group that actually saw
the
> post and deleted it! and if so.....THANK YOU SOOOOOO VERY MUCH!!!!
There is no moderator for this group. comp.lang.perl.moderated, on the
other hand, is moderated.
------------------------------
Date: Wed, 22 Sep 2004 13:44:19 -0400
From: "daniel kaplan" <nospam@nospam.com>
Subject: Re: perl newsgroup question
Message-Id: <1095875098.163702@nntp.acecape.com>
oh man ... so it is out there....funny how i dont see it....oh well, let the
spamming begin :-(
------------------------------
Date: Wed, 22 Sep 2004 08:16:50 -0500
From: "LHradowy" <laura.hradowy@NOSPAM.mts.caaaaa>
Subject: Perl script to clean up file -- Dont know if it can be done
Message-Id: <WWe4d.2141$IO.13667@news1.mts.net>
I thought I would throw this out there, I think it can not be done, but I am
not a guru.
This is the problem I get a file that I must pull the pertanent data out. I
has a header and footer, as well as page breaks, this is all in ASCII
format. I need to pull out just the columns.
I do this all manually (delete the header and footer, and well as all the
page breaks) there are also at times a 0 at the beginning of a record that I
do not want there as well.
This is what the file looks like...
REPORT NAME: FACICL
0 CLIENT JOB NUMBER: 23405
0 CLIENT NAME: LAURA XXXXXXXX
0 CLIENT MAILING CODE: D509H
0 REPORT DATE: 04/07/08
0 REPORT TIME: 12:46
1REPORT NO: FACRPT14 SOME INFO HERE
RUN DATE: 04JUL10
0 JOB NAME: FACCTICL CUTOVER ACCARE INTERFACE
REJECT REPORT PAGE NO: 2
0 PROGRAM : FACB5500 CUTOVER: LEAF CUTOVER
DATE: 04JUL09
0 TELN CUTTELN CUTOEN REJECT REASON
---- ------- -------------- -------------
-----------------
0 1555200 00 0 12 02 CUSTOMER HAS
2555206 00 0 05 01 CUSTOMER HAS
4555208 00 0 03 06 TELN NOT BILL
1REPORT NO: FACRPT14 SOME DATA HERE
RUN DATE: 04JUL10
0 JOB NAME: FACCTICL CUTOVER ACCARE INTERFACE
REJECT REPORT PAGE NO: 3
0 PROGRAM : FACB5500 CUTOVER: LEAF CUTOVER
DATE: 04JUL09
0 TELN CUTTELN CUTOEN REJECT REASON
---- ------- -------------- -------------
-----------------
0 1555200 00 0 12 02 CUSTOMER HAS
2555206 00 0 05 01 CUSTOMER HAS
4555208 00 0 03 06 TELN NOT BILL
- REJECTED = 000000145 CUTOVER = 000000213
- *** SUCCESSFUL COMPLETION OF
FACCTICL ***
I manually disect this file to make it look like this...
1555002 00 0 04 27 TELN NOT BILL
3555007 00 0 06 00 CUSTOMER HAS
5555410 00 0 12 10 CUSTOMER HAS
6755012 00 0 12 06 CUSTOMER HAS
I have manually removed the header, footer and page breaks. As well as there
always seems to be a 0 at start of the first record. I remove this as well.
I then run this perl script:
while (<>) {
chomp; # Will remove the leading , or new line
s,^\s+,,; #Remove leading spaces
my @cols=split m/\s{2,}/, $_, -1; # Split on two (or more) white space
characters
@cols == 2 and splice @cols, 1, 0, "";
print join (',',@cols)."\n";
}
And I get this: WHAT I NEED!
5555002,00 0 04 27,TELN NOT BILL
1555007,00 0 06 00,CUSTOMER HAS
2555010,00 0 12 10,CUSTOMER HAS
I want to try to eliminate as much manual intervention as I can.
------------------------------
Date: Wed, 22 Sep 2004 10:32:17 -0400
From: "Craig Ciquera" <cciquera@mathworks.com>
Subject: Re: Perl script to clean up file -- Dont know if it can be done
Message-Id: <cis2di$ohp$1@fred.mathworks.com>
Would this work:
# Read in the datafile (assume name is datafile.txt)
open(DATAFILE,"<datafile.txt") or die "Cannot open datafile.txt";
while (defined ($line = <DATAFILE>) )
{
# Skip everything but the info we are interested in
next unless $line =~ /\d{2} \d{1} \d{2} \d{2}/;
# Remove any leading 0's and/or whitespace
$line =~ s/(^0{0,}\s{0,})(.*)/$2/;
# Remove any potential empty fields
$line =~ s/\s{2,}/,/g;
print $line;
}
"LHradowy" <laura.hradowy@NOSPAM.mts.caaaaa> wrote in message
news:WWe4d.2141$IO.13667@news1.mts.net...
> I thought I would throw this out there, I think it can not be done, but I
am
> not a guru.
>
> This is the problem I get a file that I must pull the pertanent data out.
I
> has a header and footer, as well as page breaks, this is all in ASCII
> format. I need to pull out just the columns.
> I do this all manually (delete the header and footer, and well as all the
> page breaks) there are also at times a 0 at the beginning of a record that
I
> do not want there as well.
>
> This is what the file looks like...
>
>
> REPORT NAME: FACICL
> 0 CLIENT JOB NUMBER: 23405
> 0 CLIENT NAME: LAURA XXXXXXXX
> 0 CLIENT MAILING CODE: D509H
> 0 REPORT DATE: 04/07/08
> 0 REPORT TIME: 12:46
> 1REPORT NO: FACRPT14 SOME INFO HERE
> RUN DATE: 04JUL10
> 0 JOB NAME: FACCTICL CUTOVER ACCARE INTERFACE
> REJECT REPORT PAGE NO: 2
> 0 PROGRAM : FACB5500 CUTOVER: LEAF CUTOVER
> DATE: 04JUL09
> 0 TELN CUTTELN CUTOEN REJECT
REASON
> ---- ------- -------------- -----------
--
> -----------------
> 0 1555200 00 0 12 02 CUSTOMER
HAS
> 2555206 00 0 05 01 CUSTOMER
HAS
> 4555208 00 0 03 06 TELN NOT
BILL
> 1REPORT NO: FACRPT14 SOME DATA HERE
> RUN DATE: 04JUL10
> 0 JOB NAME: FACCTICL CUTOVER ACCARE INTERFACE
> REJECT REPORT PAGE NO: 3
> 0 PROGRAM : FACB5500 CUTOVER: LEAF CUTOVER
> DATE: 04JUL09
> 0 TELN CUTTELN CUTOEN REJECT
REASON
>
> ---- ------- -------------- -----------
--
> -----------------
> 0 1555200 00 0 12 02 CUSTOMER
HAS
> 2555206 00 0 05 01 CUSTOMER
HAS
> 4555208 00 0 03 06 TELN NOT
BILL
> - REJECTED = 000000145 CUTOVER = 000000213
> - *** SUCCESSFUL COMPLETION OF
> FACCTICL ***
>
>
> I manually disect this file to make it look like this...
> 1555002 00 0 04 27 TELN NOT
BILL
> 3555007 00 0 06 00 CUSTOMER
HAS
> 5555410 00 0 12 10 CUSTOMER
HAS
> 6755012 00 0 12 06 CUSTOMER
HAS
>
> I have manually removed the header, footer and page breaks. As well as
there
> always seems to be a 0 at start of the first record. I remove this as
well.
> I then run this perl script:
>
> while (<>) {
> chomp; # Will remove the leading , or new line
> s,^\s+,,; #Remove leading spaces
> my @cols=split m/\s{2,}/, $_, -1; # Split on two (or more) white space
> characters
> @cols == 2 and splice @cols, 1, 0, "";
> print join (',',@cols)."\n";
> }
>
> And I get this: WHAT I NEED!
> 5555002,00 0 04 27,TELN NOT BILL
> 1555007,00 0 06 00,CUSTOMER HAS
> 2555010,00 0 12 10,CUSTOMER HAS
>
> I want to try to eliminate as much manual intervention as I can.
>
>
------------------------------
Date: Wed, 22 Sep 2004 11:15:00 -0400
From: thundergnat <thundergnat@hotmail.com>
Subject: Re: Perl script to clean up file -- Dont know if it can be done
Message-Id: <415196f0$0$2657$61fed72c@news.rcn.com>
LHradowy wrote:
> I thought I would throw this out there, I think it can not be done, but I am
> not a guru.
>
> This is the problem I get a file that I must pull the pertanent data out. I
> has a header and footer, as well as page breaks, this is all in ASCII
> format. I need to pull out just the columns.
> I do this all manually (delete the header and footer, and well as all the
> page breaks) there are also at times a 0 at the beginning of a record that I
> do not want there as well.
>
> This is what the file looks like...
>
[snip]
> 0 1555200 00 0 12 02 CUSTOMER HAS
> 2555206 00 0 05 01 CUSTOMER HAS
> 4555208 00 0 03 06 TELN NOT BILL
[snip]
> 0 1555200 00 0 12 02 CUSTOMER HAS
> 2555206 00 0 05 01 CUSTOMER HAS
> 4555208 00 0 03 06 TELN NOT BILL
[snip]
What tranforms are you applying to change the numbers?
Where did the extra CUSTOMER HAS line come from?
>
> I manually disect this file to make it look like this...
> 1555002 00 0 04 27 TELN NOT BILL
> 3555007 00 0 06 00 CUSTOMER HAS
> 5555410 00 0 12 10 CUSTOMER HAS
> 6755012 00 0 12 06 CUSTOMER HAS
>
[snip]
What tranforms are you applying to change the numbers?
What happened to the other CUSTOMER HAS line?
>
> And I get this: WHAT I NEED!
> 5555002,00 0 04 27,TELN NOT BILL
> 1555007,00 0 06 00,CUSTOMER HAS
> 2555010,00 0 12 10,CUSTOMER HAS
>
> I want to try to eliminate as much manual intervention as I can.
>
>
Is there more than one different TELN NOT BILL lines in any one file?
If so, how do you tell which CUSTOMER HAS goes with which?
I have no idea how you got "WHAT YOU NEED" from the example data.
None of the lines in the final can be directly derive without applying
some unknown transform.
If you JUST want the lines containing TELN NOT BILL or CUSTOMER HAS
then sift them out and reformat the lines.
------------------------------
Date: Wed, 22 Sep 2004 12:18:57 -0500
From: "LHradowy" <laura.hradowy@NOSPAM.mts.caaaaa>
Subject: Re: Perl script to clean up file -- Dont know if it can be done
Message-Id: <Vti4d.2173$IO.13924@news1.mts.net>
My apologies, I have managed to waggle it out, and fix my problem. Htanks
all for all your help!
------------------------------
Date: 22 Sep 2004 08:35:33 -0700
From: tnitzke@simpson.com (Tony N.)
Subject: Printing an array of hash refs
Message-Id: <638483db.0409220735.49486c78@posting.google.com>
I'm using the following code to print an array of hash refs. It seems
to me there should be a more concise way to do this. I don't like the
trailing \t or the extra line of code to get the \n. Any pointers
would be appreciated.
print "$_\t" for sort keys %{$rows[0]};
print "\n";
for my $row (@rows) {
print "$row->{$_}\t" for sort keys %{$row};
print "\n";
}
------------------------------
Date: Wed, 22 Sep 2004 15:49:15 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Printing an array of hash refs
Message-Id: <%9h4d.3949$kn2.157@trndny07>
"Tony N." <tnitzke@simpson.com> wrote in message
news:638483db.0409220735.49486c78@posting.google.com...
> I'm using the following code to print an array of hash refs. It seems
> to me there should be a more concise way to do this. I don't like the
> trailing \t or the extra line of code to get the \n. Any pointers
> would be appreciated.
> for my $row (@rows) {
> print "$row->{$_}\t" for sort keys %{$row};
> print "\n";
> }
for my $row (@rows){
print (join ("\t", sort keys %$row), "\n");
}
Paul Lalli
------------------------------
Date: Wed, 22 Sep 2004 19:05:57 +0200
From: Mark Clements <mark.clements@kcl.ac.uk>
Subject: Re: Printing an array of hash refs
Message-Id: <4151b0f5$1@news.kcl.ac.uk>
Tony N. wrote:
> I'm using the following code to print an array of hash refs. It seems
> to me there should be a more concise way to do this. I don't like the
> trailing \t or the extra line of code to get the \n. Any pointers
> would be appreciated.
>
> print "$_\t" for sort keys %{$rows[0]};
> print "\n";
>
> for my $row (@rows) {
> print "$row->{$_}\t" for sort keys %{$row};
> print "\n";
>
> }
check out Data::Dumper.
Mark
------------------------------
Date: Wed, 22 Sep 2004 12:36:32 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: run a sub referenced in hash.
Message-Id: <cirnrp$b8f$1@sun3.bham.ac.uk>
Sherm Pendley wrote:
>
> Let me clarify that. Yes, it's considered bad practice to use strings as
> symbolic references. You should be storing code references in your hash
> instead, like this:
>
> my %caps = (
> 'red' => \&subONE,
> 'blue' => \&subTWO,
> 'green' => \&GREEN,
> );
>
> This is, in fact, the first step of creating a "dispatch table", which
> is the commonly suggested alternative to symrefs. So the idea of using a
> hash to store references to subroutines is a good one - the only part of
> it that was a bad idea is storing the sub names as strings.
If you are doing the same thing three times you are probably doing it wrong.
If you are going use named subroutines (rather than anonymous ones) and
put their names in a dispactch table then you may as well put them in
their own separate namespace and use the symbol table itself as the
dispatch table.
{
no strict 'refs';
"My::Own::Module::Handlers::$handler"->();
}
Alternatively you can call them as class methods (which means they get
an extra first argument in $_[0] equal to the package name). This will
placate the religious anti-symref zealots but will, in fact, expose you
to exactly the hazard that prompted the zealotry in the first place.
(Oh sweet irony).
my $handler = 'Some::Function::I::Should::Not::Be::Able::To::call';
My::Own::Module::Handlers->$handler;
Some people also object to the package-as-a-dispatch-table approach
because you need a find a unique namespace. But any non-trivial Perl
program is going to be modular so you must already have overcome that
hurdle.
In some cases the anonymous subroutine appraoch may seem more elegant
but you will find in any non-trivial case it's a right pain in the
backtrace.
------------------------------
Date: Wed, 22 Sep 2004 07:43:18 -0500
From: "LHradowy" <laura.hradowy@NOSPAM.mts.caaaaa>
Subject: Re: space deliminated to comma delinated with varried and need spaces between some columns
Message-Id: <ure4d.2135$IO.13626@news1.mts.net>
I want to thank all who of you that have spent time onthis problem. what a
tremendous response!
"Larry Felton Johnson" <larryj@gsu.edu> wrote in message
news:4ae7bf57.0409220200.107f8270@posting.google.com...
> larryj@gsu.edu (Larry Felton Johnson) wrote in message
news:<4ae7bf57.0409211224.14e8090b@posting.google.com>...
> > "LHradowy" <laura.hradowy@NOSPAM.mts.caaaaa> wrote in message
news:<WYF3d.1170$IO.7153@news1.mts.net>...
> > > I have file that looks like this...
> > > 1555002 00 0 04 27 TELN
NOT BILL
> > > 3555007 00 0 06 00
CUSTOMER HAS
> > > > 1
> > 5555410 00 0 12 10 CUSTOMER HAS
> > > > 1
> > 6755012 00 0 12 06 CUSTOMER HAS
> > > > 1
> > >
> > > Notice the white spaces at beginning of the line, I DONT WANT THEM
THERE
> > > Notice the white spaces in the 2nd and 3rd columns, I NEED THEM
THERE...
> > >
> > > I need to created a perl script that takes this file and makes it look
like
> > > this
> > > 1555002,00 0 04 27,TELN NOT BILL
> > > 3555007,00 0 06 00,CUSTOMER HAS > 1
> > > 5555410,00 0 12 10,CUSTOMER HAS > 1
> > > 6755012,00 0 12 06,CUSTOMER HAS > 1
> > >
> > > This output needs to be written to a file.
> > > I have no idea how to start, if I split on a space " " the it will
spit the
> > > third an fourth column up. The fourth column can basically be left
alone.
> > >
> > > Thanks for the help.
> >
>
> >
> > perl -pi.bak -e
's/^\s+(\w+)\s+(\w+)\s+(\w+)\s+(\w+)\s+(\w+)\s+(.*)/$1,$2
> > $3 $4 $5,$6/g' spaces
> >
>
> A couple of followup things. My g option above (after the last '/'
> was a typo. It didn't hurt or help, but was superfluous.
>
> The second is that the whole approach to looking at lines in a file
> like this bears a little bit of discussion. When I looked at the
> lines, the first thing that entered my mind wasn't "How do I get rid
> of the spaces?" but "What always seems to be true about these lines?"
>
> Basically you're looking at a line like this
>
> some spaces, some
digits,space,digits,space,digits,space,digits,space,digits,space,some
> variable text with no necessity to format.
>
> I could have used \d+ instead of \w+, but everything in the match
> breaks down to
> \w+, \s+ or .*
>
> So there are only three types of things to match, digits, spaces and
> the "everything else" trailing at the end.
>
> Given this a number of the approaches people have given will all work:
> regex,
> splitting into an array, substr (if the positions are uniform) and
> unpack (if the positions are uniform). The task is to capture the
> nonspace stuff into usable variables and print them out with inserted
> whitespace and any punctuation or labeling characters you choose.
> This mental approach gives you much more control over the formatting
> and use of the data than thinking of it as
> simply not wanting the spaces at the beginning of line, but wanting to
> preserve some of the spaces in the middle.
------------------------------
Date: Wed, 22 Sep 2004 12:54:10 +0000 (UTC)
From: "Paul E Collins" <find_my_real_address@CL4.org>
Subject: Strange timeout with LWP::Simple::get
Message-Id: <cirsli$8ue$1@sparta.btinternet.com>
I'm using POE::Component::IRC and LWP::Simple in the same Perl script
(an IRC bot that retrieves information from Web pages). It runs under
ActiveState Perl v5.6.1 on Windows XP.
LWP::Simple::get works just fine in simple test scripts, but when I
use it in the bot it invariably times out. This is particularly
mystifying because the same code worked about a year ago.
(Unfortunately, I don't know what versions of Perl and the libraries I
was using at the time.)
It's not a DNS problem, because it still happens when I use an IP
address instead of a URL; and it's not a scoping problem, because it
still happens when I replace 'get' with 'LWP::Simple::get'. But
evidently something in the bot script is stopping LWP::Simple from
working.
Are there any known bugs that might explain this? What else might be
wrong?
P.
------------------------------
Date: Wed, 22 Sep 2004 12:26:42 -0400
From: Michael Friendly <friendly@yorku.ca>
Subject: translating code to 'mixed' case
Message-Id: <cis94a$1t3$1@sunburst.ccs.yorku.ca>
This is a problem I thought there would have been scripts or modules
I could adapt, but I havent found anything all that useful
on CPAN or other sources (Perl cookbook, 2nd ed)
Given code (perl/C/R, ...) with comments, 'strings', "strings"
and code,
- convert all comments to mixed case as sentences, capitalizing
the first lettter of each '.' delimited sentence, but retain all
'strings' and "strings" within comments in original case.
- convert all non-comment code to lower case, but retain all
'strings' and "strings" within comments in original case.
thanks
--
Michael Friendly Email: friendly@yorku.ca
Professor, Psychology Dept.
York University Voice: 416 736-5115 x66249 Fax: 416 736-5814
4700 Keele Street http://www.math.yorku.ca/SCS/friendly.html
Toronto, ONT M3J 1P3 CANADA
------------------------------
Date: Thu, 23 Sep 2004 00:02:27 +0800
From: Alont <end@dream.life>
Subject: what module could easiely load all files to a @array from a specified folder(and subfolders)?
Message-Id: <4151a17b.15044562@130.133.1.4>
just tell me the name of module,
my english too poor to can't understand all module help files, forgive
me....
--
Your fault as a Government is My failure as a citizen
------------------------------
Date: Wed, 22 Sep 2004 16:31:09 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: what module could easiely load all files to a @array from a specified folder(and subfolders)?
Message-Id: <hNh4d.2032$fa.1836@trndny09>
"Alont" <end@dream.life> wrote in message
news:4151a17b.15044562@130.133.1.4...
> Subject: what module could easiely load all files to a @array from a
specified folder(and subfolders)?
> just tell me the name of module,
> my english too poor to can't understand all module help files, forgive
> me....
File::Find
Paul Lalli
------------------------------
Date: 22 Sep 2004 09:23:55 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
To: end@dream.com
Subject: Re: what module could easiely load all files to a @array from a specified folder(and subfolders)?
Message-Id: <86fz5ap90k.fsf@blue.stonehenge.com>
*** post for FREE via your newsreader at post.newsfeed.com ***
>>>>> "Alont" == Alont <end@dream.life> writes:
Alont> just tell me the name of module,
Alont> my english too poor to can't understand all module help files, forgive
Alont> me....
use File::Finder; # in CPAN
my @array = File::Finder->type('f')->in($specified_folder);
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
-----= Posted via Newsfeed.Com, Uncensored Usenet News =-----
http://www.newsfeed.com - The #1 Newsgroup Service in the World!
-----== 100,000 Groups! - 19 Servers! - Unlimited Download! =-----
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 V10 Issue 7167
***************************************