[23488] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5701 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Oct 23 09:05:43 2003

Date: Thu, 23 Oct 2003 06: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           Thu, 23 Oct 2003     Volume: 10 Number: 5701

Today's topics:
    Re: c programmer in need of perl advise <tore@aursand.no>
    Re: c programmer in need of perl advise <tore@aursand.no>
    Re: DBI & primary keys <tore@aursand.no>
    Re: Fill up HD fastest way <lambik@kieffer.nl>
    Re: Fill up HD fastest way <REMOVEsdnCAPS@comcast.net>
    Re: Fill up HD fastest way <abigail@abigail.nl>
    Re: Fill up HD fastest way drunkenfist@bazurk.com
        IMAP administrative tasks with Perl <who_amiNIESPAMUJ@o2.pl>
    Re: Manipulation binary files (Anno Siegel)
    Re: newbie perl - html question <nospam@bigpond.com>
    Re: newbie perl - html question <tom@ztml.com>
    Re: Pattern match over mutiple files is slow - Help Nee (Anno Siegel)
    Re: performance arrays vs hashes <tore@aursand.no>
    Re: performance arrays vs hashes <REMOVEsdnCAPS@comcast.net>
    Re: Perl and IIS - script runs but 'The page cannot be  <abigail@abigail.nl>
    Re: Perl and IIS - script runs but 'The page cannot be  <flavell@ph.gla.ac.uk>
    Re: Perl and IIS - script runs but 'The page cannot be  (stew dean)
    Re: Perl and IIS - script runs but 'The page cannot be  <barbr-en@online.no>
        Perl variable and C program <willem@xs4all.nl>
    Re: Regex to extract row data from text (Copy of data i <tore@aursand.no>
    Re: Regex to extract row data from text <tore@aursand.no>
    Re: while each hash, why not array <abigail@abigail.nl>
    Re: while each hash, why not array (Anno Siegel)
    Re: while each hash, why not array (Greg Bacon)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 23 Oct 2003 12:25:30 +0200
From: Tore Aursand <tore@aursand.no>
Subject: Re: c programmer in need of perl advise
Message-Id: <pan.2003.10.23.05.41.57.36360@aursand.no>

On Wed, 22 Oct 2003 17:16:53 +0000, Greg Patnude wrote:
> $#ARRY will give you the number of array elements also ...

No.  $#ARRAY will give you the highest index in @ARRAY, while @ARRAY in
scalar context gives you the number of elements.


-- 
Tore Aursand <tore@aursand.no>


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

Date: Thu, 23 Oct 2003 12:25:36 +0200
From: Tore Aursand <tore@aursand.no>
Subject: Re: c programmer in need of perl advise
Message-Id: <pan.2003.10.23.10.20.21.657167@aursand.no>

On Wed, 22 Oct 2003 09:26:31 -0700, Mike Deskevich wrote:
> $ct=0;
> while (<DATAFILE>)
> {
>   ($xvalue[$ct],$yvalue[$ct])=split;
>   $ct++;
> }
> #do stuff with xvalue and yvalue

I created a file with 100.000 lines of tab-delimited floating point
number, and it took my computer 1.5 seconds to add the two columns to two
different arrays.  How fast do you want it to be?


-- 
Tore Aursand <tore@aursand.no>


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

Date: Thu, 23 Oct 2003 12:25:34 +0200
From: Tore Aursand <tore@aursand.no>
Subject: Re: DBI & primary keys
Message-Id: <pan.2003.10.23.05.18.48.521377@aursand.no>

On Wed, 22 Oct 2003 13:40:00 +0100, Bigus wrote:
>> my $id = $stInsert->{'mysql_insertid'};

> That's work excellently and is easier than using the LAST_INSERT_ID. I'm
> likely to stick with mySQL aswell since along with the phpmyadmin web
> interface it's nice and easy to use :) I was gonna ask where
> 'mysql_insertid' comes from but just found it in the DBD-mysql docs.

Nice of you to read the documentation; not everyone cares about such
things nowadays. :-)

