[22163] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 4384 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Jan 11 14:05:47 2003

Date: Sat, 11 Jan 2003 11:05:08 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sat, 11 Jan 2003     Volume: 10 Number: 4384

Today's topics:
    Re: $size = -s  /home/temp/$_"  Doesn't work <clay@panix.com>
    Re: $size = -s  /home/temp/$_"  Doesn't work <jurgenex@hotmail.com>
    Re: $size = -s  /home/temp/$_"  Doesn't work <vladimir@NoSpamPLZ.net>
        3d Bar charts (reprint from c.l.p.modules (RR)
    Re: Converting CGI to XML <jurgenex@hotmail.com>
    Re: EXCEL OLE functions <jason@jasonshea.com>
    Re: FULL VERSION:  Hi all gurus.  What is wrong in my s <nobody@dev.null>
    Re: FULL VERSION:  Hi all gurus.  What is wrong in my s <wksmith@optonline.net>
    Re: How does one determine why perl prog runs so slow?? (Tad McClellan)
    Re: How does one determine why perl prog runs so slow?? <family2@aracnet.com>
    Re: How does one determine why perl prog runs so slow?? <uri@stemsystems.com>
    Re: How does one determine why perl prog runs so slow?? Andrew Lee
        how to redirect STDIN to such place like /dev/null ?? <oooooops@163.com>
    Re: Matching entries in lists (Anno Siegel)
    Re: Matching entries in lists (Anno Siegel)
        Parsing /(terminated|non-terminated)/ records from a fi (Kevin Newman)
    Re: Parsing /(terminated|non-terminated)/ records from  <Jodyman@hotmail.com>
    Re: parsing a textarea field <eric.ehlers@btopenworld.com.nospam>
        Perl and Ruby <jurgenex@hotmail.com>
    Re: Picking out options in argv (Tad McClellan)
    Re: Picking out options in argv <starfury@cats.ucsc.edu>
    Re: Picking out options in argv <jurgenex@hotmail.com>
    Re: Proper attribution in follow-ups (Was Re: parsing x Andrew Lee
    Re: Red Hat 8 breaking one-liner signature script (Emmy)
    Re: removing duplicate values from array not working... <eric.ehlers@btopenworld.com.nospam>
    Re: These are discouraging stats to Perlistas & Pythoni <ubecher@gmx.net>
    Re: undef of large Hashes/Arrays took a very long time <pa@panix.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Sat, 11 Jan 2003 15:06:33 +0000 (UTC)
From: Clay Irving <clay@panix.com>
Subject: Re: $size = -s  /home/temp/$_"  Doesn't work
Message-Id: <slrnb20cnp.r3h.clay@panix3.panix.com>

In article <c9858ca5.0301110504.3334673f@posting.google.com>, juha wrote:

> Hi all gurus.  What is wrong in my script?
> 
> I need to check if the file is complity on my disk from FTP program.
> So I check the file's size and wait a while and check it again. If
> size is same file is ready for action else do nothing. Here is what I
> can't get work:
> 
> while (<TEXTFILE>) {
> $size1 = -s "/temp/$_";
> system('sleep 20');
> $size2 = -s "/temp/$_";
> 
>    if ($size1 = $size2 ) {

Who knows? The code you posted doesn't make sense -- Did you open a file
with the TEXTFILE file handle? Are you reading each line of the file to
test the size of a file in /temp?

-- 
Clay Irving <clay@panix.com>
IMMODEST, adj. Having a strong sense of one's own merit, coupled with a
feeble conception of worth in others. 
- Ambrose Bierce 


------------------------------

Date: Sat, 11 Jan 2003 16:09:19 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: $size = -s  /home/temp/$_"  Doesn't work
Message-Id: <PkXT9.2522$DQ5.1072@nwrddc04.gnilink.net>

juha wrote:
> Hi all gurus.  What is wrong in my script?
>
> I need to check if the file is complity on my disk from FTP program.

You know that there are several FTP modules on CPAN?
When searching for "FTP" the third and sixth items look very promising.

> So I check the file's size and wait a while and check it again. If
> size is same file is ready for action else do nothing. Here is what I
> can't get work:
>
> while (<TEXTFILE>) {
> $size1 = -s "/temp/$_";

Do your file names have a newline at the end of their names or did you
forget to "chomp"?

> system('sleep 20');

Why do you call an external program and make your program non-portable
instead of using Perl's internal "sleep" function?

> $size2 = -s "/temp/$_";
>
>    if ($size1 = $size2 ) {

Do you really mean to assign the value of $size2 to $size1? I cannot think
of a scenario where the assignment would fail and yield a false.

jue




------------------------------

Date: Sat, 11 Jan 2003 16:42:23 GMT
From: "Vladimir P." <vladimir@NoSpamPLZ.net>
Subject: Re: $size = -s  /home/temp/$_"  Doesn't work
Message-Id: <PPXT9.47782$3u5.343218@weber.videotron.net>

On 11 Jan 2003 05:04:14 -0800, juha wrote:
> Hi all gurus.  What is wrong in my script?
> 
> I need to check if the file is complity on my disk from FTP program.
> So I check the file's size and wait a while and check it again. If
> size is same file is ready for action else do nothing. Here is what I
> can't get work:
> 
> while (<TEXTFILE>) {

#you need chomp here:
chomp;
> $size1 = -s "/temp/$_";
> system('sleep 20');
# no need to fork any processes!
sleep 20;
> $size2 = -s "/temp/$_";
> 
# need to compare and not assign
>    if ($size1 = $size2 ) {
if ($size1 == $size2 ) {



-- 
 .signature: No such file or directory


------------------------------

Date: 11 Jan 2003 10:39:13 -0800
From: rickraster@hotmail.com (RR)
Subject: 3d Bar charts (reprint from c.l.p.modules
Message-Id: <97b4acf3.0301111039.454f789e@posting.google.com>

<I've cut 'n pasted my question from last night here. There didn't
seem to be much response in the modules group. ;-)>

Hi all,
Allow me to pick your collective brains for a moment.

I'm looking for a good 3d bar chart (3D as in, Z axis, not just an
extra edge to the column) module (for web graphs and image (latex?) ->
pdf).
I've so far found DBIx::Chart, GD::Chart, Chart::Graph::3dbars, Caida
xrt-3d (?) etc., and was wondering if anyone has tried those and knows
if they produce clean, professional looking charts - it's seems to be
pretty tough to track down  examples of images from these (found a few
though).

We are currently running our extensive (and relatively complex)
reports through MS Access (yeah I know - it's a dog), with an Oracle
backend. Access does however make nice charts, but it's cranky.
We're also using GD::Graph from M. Verbruggen for our web graphs (2D
bar vertical bar graphs - pretty neat actually (with drill-down)), so
I'm familiar with how to use that, although I haven't had a chance to
do a whole lot of exploring in that direction.

If anyone has any hints or tips I'd love to hear your opinions!

Cheers,

Rick


------------------------------

Date: Sat, 11 Jan 2003 16:22:04 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Converting CGI to XML
Message-Id: <MwXT9.15438$uL2.14260@nwrddc01.gnilink.net>

Keith R. wrote:
> Thanks for the help. I was reading about a script, I believe a perl
> script, that would parse the objects in a CGI script into XML.

Why didn't you say so in the first place? Your original question was about
if it's possible to convert an interface into a programming language. That
question didn't make any sense.
Now you seem to be asking if you can represent some data (which happens to
be some kind of object in some CGI scripts) in XML. That of course is a
totally different question and you can certainly do that. It's is actually
what XML was made for.
And if those object are accessible from Perl (e.g they are plain text
format) then Perl can certainly convert the objects.

> an extremely vague explaination. I thought it would be interesting to
> try and convert the CGI scripts in Bugzilla and Bonsai to use XML.

And you want to use a program (written in Perl) to modify the CGI scripts?
Why? Wouldn't it be easier to use a programmer and an editor?

> I suppose Java is an option also. We'll see :-)

Sure. But it's still not clear to me _what_  you want to convert?
- the Common Gateway Interface itself
- the data objects coming from the CGI program
- the CGI program itself

jue




------------------------------

Date: Sat, 11 Jan 2003 17:01:36 GMT
From: Jason Shea <jason@jasonshea.com>
Subject: Re: EXCEL OLE functions
Message-Id: <a1j02vcuamcg4d5kcf5lnlrgf6fbdbntkd@4ax.com>

Try the website http://www.roth.net  This is the website of the author
of Win32 Perl Programming: The Standard Extensions
Second Edition.  This book is a fantastic reference of using perl in
the windows environment.  I believe that book's examples on using the
Win32::OLE module include specifics on accessing Excel COM objects.
Roth.net's script examples http://www.roth.net/perl/scripts/ have some
basic examples using Win32::OLE objects.  As a Systems Administrator I
use the Win32::OLE module religiously to access WMI and ADSI COM
objects, it works fantastically and makes my life easier on a daily
basis..... :)  I hope this helps.

Jason.



On Thu, 09 Jan 2003 23:14:01 GMT, Javier Pérez Montes
<j.perez.montes@terra.es> wrote:

>Hi!
>
>First I'm not sure if this question is off topic here.
>
>I need to access with Perl the OLE functions of Excel, I have few
>examples but I need a more complete source or manual.
>
>Looking around the net it seems that there is no manual. Exists such
>documentacion?
>
>Any help (link) is welcome.
>
>Thanks Javier.



------------------------------

Date: Sat, 11 Jan 2003 15:42:39 GMT
From: Andras Malatinszky <nobody@dev.null>
Subject: Re: FULL VERSION:  Hi all gurus.  What is wrong in my script?
Message-Id: <3E203A90.2080206@dev.null>



juha wrote:

> I need to check if the file is complity on my disk from FTP program.
> So I check the file's size and wait a while and check it again. If
> size is same as firts time, file is ready for action, else do nothing.


I think this is flawed right there. What if you got disconnected from 
the FTP server in the middle of your download? You would have half a 
file but its size would not change so your script would think it's been 
downloaded completely.

FTP already has a mechanism for letting you know when the file has been 
transferred -- don't roll your own. Consider using Net::FTP instead.


> Here is what I can't get work:
> 
> while (<TEXTFILE>) {


What is TEXTFILE?

Well, whatever  it is, you are reading it, line by line.


> $size1 = -s "/temp/$_";

For each line, you are checking the size of a file named whatever is in 
that line, complete with the end-of-line marker.


> system('sleep 20');
> $size2 = -s "/temp/$_";


You do it again in 20 seconds.


> 
>    if ($size1 = $size2 ) {

Now you are assigning $size2 to $size1 and seeing if this was 
successful. You probably meant $size1==$size2, and perl would have 
warned you if you had used warnings.


> 
>      do something;
>                          }
> 
> }
> 

So if the file size didn't change in the first 20 seconds, you do 
something. If it did change, you just abandon this file to look at the 
next file name in TEXTFILE.




------------------------------

Date: Sat, 11 Jan 2003 15:45:21 GMT
From: "Bill Smith" <wksmith@optonline.net>
Subject: Re: FULL VERSION:  Hi all gurus.  What is wrong in my script?
Message-Id: <l_WT9.79493$FT6.14191066@news4.srv.hcvlny.cv.net>


"juha" <salmjuh@hotmail.com> wrote in message
news:c9858ca5.0301110508.5b4d6460@posting.google.com...
> I need to check if the file is complity on my disk from FTP program.
> So I check the file's size and wait a while and check it again. If
> size is same as firts time, file is ready for action, else do nothing.
> Here is what I can't get work:
>
> while (<TEXTFILE>) {
> $size1 = -s "/temp/$_";
> system('sleep 20');
> $size2 = -s "/temp/$_";

--snip--

The handle TEXTFILE clearly refers to a list of file names.  Is it a
directory?  If so, did you remember to open it with opendir rather than
open?

Bill





------------------------------

Date: Sat, 11 Jan 2003 09:16:41 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: How does one determine why perl prog runs so slow????
Message-Id: <slrnb20dap.v4c.tadmc@magna.augustmail.com>

Bob Mariotti <R.Mariotti@FinancialDataCorp.com> wrote:
> Honestly!  I HAVE searched this group, other perl sites, perlfaqs, etc
> and I cannot find anything that actually covers this topic.


You missed it then.


> So, here's my question for the perl guru's that I could not find in
> the faqs or other resources:
> 
> How does one go about determining what may be the cause of this
> unacceptable performance?


   perldoc -q profile

      "How do I profile my Perl programs?"


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: Sat, 11 Jan 2003 10:29:20 -0600
From: Abernathey Family <family2@aracnet.com>
Subject: Re: How does one determine why perl prog runs so slow????
Message-Id: <3E204660.C841C69C@aracnet.com>

Feeling obligated to make a contribution to continue a 24x7 presense on
this newsgroup Tad McClellan wrote:
> 
> Bob Mariotti <R.Mariotti@FinancialDataCorp.com> wrote:
> > Honestly!  I HAVE searched this group, other perl sites, perlfaqs, etc
> > and I cannot find anything that actually covers this topic.
> 
> You missed it then.
> 
> > So, here's my question for the perl guru's that I could not find in
> > the faqs or other resources:
> >
> > How does one go about determining what may be the cause of this
> > unacceptable performance?
> 
>    perldoc -q profile
> 
>       "How do I profile my Perl programs?"
--snip--
Here's another classic perldoc -g lookie-here-for-nothing answers all
too common on this newsgroup.


------------------------------

Date: Sat, 11 Jan 2003 18:59:12 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: How does one determine why perl prog runs so slow????
Message-Id: <x7of6nfr7j.fsf@mail.sysarch.com>

>>>>> "AF" == Abernathey Family <family2@aracnet.com> writes:

  AF> Feeling obligated to make a contribution to continue a 24x7 presense on
  AF> this newsgroup Tad McClellan wrote:

you are killfile material for that. i can here the plonks from all over
the world.

  >> perldoc -q profile
  >> 
  >> "How do I profile my Perl programs?"
  AF> --snip--

  AF> Here's another classic perldoc -g lookie-here-for-nothing answers all
  AF> too common on this newsgroup.

and here's another classic whine about references to the docs from
someone who doesn't answer the OP themselves. 

you don't have the right to whine about an answer unless you provide
better help yourself.

and do you speak for your entire family? do your wife and kids concur
with your whines? do they read the perl docs?

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org
Damian Conway Perl Classes - January 2003 -- http://www.stemsystems.com/class


------------------------------

Date: Sat, 11 Jan 2003 14:03:23 -0500
From: Andrew Lee
Subject: Re: How does one determine why perl prog runs so slow????
Message-Id: <h7q02vgfkjip8kn46fi0kb5k2od5bingun@4ax.com>

On Sat, 11 Jan 2003 04:28:32 GMT, R.Mariotti@FinancialDataCorp.com
(Bob Mariotti) wrote:

>Honestly!  I HAVE searched this group, other perl sites, perlfaqs, etc
>and I cannot find anything that actually covers this topic.  It IS
>perl so I'm posting in the perl group.
>


Did you try the web? I searched Goggle for "perl profiling" and got
back 34,000 documents.

The third docuent was an article in Dr Dobbs by a person who regularly
uses this newsgroup and is an authority on Perl.

http://www.ddj.com/documents/s=1498/ddj0104pl/

-- Andrew


------------------------------

Date: Sun, 12 Jan 2003 02:46:26 +0800
From: "oooooops" <oooooops@163.com>
Subject: how to redirect STDIN to such place like /dev/null ??
Message-Id: <avpp0m$11h9$1@mail.cn99.com>

I set up a script for catching output of a pipe
from aother program as following.
but I can not close the STDIN
or just redirect else behind double "\n"
input. if I run it with
$perl to_file.pl
I have to type three time enter to end
the script, but there is only two "\n"
in the file catched. I am confused with it.

could you give me some advice ??

Thanks!!

[test@mail test]$ less to_file.pl
#!/usr/bin/perl -w

use strict;

my $i;
open (DEST, ">>/home/test/testfile.dat")||die "$!";
$i=0;
OUTER: while (<STDIN>){
        if ($_ eq "\n" && $i==1){
#               close STDIN;
                last OUTER;
        }elsif($_ eq "\n" && $i==0){
                $i=1;
        }else{
                $i=0;
        }
        print DEST $_;
}
close (DEST);




------------------------------

Date: 11 Jan 2003 14:41:23 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Matching entries in lists
Message-Id: <avpaej$pdk$1@mamenchi.zrz.TU-Berlin.DE>

Michael Peuser \(h\) <post@mpeuser.de> wrote in comp.lang.perl.misc:
> 
> "Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> schrieb im Newsbeitrag
> news:avmodu$qem$1@mamenchi.zrz.TU-Berlin.DE...
> > Bernd Schandl <schandl@gmx.net> wrote in comp.lang.perl.misc:
> > > I have the following problem: I have a list where each entry is a
> telephone
> > > number, a name and a category. In a second list, I have telephone
> numbers
> > > (in the same format) and I want to check whether they appear in the
> first
> > > list and if yes, what the corresponding name and category is. As an
> > > additional difficulty, the numbers in the first list are not necessarily
> > > complete numbers but rather the beginning of a telephone number (think
> area
> > > code or company). So for the entry 12345678 in the second list, I want
> to be
> > > able to find the entry (123,"Some company","work") in the first list. I
> only
> > > need to find the first match.
> > >
> > > So my questions are:
> > > - What is the best data structure for the first list? Some kind of
> array?
> > >   Two hashes?
> >
> > A hash (why two?) is the usual Perl answer to a lookup problem.
> >
> > Out of the "first list", build a hash keyed on the phone numbers
> > with the values containing the other info (as a string, or as a
> > listref, it doesn't matter).
> >
> > > - What is a good/efficient/elegant way to find an entry in the first
> list
> > >   matching a number from the second?
> >
> >     sub lookup {
> >         my ( $table, $number) = @_;
> >         # find the longest prefix of $number that is in $table
> >         while ( length $number ) {
> >             last if exists $table->{ $number};
> >             chop $number;
> >         }
> >         ( $number, @{ $table->{ $number}} ) if length $number;
> >         return;
> >     }
> 
> 
> 
> I like the idea of the above soulution very much. The important to consider
> run time behaviour of Perl scripts is generally not very much appreciated,
> because Perl normally manipulates MB of data in a flash. It becomes
> important when you shuffle around GB, or even just 100 MB through the memory
> for several times.
> 
> The standard solution for the above problem would be not a hash but an
> array, sorted according to telephone number and accessing it by binary
> search. Be N the length of that list  a*ld N would be the time needed, 'a'
> beeing the time for accessing an array.

Binary search should certainly be considered, but I wouldn't call it the
standard solution.  If anything, the standard solution for a prefix problem
is a trie structure, which could be implemented quite efficiently for
this task since the alphabet ('0' .. '9') is short and compact.

> The above soulution takes h*M where M ist the mean length of a requested

No, M is the mean number of digits that must be chopped off until it can
be decided whether the number is in the table.  This will be less than
the length of the requested number in most cases.

> telefon number and 'h' the time for a hash access, 'h' upto 10 times slower

Ten times?  Benchmarks show the relation between 1:2 and 1:3, closer to 1:2.

> than 'a' (though it depends on various circumstances, read the,man page for
> pre-allocating hash space, e.g.).

Where does pre-allocation come in?  The hash is fixed in the situation
we're talking about.

> So I should expect for 10 digit telephone numbers the clasical binary search
> to be faster up to a list of 2**20 = 1 Mio entries.

It may or may not be faster.  I don't think much can be said about the
relationship unless we know more about the distribution of keys, the
fixed keys in the lookup table as well as the numbers that will be
queried.

Anno


------------------------------

Date: 11 Jan 2003 14:47:40 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Matching entries in lists
Message-Id: <avpaqc$pdk$2@mamenchi.zrz.TU-Berlin.DE>

Benjamin Goldberg  <goldbb2@earthlink.net> wrote in comp.lang.perl.misc:
> Anno Siegel wrote:
> [snip]
> >         ( $number, @{ $table->{ $number}} ) if length $number;
> >         return;
> 
> This always returns the empty list.  The ($number, @...) on the line
> above have no effect.

Thanks for catching that.  The same thing occured to me while riding the
bus back home.  The effect has been called "l'esprit de logoff".

[correction snipped]

Anno


------------------------------

Date: 11 Jan 2003 10:06:17 -0800
From: knewman00@earthlink.net (Kevin Newman)
Subject: Parsing /(terminated|non-terminated)/ records from a file
Message-Id: <4c8e4398.0301111006.293f4c5c@posting.google.com>

Hi all,

I need help with parsing records from a file that may or may not have
record terminators.  The long explanation of the problem is below. 
The purpose of this program is to check record formatting and collect
stats on how well the records are formatted.  Right now I will be
happy with being able to loop through a terminated and non-terminated
file with no errors.  The following code works, but needs some
tweaking. If I use local $/ = \$lreclBytes instead of $/ =
\$lreclBytes files with no terminators won't work. For terminated
files I get "Died at stats-both.pl line 16, <> line 1.".

use strict;

my $lreclBytes = 4;
# Remember to change.  0 = terminated records 1 = non-terminated
records
my $terminator = 1;  
	while( 1 )
	{
	   if ($terminator)
	   {
	      $/ = \$lreclBytes; 
	      defined(my $length = <>) or last;
	      my $lrecl = ($length - $lreclBytes); #logical record length is
part of the record
	      $/ = \$lrecl;
	   }
	   #Handles records with or without a lrecl
	   defined(my $data = <>) or die;
	   my $recNum = sprintf ("%05d",$./($terminator + 1));
	   $data =~ s/\015\012\z|[\015\012\000]\z//;
	   print "Record [$recNum] -> [$data]\n";
	}

** Long Explanation **

There are two types of files that can occur in a number of valid
configurations.  Here are a few examples:
1.
TEXTTEXTTEXTTEXT TEXT TEXTTEXTTEXTTEXTTEXT TEXT TEXTTEXTTEXTTEXTTEXT
TEXT TEXT
2.
TEXTTEXTTEXTTEXT TEXT TEXT\n
TEXTTEXTTEXTTEXT TEXT TEXT\n
3.
0012TEXTTEXT0012TEXTTEXT0012TEXTTEXT
4.
0012TEXTTEXT\n
0012TEXTTEXT\n
5.
0012TEXTTEXT0016TEXTTEXTTEXT0012TEXTTEXT0020TEXTTEXTTEXTTEXT
6.
0012TEXTTEXT\n
0016TEXTTEXTTEXT\n
0020TEXTTEXTTEXTTEXT\n

Type 1 files are just plain ol' text files.  These types of files
usually have terminators but don't necessarily have to.  Files with no
terminators will be ignored because there is no way to figure out
where a record stops or starts.

Type 2 files include a logical record length as the first 4 bytes of
each record.  The physical record lengths (precl) of type 2 files are
supposed to agree with the lrecl, but do not have to in order to be
valid.  Also, the precl includes the length of lrecl.   If the file
has terminators, the terminators will override the logical record
length of each record.  IOW, terminators always win!

Either type of file may have \CR|\LF|\CR\LF terminators which will
eventually be replaced with \LF.

Thanks,

kln


------------------------------

Date: Sat, 11 Jan 2003 18:15:11 GMT
From: "Jodyman" <Jodyman@hotmail.com>
Subject: Re: Parsing /(terminated|non-terminated)/ records from a file
Message-Id: <PaZT9.5021$Qr4.486776@newsread1.prod.itd.earthlink.net>

"Kevin Newman" <knewman00@earthlink.net> wrote in message

> I need help with parsing records from a file that may or may not have
> record terminators.

[snip]

Kevin,

        If the files aren't too large, you can slurp them into a single
variable and then break up the individual records or fields (i.e. apply
rules) after having removed all \r\n|\n|\r.  I've used this to parse phone
books before and it works great.  I'm not telling you how to do it but
perhaps a different method.

Jody




------------------------------

Date: Sat, 11 Jan 2003 16:58:45 +0000 (UTC)
From: "eric" <eric.ehlers@btopenworld.com.nospam>
Subject: Re: parsing a textarea field
Message-Id: <avpig5$d5i$1@helle.btinternet.com>

use strict;
use warnings;
my $textarea="hello\nhow\nare\nyou\n";
print "\$textarea=\n===\n$textarea===\n";
my @fields=split("\n",$textarea);
for (@fields) {
  print "processing field >$_<\n";
}

eric




------------------------------

Date: Sat, 11 Jan 2003 18:32:42 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Perl and Ruby
Message-Id: <erZT9.3045$%V.517@nwrddc02.gnilink.net>

I just read a magazine article about Ruby and I was wondering if some
Perlers have any experience with that language.
How does it compare to Perl? Where are the individual strengths and
weaknesses of each language when compared to each other?

jue




------------------------------

Date: Sat, 11 Jan 2003 09:07:18 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Picking out options in argv
Message-Id: <slrnb20cp6.v4c.tadmc@magna.augustmail.com>

John Tuong <starfury@cats.ucsc.edu> wrote:

> This is my first time using perl, and the perl code i made to grab options


You should consider using a module for processing switches.


> so far is very cumbersome and c related which makes me think I'm headed
> towards the wrong direction.  Especially my constant use of if/else which is
> already bad coding style...  any clue as to what kind of perl function will
> hold true to perl's power and do all these in fewer steps?


But a "dispatch table" would be a better alternative if you
still want to roll your own.


> while ($x = shift @ARGV) {
>     if($x =~ /-T/) {


Do you want to execute this clause with any of:

   -Text
   --T
   Print-Text

etc.  ??

If you want to test for equality, then you should use the operator
that tests for equality

   if ( $x eq '-T' ) {

or at least anchor the beginning:  /^-T/


>         $x = shift @ARGV;
>         print "quote: postscripting endquote\n" if($x =~ /ps/);
>         print "groffing\n" if($x =~ /groff/);
>         print "pdf'ing\n" if($x =~ /pdf/);
>     } elsf($x =~ /-fT/) {
>         print "Time Roman Font\n";


Let's make a dispatch table for those first 2 cases (untested):

   my %todo = (
      '-T'  => sub {
                      $x = shift @ARGV;
                      print "quote: postscripting endquote\n" if($x eq 'ps');
                      print "groffing\n" if($x eq 'groff');
                      print "pdf'ing\n" if($x eq 'pdf');
                   },
      '-fT' => sub {
                      print "Time Roman Font\n";
                   }
   );


Then process all of the switches with this simple loop:

   while ( defined $ARG[0] and exists $todo{$ARG[0]} ) {
      my $arg = shift;
      $todo{$arg}->();      # execute the appropriate anon subroutine
   }


>     } elsf($x =~ /-fN/) {
        ^^^^

So this is not even your real code then. Please don't take advantage 
of folks by having them review code that does not even really exist.

   Please Do not re-type Perl code
        Use copy/paste or your editor's "import" function rather than
        attempting to type in your code. If you make a typo you will get
        followups about your typos instead of about the question you are
        trying to get answered.


>         print "NewCenturySchlbk\n";

[snip more elsif clauses]

>     } elsf($x =~ /-vs/) {
>         $x = shift @ARGV;
>         if ($x =~ /-.*/) {
>             die "Invalid points type\n";
>         }
>         $vspoint = $x;
>     }

   else {
      print "'$x' is an invalid argument\n";
   }


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: Sat, 11 Jan 2003 10:35:41 -0800
From: "John Tuong" <starfury@cats.ucsc.edu>
Subject: Re: Picking out options in argv
Message-Id: <3e2063fc$1@news.ucsc.edu>

> Then process all of the switches with this simple loop:
>
>    while ( defined $ARG[0] and exists $todo{$ARG[0]} ) {
>       my $arg = shift;
>       $todo{$arg}->();      # execute the appropriate anon subroutine
>    }

This is a cool concept, I think I'll stick to this 1 because perldoc getopt
doesn't yield any results.  But I don't quite understand the checking part
of the while loop.  It seems to only check $ARG[0].  And the shift seems
to not affect $ARG[0] at all making it go in an infinite loop.

> >     } elsf($x =~ /-fN/) {
>         ^^^^
>
> So this is not even your real code then. Please don't take advantage
> of folks by having them review code that does not even really exist.
>
>    Please Do not re-type Perl code
>         Use copy/paste or your editor's "import" function rather than
>         attempting to type in your code. If you make a typo you will get
>         followups about your typos instead of about the question you are
>         trying to get answered.

sorry, I was reading a tutorial.. and i remember something vaguely about
elseif and being on the spur of code spewing, checking for correctness of
code
came last in my mind.  Then I realized that the code I made so far is bad
coding
convention, because in c / java to maximize efficiency, i would make use of
a
switch statement.  The concept and idea behind the code is wrong, so I
didn't
take any further actions in correcting my code.




------------------------------

Date: Sat, 11 Jan 2003 18:42:58 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Picking out options in argv
Message-Id: <SAZT9.3082$%V.1081@nwrddc02.gnilink.net>

John Tuong wrote:
>> Then process all of the switches with this simple loop:
>>
>>    while ( defined $ARG[0] and exists $todo{$ARG[0]} ) {
>>       my $arg = shift;
>>       $todo{$arg}->();      # execute the appropriate anon subroutine
>>    }
>
> This is a cool concept, I think I'll stick to this 1 because perldoc
> getopt doesn't yield any results.  But I don't quite understand the
> checking part of the while loop.  It seems to only check $ARG[0].
> And the shift seems to not affect $ARG[0] at all making it go in an
> infinite loop.

perldoc -f shift:

    shift   Shifts the first value of the array off and returns it,
            shortening the array by 1 and moving everything down. [...] If
            ARRAY is omitted, shifts [...] the "@ARGV" array at file scopes
            [...]

jue




------------------------------

Date: Sat, 11 Jan 2003 13:50:30 -0500
From: Andrew Lee
Subject: Re: Proper attribution in follow-ups (Was Re: parsing xml with perl --- very urgent .. help please)
Message-Id: <hpo02vcb626goc1hf0l5umb0abfqq647vc@4ax.com>

On Fri, 10 Jan 2003 08:43:42 -0600, tadmc@augustmail.com (Tad
McClellan) wrote:

>Andrew Lee <AndrewLee> wrote:
>
>> Subject: Re: parsing xml with perl --- very urgent .. help please
>                                         ^^^^^^^^^^^    ^^^^^^^^^^^

Note: I was not the orginal poster.  That is not my subject line.
Please do not put words in my mouth.

Indeed there ought to be something in the posting guidelines about
proper attribution -- it is far more important (AFAIC) to _correctly_
quote your fellow netizens than to minimize the pleading on clpm.

I am certain you would agree.

-- Andrew




------------------------------

Date: 11 Jan 2003 09:01:39 -0800
From: mweb@inwind.it (Emmy)
Subject: Re: Red Hat 8 breaking one-liner signature script
Message-Id: <e8974ed3.0301110901.1c78ddfb@posting.google.com>

> WAG: It's possible that Mutt isn't running the command through bash, and
> as a result, the -F'\n\s*\n' part is being misinterpreted.  See what
> happens if you run this through Mutt:
> 
>    perl -le 'print q <<' -e'\n\s*\n' -e '>>;'
> (Note the lack of a space between the second -e and it's argument)
> 
> If everything is working right, you should get:
> <
> \n\s*\n
> >
>

Using that as signature macro in mutt I get:
<

s*

>

running it as shell command in mutt I get what you said, however:
<
\n\s*\n
>


Changing the one liner to:

set signature="perl -an0777F'\\n\\s*\\n' -e 'print \$F[rand(@F)],
\"\ngee\n\"' ~/pers_doc/massime|"

i.e. escaping like this \\n\\s*\\n WORKS!!!!!!!!!!!!!!!
THANKS! (Now I'll have to ask on the mutt list why this wasn't needed
before, I guess)
> Otherwise... there's your error.
> 
> [snip]
> The problems that people have there occur because they think "unix means
> you don't have to binmode() your binary files", and they get bitten by
> the fact this is untrue on redhat8 with perl5.8.
> 
> The historical "binary mode == text mode on unix" behavior has induced a
> certain laziness in unix programmers with respect to binmode, causing
> them to leave it out when they should have it in.

So, in general, if one has an old Perl script which was writing and
reading ASCII files, he should binmode() them all to make it work now?

> Hmm, try this (both from within Mutt, and from the xterm):
>    echo $LANG
> Or:
>    perl -le 'print $ENV{LANG}'

This gives in both cases:

en_US.UTF-8

 Thanks again!
          Emmy


------------------------------

Date: Sat, 11 Jan 2003 17:54:32 +0000 (UTC)
From: "eric" <eric.ehlers@btopenworld.com.nospam>
Subject: Re: removing duplicate values from array not working...
Message-Id: <avploo$da8$1@knossos.btinternet.com>

hello,
try the below.
-eric

use strict;
use warnings;

my (@tmp,@tmpTwo);
while (<DATA>) {
  chomp;
  push @tmp,[split/;/];
}

push @tmpTwo,$_->[4] for @tmp;

my %saw;
my @out = grep(!$saw{$_}++, @tmpTwo);

print "$_\n" for @out;

# lines and fields
__DATA__
L1F0;L1F1;L1F2;L1F3;L1F4;L1F5
L2F0;L2F1;L2F2;L2F3;DUPLICATE;L2F5
L3F0;L3F1;L3F2;L3F3;DUPLICATE;L3F5




------------------------------

Date: Sat, 11 Jan 2003 19:53:31 +0100
From: Uwe Becher <ubecher@gmx.net>
Subject: Re: These are discouraging stats to Perlistas & Pythonistas...
Message-Id: <avpp51$nnu$01$1@news.t-online.com>

John W. Krahn wrote:
> Paul Boddie wrote:
> 
>>jacob@cd.chalmers.se (Jacob Hallen) wrote in message news:<avfkpp$a7n$1@nyheter.chalmers.se>...
>>
>>>An interesting thought is wether the 55 Python programmers will produce
>>>more useful applications than the 2037 VB programmers.
>>
>>It gets even more interesting if you take monkeys and typewriters into
>>consideration.
> 
> 
> I thought VB implied monkeys and typewriters?
> 
> 
> John
It does: VB is the result after trying to electronically simulate the 
monkeys and typewriters thing



------------------------------

Date: Sat, 11 Jan 2003 16:42:17 +0000 (UTC)
From: Pierre Asselin <pa@panix.com>
Subject: Re: undef of large Hashes/Arrays took a very long time
Message-Id: <avphh5$bme$1@reader1.panix.com>

In <3E1F9A5D.B4CF629E@earthlink.net> Benjamin Goldberg <goldbb2@earthlink.net> writes:

>Jan Schubert wrote:
>> 
>> Pls, may someone point me to some documentation about memory
>> consumption of very large Arrays and/or Hashes!? It seems that
>> undef/unfree of huge Arrays (2-3GB) takes very long

>It generally shouldn't.  If it does, there's a bug in your malloc.

Are you sure?  I had large undef times too and I interpreted that as a
garbage collection expense:  free a chunk, decrement reference counts,
recurse.  My data structures were more than straight arrays, though.
Still, a perl array is not allocated into a single buffer, is it?


>> and would even apply when exiting a perl-program.

Saw that too.  I even considered having the script kill itself -9
instead of exiting.


>Not necessarily.  Under normal circumstances, many of the things in
>perl's memory are freed simply by exiting -- that is, the operating
>system magically cleans up all memory used by a program.  This happens
>nearly instantaneously, no matter what kind of wierd malloc bugs the
>program might have.

This doesn't help if garbage collection occurs before the exit.



------------------------------

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.  

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 4384
***************************************


home help back first fref pref prev next nref lref last post