Anyway:  Be careful about your design.  Suddenly (...) you have to change
from MySQL to something else, and then you're in deep shit.  For me it was
quite easy, as I had a base class for handling database work from which
every other class derived from.

I'm not an RDBMS expert or anything, but I've been playing around with a
few of them for a few years.  What strikes me is that there's no universal
method around to get the last auto-increment id from a table?  Is it?


-- 
Tore Aursand <tore@aursand.no>


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

Date: Thu, 23 Oct 2003 12:17:25 +0200
From: "Lambik69" <lambik@kieffer.nl>
Subject: Re: Fill up HD fastest way
Message-Id: <bn8a22$un6bk$1@ID-146686.news.uni-berlin.de>

<drunkenfist@bazurk.com> schreef in bericht
news:3f979ec5$0$58701$e4fe514c@news.xs4all.nl...
>
> Any faster way?

how about something like:
#!/usr/bin/perl -w
use strict;

sub fisher_yates_shuffle {
 my $array = shift;
 my $i;
 for ($i = @$array; --$i; ) {
  my $j = int rand ($i+1);
  next if $i == $j;
  @$array[$i,$j] = @$array[$j,$i];
 }
}

my @array = 1..1000000;
open(FILE,'>garbage.dat');
while(1) {
    print FILE fisher_yates_shuffle (\@array);
}
close FILE;




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

Date: Thu, 23 Oct 2003 06:23:54 -0500
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: Fill up HD fastest way
Message-Id: <Xns941D4B3B4B1Esdn.comcast@216.196.97.136>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

"Lambik69" <lambik@kieffer.nl> wrote in news:bn8a22$un6bk$1@ID-
146686.news.uni-berlin.de:

> <drunkenfist@bazurk.com> schreef in bericht
> news:3f979ec5$0$58701$e4fe514c@news.xs4all.nl...
>>
>> Any faster way?
> 
> how about something like:
> #!/usr/bin/perl -w
> use strict;
> 
> sub fisher_yates_shuffle {

Is that really faster?

- -- 
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print

-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBP5e6PWPeouIeTNHoEQI2SgCg3fMP0z3YuCAN1nSaDjUGaAOl8eMAnilo
u14RrlPjR0iMbwkDw7oirCey
=Mwor
-----END PGP SIGNATURE-----


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

Date: 23 Oct 2003 11:26:31 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Fill up HD fastest way
Message-Id: <slrnbpfen7.eg9.abigail@alexandra.abigail.nl>

drunkenfist@bazurk.com (drunkenfist@bazurk.com) wrote on MMMDCCV
September MCMXCIII in <URL:news:3f979ec5$0$58701$e4fe514c@news.xs4all.nl>:
~~  
~~  Hi,
~~  
~~  I'm writing a Perl script that fills a HD with random data as fast as possib
~~  
~~  open(FILE,'>garbage.dat');

That opens a file, it won't fill a hard disk with random data - you will
still be left with a filesystem, and it won't overwrite existing files.

I'd do:

    system "dd if=/dev/urandom of=/dev/rdsk/c1t6d2s2 bs=1024k"

(Assuming /dev/rdsk/c1t6d2s2 is the disk to be filled).



Abigail
-- 
perl -wle 'eval {die [[qq [Just another Perl Hacker]]]};; print
           ${${${@}}[$#{@{${@}}}]}[$#{${@{${@}}}[$#{@{${@}}}]}]'


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

Date: 23 Oct 2003 13:03:07 GMT
From: drunkenfist@bazurk.com
Subject: Re: Fill up HD fastest way
Message-Id: <3f97d18b$0$58709$e4fe514c@news.xs4all.nl>

In article <Message-ID>
Abigail <abigail@abigail.nl> wrote:

> drunkenfist@bazurk.com (drunkenfist@bazurk.com) wrote on MMMDCCV
> September MCMXCIII in <URL:news:3f979ec5$0$58701$e4fe514c@news.xs4all.nl>:
> ~~  
> ~~  Hi,
> ~~  
> ~~  I'm writing a Perl script that fills a HD with random data as fast as possib
> ~~  
> ~~  open(FILE,'>garbage.dat');
> 
> That opens a file, it won't fill a hard disk with random data - you will
> still be left with a filesystem, and it won't overwrite existing files.
> 
> I'd do:
> 
>     system "dd if=/dev/urandom of=/dev/rdsk/c1t6d2s2 bs=1024k"
> 
> (Assuming /dev/rdsk/c1t6d2s2 is the disk to be filled).
> 

ehh, forgot to mention 'fill free space'. It should be portable as well.



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

Date: Thu, 23 Oct 2003 10:43:10 +0000 (UTC)
From: John Doe <who_amiNIESPAMUJ@o2.pl>
Subject: IMAP administrative tasks with Perl
Message-Id: <slrnbpfccb.1j8.who_amiNIESPAMUJ@neo.neostrada.pl>

Hi!

I need to write IMAP client that does some administrative tasks on the 
server. I need to know if it is possible to log into IMAP server as
and administrator and then switch between user mailboxes having only
logins and what Perl modules should I use. is it hard to find some example
on it.

thanks in advance
hs


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

Date: 23 Oct 2003 12:57:45 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Manipulation binary files
Message-Id: <bn8j89$n8a$3@mamenchi.zrz.TU-Berlin.DE>

John W. Krahn <krahnj@acm.org> wrote in comp.lang.perl.misc:
> "Eric J. Roode" wrote:
> > 
> > "Chris" <chris@nospam.dustbubble.com> wrote in
> > news:cSvkb.498$jk1.619339@newsfep1-win.server.ntli.net:
> > >
> > > a) write to a file in binary mode. I have tried using binmode(FH)
> > > before the writing beging, but it seems to make little difference
> > 
> > To write to a binary file, you use "print", just like writing to a text
> > file.  You should use binmode on the file handle beforehand, yes.
> > 
> > > b) write strings in binary mode. I dont really have to do write 0x52
> > > 0x49 0x46 0x46 if there is a way to write "RIFF" and have perl do the
> > > donkey work
> > 
> > Yes: print FH "RIFF";
> 
> And you may want to turn on autoflush for your output file handle.  Have
> a look in perlvar.pod for "OUTPUT_AUTOFLUSH".

How would that make a difference?  If the file is a normal disk file,
I don't see the use of autoflush.

Anno


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

Date: Thu, 23 Oct 2003 20:48:43 +1000
From: Gregory Toomey <nospam@bigpond.com>
Subject: Re: newbie perl - html question
Message-Id: <2295010.NX2Z77MczJ@gregs-web-hosting-and-pickle-farming>

It was a dark and stormy night, and tom managed to scribble:

> Your perl script and images files might not in the same directory. In this
> case, you need to specify the location of your image files with an
> absolute path. For example: <img
> src="http://job1data.com/images/phslogo.bmp"
> 

Or better still
<img src="/images/phslogo.bmp"> or
<img src="../images/phslogo.bmp">

gtoomey



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

Date: Thu, 23 Oct 2003 11:32:44 GMT
From: tom <tom@ztml.com>
Subject: Re: newbie perl - html question
Message-Id: <w%Olb.16262$Vf7.15647@nwrdny02.gnilink.net>

Gregory Toomey (bigpond.com) wrote:
>It was a dark and stormy night, and tom managed to scribble:
>
>> Your perl script and images files might not in the same directory. In this
>> case, you need to specify the location of your image files with an
>> absolute path. For example: <img
>> src="http://job1data.com/images/phslogo.bmp"
>> 
>
>Or better still
><img src="/images/phslogo.bmp"> or
><img src="../images/phslogo.bmp">
>
>gtoomey
>

Yes indeed your is better. However, the script used must be in the same server 
and the images directory is the one above; otherwise, the full URL is needed.

Tom


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

Date: 23 Oct 2003 11:42:54 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Pattern match over mutiple files is slow - Help Needed !
Message-Id: <bn8eru$n8a$1@mamenchi.zrz.TU-Berlin.DE>

RV <rvstore1@yahoo.com> wrote in comp.lang.perl.misc:
> < Note: Posted this message earlier today to comp.lang.perl - then
> realized that it was defunct. Hence posting it to this group >
> 
> Hi:
> 
> Am having a huge performance problem in one of my scripts.
> 
> I have an array containing some reference keys. ( about 1000 entries
> or so ).
> I also have a list of files ( about 100 or so ) and I need to locate
> occurence of these keys in all of the files and replace with some
> value ( lets say the key-value hash is also given ).
> 
> My code looks something like this:
> 
> #Note: %keyval --> holds the key-value mapping
> # @keylist - is the array with the 1000 keys ( like keys %keyval )
> # @files - holds the list of files ( about 100 or so ).
> 
> foreach $f ( @files )
> {
>     #open file - validate etc - assume it is opened as <FH>
>     while(<FH>) #each line
>     {
>         $line=$_ ;
>         foreach $k (@keylist)
>         {
>             $line =~ s/$k/$keyval{$k}/ig ; #replace key with value
>         } #key loop
>     }
>     close(FH);
> } #foreach
> 
> This code works - but its too slow ! -- Obviously I run the inner loop
> 1000 times for each line in the file.
> Constraints being that multiple keys may occur on the same line ( and
> even the same key will occur multiple times on the same line ).
> 
> I tried globbing the file into a scalar ( unsetting $/ ) - no big
> difference in timing.
> 
> Can someone help me here ? - If you can give some ideas that I can
> look into, I'll greatly appreciate it.
> Pseudocode is fine as well.

There's a FAQ about this, "perldoc -q 'many regular'" finds it.
In short, it will point you to the qr// operator, which should
indeed be a time saver here.

Combining all patterns into a big regex of alternatives may help too.
As Tad has pointed out in another post, make sure that long strings
come before shorter ones (sort them), or you may get spurious matches.

Finally, consider the rarely-used study() function.  You may try
slurping the entire files and study() the string before applying
the regex.  Whether this speeds things up must be seen.

Anno


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

Date: Thu, 23 Oct 2003 12:25:35 +0200
From: Tore Aursand <tore@aursand.no>
Subject: Re: performance arrays vs hashes
Message-Id: <pan.2003.10.23.05.21.11.543215@aursand.no>

On Wed, 22 Oct 2003 23:24:12 -0500, Tad McClellan wrote:
>> You _can_ say "$hash{'abcd'}" or "$hash{'whatever I damn well
>> please'}" and actually, you don't need the quotes;

> You don't need the quotes when the key matches /^\w+$/.
> So you need the quotes for something like that 2nd one above.

Word of advice, but shouldn't one use quotes whenever possible?  I
constantly use quotes, as it looks better in my editor (FTE).

I don't use quotes when working with variables, of course;

  my $value = $hash{ $key };

Hmm.  But I tend to carry around those spaces, I see. :-)  Easier to read?


-- 
Tore Aursand <tore@aursand.no>



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

Date: Thu, 23 Oct 2003 06:16:31 -0500
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: performance arrays vs hashes
Message-Id: <Xns941D49FB5BB46sdn.comcast@216.196.97.136>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

Tore Aursand <tore@aursand.no> wrote in
news:pan.2003.10.23.05.21.11.543215@aursand.no: 

> On Wed, 22 Oct 2003 23:24:12 -0500, Tad McClellan wrote:
>>> You _can_ say "$hash{'abcd'}" or "$hash{'whatever I damn well
>>> please'}" and actually, you don't need the quotes;
> 
>> You don't need the quotes when the key matches /^\w+$/.
>> So you need the quotes for something like that 2nd one above.
> 
> Word of advice, but shouldn't one use quotes whenever possible?  I
> constantly use quotes, as it looks better in my editor (FTE).
> 
> I don't use quotes when working with variables, of course;
> 
>   my $value = $hash{ $key };
> 
> Hmm.  But I tend to carry around those spaces, I see. :-)  Easier to
> read? 

It's a matter of taste.  I prefer omitting the quotes, because to me,

    $hash{foo}

is analogous to

    $array[7]

and you don't write $array['7'], do you?  (even though you could, in 
Perl).

- -- 
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print

-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBP5e4gmPeouIeTNHoEQJUVgCfRdf4LiJdpHhjQggWURjQZErUDyoAoNlG
pUCI/8+2z1bi4oC8yjd5MA8O
=ocVj
-----END PGP SIGNATURE-----


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

Date: 23 Oct 2003 10:05:53 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Perl and IIS - script runs but 'The page cannot be displayed'
Message-Id: <slrnbpfa00.7uo.abigail@alexandra.abigail.nl>

stew dean (stewart@webslave.dircon.co.uk) wrote on MMMDCCV September
MCMXCIII in <URL:news:2b68957a.0310230145.498158bc@posting.google.com>:
**  "Alan J. Flavell" <flavell@ph.gla.ac.uk> wrote in message news:<Pine.LNX.4.53.0310230029460.11611@ppepc56.ph.gla.ac.uk>...
** > On Wed, 22 Oct 2003, stew dean acidicly remarked for the benefit of
** > the gallery:
** > 
** > > Thanks for what is probably the only helpful responce so far.
** > 
** > I think that's reached the plonk threshold now.  Bye.
**  
**  Hang on - why does your name ring a bell?  My god - it's the same Alan
**  Flavell I used to talk about HTML to way back in 1996. You where the
**  one who was saying HTML should not be used for layout. You even
**  suggested that all layout should be done in PDF at one point. Shame I
**  missed all your wining about Flash and what about style sheets?


*PLONK*

(I talked about HTML way back in 1996 (and even before as well). I said
 then, and I still say, that HTML should not be used for layout. I still
 suggest that PDF is an excellent format for that, and given the current
 state of HTML and browser, PDF is far more crossplatform than HTML).


Abigail
-- 
:$:=~s:$":Just$&another$&:;$:=~s:
:Perl$"Hacker$&:;chop$:;print$:#:


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

Date: Thu, 23 Oct 2003 11:33:28 +0100
From: "Alan J. Flavell" <flavell@ph.gla.ac.uk>
Subject: Re: Perl and IIS - script runs but 'The page cannot be displayed'
Message-Id: <Pine.LNX.4.53.0310231121460.12628@ppepc56.ph.gla.ac.uk>

On Thu, 23 Oct 2003, Abigail exposed the fact that:

> stew dean (stewart@webslave.dircon.co.uk) wrote on MMMDCCV September
> MCMXCIII in <URL:news:2b68957a.0310230145.498158bc@posting.google.com>:

> **  Hang on - why does your name ring a bell?  My god - it's the same Alan
> **  Flavell I used to talk about HTML to way back in 1996.

I was responding specifically to the current issues.  I saw no reason
to rake-over past acrimony.

>      You where the
> **  one who was saying HTML should not be used for layout.

I'm one who's saying that the web has now finally caught up with the
recognition that HTML would better not be used for layout.  The idea
of using stylesheets pre-dated RFC1866/HTML2.0, and it should have
been obvious to anyone who bothered to rub two brain cells together
that they were a good approach.  It's taken too long to get there, but
it's finally happening, and I find that development rather positive.

But it really has nothing to do with how and where to look for
solutions to IIS problems.

> *PLONK*

Well-plonked.  :-}

> (I talked about HTML way back in 1996 (and even before as well). I said
>  then, and I still say, that HTML should not be used for layout.

Indeed.

[f'ups prophylactically set...]


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

Date: 23 Oct 2003 04:02:54 -0700
From: stewart@webslave.dircon.co.uk (stew dean)
Subject: Re: Perl and IIS - script runs but 'The page cannot be displayed'
Message-Id: <2b68957a.0310230302.3ba9ece5@posting.google.com>

tiltonj@erols.com (Jay Tilton) wrote in message news:<3f96fb83.18919527@news.erols.com>...
> stewart@webslave.dircon.co.uk (stew dean) wrote:
> 
> : The code it's self, although clunky no doubt compared to the abilities
> : of many, works fine. 
> 
> Then the Perl problem has been solved.  Yay team!

Be nice.

> 
> : I'm thinking it's a set up issue with IIS.
> 
> You are probably right.
> 
> Since Perl is not IIS, an IIS-oriented newsgroup would be a more
> appropriate place to seek help than a Perl newsgroup. 

My problem is running perl script on IIS. So although it is not
strictly to do with the perl code it is to do with the running of
perl.

I was hoping that someone here might run perl on IIS and know what my
problem is.

> Right now, the only thing known about the error is that it exists.  That
> is not enough information to begin diagnosis.

There is no error from perl - that's my problem. 

Stew Dean


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

Date: Thu, 23 Oct 2003 14:25:14 +0200
From: Kåre Olai Lindbach <barbr-en@online.no>
Subject: Re: Perl and IIS - script runs but 'The page cannot be displayed'
Message-Id: <m3gfpvc6pnbq87egkg9ev4306shkj8kd59@4ax.com>

On 23 Oct 2003 02:29:29 -0700, stewart@webslave.dircon.co.uk (stew
dean) wrote:

>"Jürgen Exner" <jurgenex@hotmail.com> wrote in message news:<mjFlb.28443$Ee6.26897@nwrddc01.gnilink.net>...
>> stew dean wrote:
>> > The perl script is not buggy - it's running fine.
>> 
>> Then what is your problem? Apparently it has nothing to do with Perl or has
>> it?
>
>It's to do with the way perl is running on IIS - that is for some
>reason it is running but the output is not reaching the browser.
>
>It's also about finding out more about how Perl runs on windows. 
>
>Perl doesnt naturaly have an error log on windows from what I can see
>and so far I have been relying on the errors given to me in the
>headers returned -that is the usualy syntax and other errors that are
>returned by using strict.
>
>Now I'm exploring all the other suggestions but so far I've had not
>joy.

(I think you are wining alot, and putting yourself more and more into
a corner. It is often better to listen to the advices, think, and
rephrase questions and summerize that you have tried in a systematic
and quiet/calm way. If you start answering all inputs, and starts
making new unnecessary ones, as you have done, you will end up just
discussing nonsense.  I was just at the edge of plonking you :-).

I have some years experience (> 6) with MSwin32 and MS-IIS in
different environments, especially using CGI. I always use CGI::CARP
qw(fatalsToBrowser warningsToBrowser) during testing, besides those
obvious let-perl-help-you things. I also test syntaxt through my Emacs
shell as "perl -c <perl-script>", and often also run them, and watch
the raw output..

What I have experienced when running large output to browser from
MS-IIS, compared to small output, is that if it contains undefined
fields, it woun't show anything, not even an error, just time out.
Maybe that's your problem?

Also you might get timed-out if the output takes considerable longer
time to output. Then you need to send something to keep-alive, or use
other methods. Are you sure your big-scripts algorithm isn't so that
it takes considerably longer time to run, than a small one?

As I have understood, you are able to run small scripts correctly?!

-- 
mvh/Regards
Kåre Olai Lindbach


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

Date: Thu, 23 Oct 2003 13:24:53 +0200
From: Willem <willem@xs4all.nl>
Subject: Perl variable and C program
Message-Id: <f9efpvs4vu81udb01tnc8pgh6hgid1dpns@4ax.com>

Hi,

I've got difficulties with IPC in Perl. In my script a variable is
given to an c program. so far so good. Now I want to be interactive
with the c program and get back to my script when I type -1.
The next variable is then launched to my c program... and so on.
My problem is that I cannot be interactive with my c program.
Solutions??

thx , Willem 



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

Date: Thu, 23 Oct 2003 12:25:32 +0200
From: Tore Aursand <tore@aursand.no>
Subject: Re: Regex to extract row data from text (Copy of data included)
Message-Id: <pan.2003.10.23.05.37.11.511925@aursand.no>

On Wed, 22 Oct 2003 14:50:32 +0000, TimBenz wrote:
> Thanks for all the replies. Sorry for having been remiss in not posting the 
> exact data, but it's proprietary trading data for our money management 
> firm, so I didn't know what I could post. Here is a representative piece, 
> however, that I don't think should worry anyone:
> [...]

The data was wrapped, so I still don't know the original format.  It
seems, however, that it's quite hard to parse this data.

But!  If you're sure that you know the text on the first line, and that
the following lines are formatted as that line, you could always "cheat":

  1. Get the first line.
  2. Get the position of each column from that line.
  3. Iterate through the "remaining" lines, gathering the data
     based on the format of the first line.

Not a clever solution, but it would work.


-- 
Tore Aursand <tore@aursand.no>


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

Date: Thu, 23 Oct 2003 12:25:27 +0200
From: Tore Aursand <tore@aursand.no>
Subject: Re: Regex to extract row data from text
Message-Id: <pan.2003.10.23.05.22.41.259758@aursand.no>

On Wed, 22 Oct 2003 06:25:55 -0400, Chris Mattern wrote:
> When you're parsing input data, what is necessary is a true understanding
> of its syntax, not samples which will almost invariably fail to cover
> certain cases.  "The data looks like such-and-so" or "The data is in
> a form like this" is usually a red flag that the speaker doesn't understand
> his input data well enough to parse it properly.

Isn't that why Perl was created? :-)


-- 
Tore Aursand <tore@aursand.no>


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

Date: 23 Oct 2003 10:10:20 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: while each hash, why not array
Message-Id: <slrnbpfa8c.7uo.abigail@alexandra.abigail.nl>

Malcolm Dew-Jones (yf110@vtn1.victoria.tc.ca) wrote on MMMDCCIV September
MCMXCIII in <URL:news:3f96dc44@news.victoria.tc.ca>:
{}  Robert Wallace (robertw@nospam.acm.org) wrote:
{} : I can extract two values at a time from a hash with while, why not with
{} : an array?
{}  
{}  
{} : that is with 
{} : %hashish = ( a => 1, b => 2, c => 3);
{} : I can:
{} : while (($k,$v) = each %hashish ){
{} :     print "$k => $v\n";
{} : }
{}  
{}  
{} : why not:
{} :    while (($k,$v) = each @arr){
{} :        print "$k => $v\n";
{} :    }
{}  
{}  Because you aren't extracting two "values" at a time from the hash (and
{}  you're not extracting them using "while" either, though that's just
{}  pedantics).
{}  
{}  `each' extracts one key and the associated value from a hash.
{}  
{}  each is designed to work on hashes, not arrays.
{}  
{}  If each worked on array's (which would look nice sometimes) then it would
{}  presumably extract the next, single, value, which is basically what
{}  foreach does already.
{}  
{}  	# hypothetical "each" of array
{}  
{}  	while ( $v = each @arr)
{}  
{}  	# what you can do today
{}  
{}  	foreach my $v (@arr)


Nah, a hypothetical 'each' for arrays would be:

    while (my ($key, $value) = each @array) {
        # $key is the index, $value the value.
    }

Quite useful actually, no reason to write 

    for (my $key = 0; $key < @array; $key ++) {
        my $value = $array [$key];
        ...
    }



Abigail
-- 
perl -MLWP::UserAgent -MHTML::TreeBuilder -MHTML::FormatText -wle'print +(
HTML::FormatText -> new -> format (HTML::TreeBuilder -> new -> parse (
LWP::UserAgent -> new -> request (HTTP::Request -> new ("GET",
"http://work.ucsd.edu:5141/cgi-bin/http_webster?isindex=perl")) -> content))
=~ /(.*\))[-\s]+Addition/s) [0]'


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

Date: 23 Oct 2003 12:17:23 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: while each hash, why not array
Message-Id: <bn8gsj$n8a$2@mamenchi.zrz.TU-Berlin.DE>

Abigail  <abigail@abigail.nl> wrote in comp.lang.perl.misc:
> Malcolm Dew-Jones (yf110@vtn1.victoria.tc.ca) wrote on MMMDCCIV September
> MCMXCIII in <URL:news:3f96dc44@news.victoria.tc.ca>:
> {}  Robert Wallace (robertw@nospam.acm.org) wrote:
> {} : I can extract two values at a time from a hash with while, why not with
> {} : an array?
> {}  
> {}  
> {} : that is with 
> {} : %hashish = ( a => 1, b => 2, c => 3);
> {} : I can:
> {} : while (($k,$v) = each %hashish ){
> {} :     print "$k => $v\n";
> {} : }
> {}  
> {}  
> {} : why not:
> {} :    while (($k,$v) = each @arr){
> {} :        print "$k => $v\n";
> {} :    }
> {}  
> {}  Because you aren't extracting two "values" at a time from the hash (and
> {}  you're not extracting them using "while" either, though that's just
> {}  pedantics).
> {}  
> {}  `each' extracts one key and the associated value from a hash.
> {}  
> {}  each is designed to work on hashes, not arrays.
> {}  
> {}  If each worked on array's (which would look nice sometimes) then it would
> {}  presumably extract the next, single, value, which is basically what
> {}  foreach does already.
> {}  
> {}  	# hypothetical "each" of array
> {}  
> {}  	while ( $v = each @arr)
> {}  
> {}  	# what you can do today
> {}  
> {}  	foreach my $v (@arr)
> 
> 
> Nah, a hypothetical 'each' for arrays would be:
> 
>     while (my ($key, $value) = each @array) {
>         # $key is the index, $value the value.
>     }

That would be my idea too of what "each" should mean for an array.
However, there are other interpretations.  Besides Malcolm's (essentially
equivalent to "foreach"), there was

    while (my ($key, $value) = each @array) {
        # $key is an even-indexed element, $value an odd-indexed element
    }

which is also a plausible generalization of the behavior of "each",
though, I believe, not a very useful one.

Maybe this ambiguity is another reason why "each" hasn't been generalized.

Anno


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

Date: Thu, 23 Oct 2003 12:34:42 -0000
From: gbacon@hiwaay.net (Greg Bacon)
Subject: Re: while each hash, why not array
Message-Id: <vpfin2daahu832@corp.supernews.com>

In article <slrnbpfa8c.7uo.abigail@alexandra.abigail.nl>,
    Abigail  <abigail@abigail.nl> wrote:

: Nah, a hypothetical 'each' for arrays would be:
: 
:     while (my ($key, $value) = each @array) {
:         # $key is the index, $value the value.
:     }

Sweet!  Something like this?

    $ cat ArrayEach.pm
    package ArrayEach;

    use strict;

    require Exporter;
    our @ISA = 'Exporter';
    our @EXPORT = 'each';

    # next index
    my %iter;

    sub each (\[%@]) {
        my $that = shift;

        if (ref($that) eq "HASH") {
            return CORE::each %$that;
        }

        if (defined $iter{$that} && $iter{$that} >= @$that) {
            delete $iter{$that};
            return;
        }

        my $k = $iter{$that}++ || 0;
        my $v = $that->[$k];

        wantarray ? ($k, $v) : $v;
    }

    1;

    $ cat test-each
    #! /usr/local/bin/perl

    use warnings;
    use strict;

    use ArrayEach;

    my %h = (a => 1, b => 2, c => 3);
    my @a = qw/ apples oranges bananas /;

    my %core;
    while (my($k,$v) = CORE::each %h) {
        $core{$k} = $v;
    }

    my %new;
    while (my($k,$v) = each %h) {
        $new{$k} = $v;
    }

    for (keys %core) {
        warn "'$_' missing from new\n"
            unless exists $new{$_} && $new{$_} eq $core{$_};
    }

    for (keys %new) {
        warn "'$_' extra in new\n"
            unless exists $core{$_};
    }

    my @new;
    while (my($k,$v) = each @a) {
        push @new, [$k,$v];
    }

    warn "too many results: ", scalar @new, "\n"
        unless @new == @a;

    for (my $i = 0; $i < @new; ++$i) {
        warn "bad key at $i ($new[$i]->[0])\n"
            unless $i == $new[$i]->[0];

        warn "bad value at $i ($new[$i]->[1])\n"
            unless $a[$i] eq $new[$i]->[1];
    }

    print "Done\n";

    __END__

Greg
-- 
While the federal government is frustrating when it treats economic
problems with nonchalance, it is terrifying when it gets involved.
    -- Bob Novak


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

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


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