[19524] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1719 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Sep 9 18:05:50 2001

Date: Sun, 9 Sep 2001 15:05:09 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1000073108-v10-i1719@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sun, 9 Sep 2001     Volume: 10 Number: 1719

Today's topics:
    Re: a mystery to me: EOF (Alan Barclay)
    Re: Arrays, References and indexes. <sudhir@newmail.net>
    Re: Arrays, References and indexes. <chengkail@home.com>
    Re: Baiting Gozilla to obtain quality code for nothing! <matthew.garrish@sympatico.ca>
    Re: CR/LF (Tim Hammerquist)
    Re: Disappearing Compiler messages <flavell@mail.cern.ch>
    Re: Evaluation order of object methods <djberg96@hotmail.com>
    Re: free guestbook script <rob_13@excite.com>
    Re: guestbook <rob_13@excite.com>
        inter process communication <gortona@cs.man.ac.uk>
        Inter-Process Communication <gortona@cs.man.ac.uk>
        lost children after fork() <brandon_usenet@2i.com>
    Re: Net::Telnet.pm and the Escape Key <iltzu@sci.invalid>
        Pattern Matching (shaz)
    Re: Pattern Matching <krahnj@acm.org>
    Re: Perl objects problems <Tassilo.Parseval@post.rwth-aachen.de>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 9 Sep 2001 15:21:26 GMT
From: gorilla@elaine.furryape.com (Alan Barclay)
Subject: Re: a mystery to me: EOF
Message-Id: <1000048886.138776@elaine.furryape.com>

In article <9mpunp$kr0$1@ichaos.ichaos-int>,
Juha Laiho  <Juha.Laiho@iki.fi> wrote:
>of bytes actually read from the stream. If no additional error condition
>is set (in a global variable errno), and the number of bytes read was
>smaller than the number of bytes desired, then the read() encountered the
>end of file.

Not neccessarily. read(2) returns as many bytes as it feels like, which
may be less than the program asked for. This is particularly true when
reading from a socket, pipe, or device, but even when reading from
a real file, it's possible for the read() to return early.


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

Date: Sun, 09 Sep 2001 20:06:43 GMT
From: Sudhir Krishnan <sudhir@newmail.net>
Subject: Re: Arrays, References and indexes.
Message-Id: <3B9BCC9B.3C2AC609@newmail.net>

This is a multi-part message in MIME format.
--------------02F1F10F963F2A424F3F6C7F
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit

Thanks Martien!
 Actually I've got the code working as I want. It's just that
since I'm new to perl, I think my code is Cish.

I was just wanting to know if I can reduce the lines the code
and make it more perlish!

I'm just attaching 2 sample data files, just in case you're interested
in knowing more about the problem.

I'm finding it a little difficult to explain the problem in
a simple way without getting into too much detail!!

Anyway, here goes. This is just FYI.

Actually I simplified the problem a bit, when I posted.
The way the data is defined, the data structure is 4D.

The way to read the data files. p1 and p2
 first 2 lines: result header
  next 3 lines: cgi header
  next 3 lines: system wide stanza (another header)

<main body>

  3rd and 4th last lines: physical system trailer
  2nd last and last lines: file trailer.
####################################################3

The body consists of 'stanzas'

Each stanza starts with "*FC ????????"

So all text, starting with *FC until the next *FC is a stanza.

I process each file convert stanza to line format for simplicity.

i.e into something line:

*FC=????????&data1=value&data2=value ....

Stanzas in the file are grouped together as follows:

System Stanza
  Subsystem Stanza
  Subsystem Stanza
  .
  .
  .
System Stanza
  subsystem stanza
  subsystem stanza  
  .
  .

So each stanza with its subsystem stanzas is what I called
a 'section'

The problem is to come up with one ouput file, that'll contain
all the system stanzas from all files.
Also all subsystem stanzas should be present under them.
Corresponding system stanzas can have duplicate sub-system stanza
entries, duplicates should be removed

After I process each file, it'll look something like:

FC=????????&*VC=5.0&*TM=1&*YL=U1.17&*SE=1&*VK=&
ss[0][0]
ss[0][1]
ss[0][2]
ss[0][3]
ss[0][4]
ss[0][5]
*FC=????????&*VC=5.0&*TM=2&*YL=U1.17&*SE=2&*VK=&
ss[1][0]
ss[1][1]
ss[1][2]
ss[1][3]
ss[1][4]
ss[1][5]

Imagine a second file thats the same as above, but with
ss[a][b] instead of ss[0][4]

Then the output file will be the same as the input files
except that the first system stanza except there will be
an additional entry ss[a][b] in the first section.

Do you think this problem is worthy of perl?

thanks
Sudhir



> 
> On Sun, 09 Sep 2001 11:59:50 GMT,
>         Sudhir Krishnan <sudhir@newmail.net> wrote:
> 
> > i=file index
> > j=section index in file
> 
> How do you distinguish between the 'sections'?
> 
> > k=line (record) index in (file, section)
> 
> > While iterating over the files, I'm storing it as:
> >
> > a[i][j][k] = $_;
> >
> > And it seems to work fine.
> >
> > Problems:
> > 1) I don't really understand the underlying implementation
> >    with references.
> 
> Have you read the documentation, specifically perlref, perllol and
> perldsc? They go into quite some detail about how perl references, and
> perl's complex data structures work..
> 
> > 2) I use a[i][j][k] for getting/setting values, its
> >    3 loops and is cumbersume.
> 
> You will, most likely need three loops. However, you may not need them
> all explicitly. You could do something like:
> 
> Read the line into a (lexically scoped) array, splitting it. Then use an
> assignment like:
> 
> $a[i][j] = \@array;
> 
> or, if the array needs to be reused, store a reference to a copy of the
> array:
> 
> $a[i][j] = [@array];
> 
> Of course, you can do the same thing with the files, one level up.
> You'll still be using three iterations, just not as specific anymore,
> maybe.
> 
> > 3) I'd like to know how I can get/set values without using indexes.
> >
> >   i.e for a simple array:
> > instead of
> >    for ($i=0; $i <=$#ARR; $i++)
> >
> > I'd like to use
> >    for $val (@ARR)
> >
> > But in my case, $val will be a reference until I read the 3rd level,
> > right?
> 
> I'm not entirely sure what you mean. $val, in this for loop, will always
> specifically be an alias (not the same as a reference, but similar) to
> the things you're iterating over. If there isn't anything yet to be an
> alias to, then how can this work? I mean, you're filling the data
> structure, right? So the data and the references aren't there yet...
> 
> If these things that you work with are all numbered, what's wrong with
> using indexes? If you'd rather use push to add new data to the end, you
> could do something like (untested pseudo-code follows):
> 
> my @files;
> 
> foreach my $file (@files)
> {
>     my @sections;   # all the sections in a file
>     my @section;    # the records in a single section in a file
> 
>     open my $fh, $file or die $!;
>     while (<$fh>)
>     {
>         if (line_looks_like_new_section)
>         {
>             push @sections, [@section];
>             @section = ();
>         }
>         else
>         {
>             my @records = split;
>             push @section, \@records;
>         }
>     }
> 
>     push @array, \@sections;
> }
> 
> ... unless I've misunderstood your structure. If I have, I'm sure you'll
> be able to get the idea and adapt it to your needs.
> as you can see, you can just store a reference to @sections and
> @records, since they will go out of scope immediately after you've
> stored them, and therefore won't be reused. @section, however, stays in
> scope, and therefore, you need to make a copy of the array, and store a
> reference to that, and empty the array after that.
> 
> Martien
> 
> PS. If you provide some real data next time, not much, but just enough,
> I might be tempted to write some real code.
> --
> Martien Verbruggen              | Since light travels faster than
> Interactive Media Division      | sound, isn't that why some people
> Commercial Dynamics Pty. Ltd.   | appear bright until you hear them
> NSW, Australia                  | speak?
--------------02F1F10F963F2A424F3F6C7F
Content-Type: text/plain; charset=UTF-8;
 name="p1"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="p1"

RESULT=0

1
osimage
discord.austin.ibm.com
*VC 15.0
*N1 1.3.0.0
*DC Tue Jan 16 14:42:42 CST 2001
*FC ????????
*VC 5.0
*TM 7017-S90
*SE 8386522
*PI 123456789
*OS 4.3.0.0
*FC ????????
*VC 5.0
*TM 7017-S90
*YL U1.17
*SE 8386522
*VK 
*FC ????????
*VC 15.0
*N1 1.3.0.0
*OS 4.3.0.0
*Z1 ssp.basic 3.2.0.0
*Z2 ssp.css 3.2.0.0
*VD discord.austin.ibm.com:001:partition one 
*DC Tue Jan 16 14:42:42 CST 2001
*FC ????????
*VC 5.0
*FB @@@@@@@@
*PN 00000000
*PL 00-00
*AX sys0
*FC ????????
*DS RS M CEC OP PAN
*YL U1.17-L1
*SN YL1620012285
*EC F73731
*CC 248B
*FN  24L1089
*DC BD 199911221000
*VK RS6K
*FC ????????
*DS Memory Card
*YL U1.17-TEST1
*FN 4A85
*EC 0000
*PN 0000023L7544
*SN 09351056
*MN 0016
*SZ 0256
*VK RS6K
*FC ????????
*DS 2.2 GB 16 Bit SCSI Disk Drive
*AX hdisk0
*PL 10-60-00-8,0
*MF IBMRISC
*TM DFHSS2W
*PN 74G6984
*RL 34323432
*SN 00BF3943
*EC 486509
*FN 27H0262
*Z0 000002029F00003E
*Z1 RAMST04B
*Z2 0068
*Z3 97092
*Z4 0002
*Z5 22
*Z6 484547
*YL U1.17-TEST2
*FC ????????
*FB @@@@@@@@
*PN 00000000
*PL 00-00
*AX sys0
*FC ????????
*VC 5.0
*TM 7088-888
*YL U1.18
*SE 98765432
*VK 
*FC ????????
*VC 15.0
*N1 1.3.0.0
*OS 4.3.0.0
*VD discord.austin.ibm.com:001:partition one 
*DC Tue Jan 16 14:42:42 CST 2001
*FC ????????
*VC 5.0
*DS IBM Air Mover
*YL U1.18-F1
*FN  07H5349
*VK RS6K
*FC ????????
*DS IBM Air Mover
*YL U1.18-F2
*FN  07H5349
*VK RS6K
*FC ????????
*DS IBM Air Mover
*YL U1.18-F3
*FN  07H5349
*VK RS6K
*FC ????????
*DS IBM Air Mover
*YL U1.18-F4
*FN  07H5349
*VK RS6K
*FC ????????
*DS 8-32W BACKPLANE
*YL U1.18-P1
*SN YL100LAB0000
*PN 23L2829
*CC 25C0
*FN  11P3046
*VK RS6K
*FC ????????
*DS 8-W 1.3GHZ MCM
*YL U1.18-P1-C1
*SN YL1108888888
*PN 7777777
*CC 25D3
*FN  04N5555
*MD 0000
*VK RS6K
*FC ????????
*DS L3 VPD/ERROR LOG
*YL U1.18-P1-C10
*SN YL1108388888
*PN 7777777
*CC 25D9
*FN  04N5555
*SZ 32
*EC
*BH
*MD 0000
*VK RS6K
*FC ????????
*DS L3 VPD/ERROR LOG
*YL U1.18-P1-C11
*SN YL1108288888
*FC ????????
*VC 5.0
*TM 7040-618
*YL U0.4
*SE 987654321
*VK
*FC ????????
*VC 15.0
*N1 1.3.0.0
*OS 4.3.0.0
*VD discord.austin.ibm.com:001:partition one
*DC Tue Jan 16 14:42:42 CST 2001
*FC ????????
*VC 5.0
*FB @@@@@@@@
*PN 00000000
*PL 00-00
*AX sys0
*FC ????????
*DS Wide/Fast-20 SCSI I/O Controller
*AX scsi4
*FN 97H7610
*YL U0.4-P1-I7-Z1-A2
*FC ????????
*DS 16Bit SCSI Disk Drive
*AX hdisk1
*PL 30-68-00-8,0
*MF IBM
*TM DGHS09U
*FN 59H6926
*RL 30334530
*SN 68206A52
*EC E31898
*PN 59H6816
*Z0 0003029F00013A
*Z1 GAGSPR603E
*Z2 09RI
*Z3 99022
*Z4 0001
*Z5 22
*Z6 E31777
*YL U0.4-P1-I13-Z1-A8
====================
0
====================
0

--------------02F1F10F963F2A424F3F6C7F
Content-Type: text/plain; charset=UTF-8;
 name="p2"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="p2"

RESULT=0

1
osimage
jeana.austin.ibm.com
*VC 15.0
*N1 1.3.0.0
*DC Tue Jan 16 14:42:42 CST 2001
*FC ????????
*VC 5.0
*TM 7017-S90
*SE 8386522
*PI 123456789
*OS 4.3.0.0
*FC ????????
*VC 5.0
*TM 7017-S90
*YL U1.17
*SE 8386522
*VK
*FC ????????
*VC 15.0
*N1 1.3.0.0
*OS 4.3.0.0
*Z1 ssp.basic 3.2.0.0
*Z2 ssp.css 3.2.0.0
*VD jeana.austin.ibm.com:2:partition two 
*DC Tue Jan 16 14:42:42 CST 2001
*FC ????????
*VC 5.0
*FB @@@@@@@@
*PN 00000000
*PL 00-00
*AX sys0
*FC ????????
*DS RS M CEC OP PAN
*YL U1.17-L1
*SN YL1620012285
*EC F73731
*CC 248B
*FN  24L1089
*DC BD 199911221000
*VK RS6K
*FC ????????
*DS Memory Card
*YL U1.17-TEST1
*FN 4A85
*EC 0000
*PN 0000023L7544
*SN 09351056
*MN 0016
*SZ 0256
*VK RS6K
*FC ????????
*DS 2.2 GB 16 Bit SCSI Disk Drive
*AX hdisk0
*PL 10-60-00-8,0
*MF IBMRISC
*TM DFHSS2W
*PN 74G6984
*RL 34323432
*SN 00BF3943
*EC 486509
*FN 27H0262
*Z0 000002029F00003E
*Z1 RAMST04B
*Z2 0068
*Z3 97092
*Z4 0002
*Z5 22
*Z6 484547
*YL U1.17-TEST2
*FC ????????
*FB @@@@@@@@
*PN 00000000
*PL 00-00
*AX sys0
*FC ????????
*VC 5.0
*TM 7088-888
*YL U1.18
*SE 98765432
*VK 
*FC ????????
*VC 15.0
*N1 1.3.0.0
*OS 4.3.0.0
*VD jeana.austin.ibm.com:2:partition two 
*DC Tue Jan 16 14:42:42 CST 2001
*FC ????????
*VC 5.0
*DS IBM Air Mover
*YL U1.18-F1
*FN  07H5349
*VK RS6K
*FC ????????
*DS IBM Air Mover
*YL U1.18-F2
*FN  07H5349
*VK RS6K
*FC ????????
*DS IBM Air Mover
*YL U1.18-F3
*FN  07H5349
*VK RS6K
*FC ????????
*DS IBM Air Mover
*YL U1.18-F4
*FN  07H5349
*VK RS6K
*FC ????????
*DS 8-32W BACKPLANE
*YL U1.18-P1
*SN YL100LAB0000
*PN 23L2829
*CC 25C0
*FN  11P3046
*VK RS6K
*FC ????????
*DS 8-W 1.3GHZ MCM
*YL U1.18-P1-C1
*SN YL1108888888
*PN 7777777
*CC 25D3
*FN  04N5555
*MD 0000
*VK RS6K
*FC ????????
*DS L3 VPD/ERROR LOG
*YL U1.18-P1-C10
*SN YL1108388888
*PN 7777777
*CC 25D9
*FN  04N5555
*SZ 32
*EC
*BH
*MD 0000
*VK RS6K
*FC ????????
*DS L3 VPD/ERROR LOG
*YL U1.18-P1-C11
*SN YL1108288888
*FC ????????
*VC 5.0
*TM 7040-618
*YL U0.4
*SE 987654321
*VK
*FC ????????
*VC 15.0
*N1 1.3.0.0
*OS 4.3.0.0
*VD jeana.austin.ibm.com:2:partition two
*DC Tue Jan 16 14:42:42 CST 2001
*FC ????????
*VC 5.0
*FB @@@@@@@@
*PN 00000000
*PL 00-00
*AX sys0
*FC ????????
*DS Wide/Fast-20 SCSI I/O Controller
*AX scsi4
*FN 97H7610
*YL U0.4-P1-I7-Z1-A2-par2
*FC ????????
*DS 16Bit SCSI Disk Drive
*AX hdisk1
*PL 30-68-00-8,0
*MF IBM
*TM DGHS09U
*FN 59H6926
*RL 30334530
*SN 68206A52
*EC E31898
*PN 59H6816
*Z0 0003029F00013A
*Z1 GAGSPR603E
*Z2 09RI
*Z3 99022
*Z4 0001
*Z5 22
*Z6 E31777
*YL U0.4-P1-I13-Z1-A8-par2
====================
0
====================
0

--------------02F1F10F963F2A424F3F6C7F--



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

Date: Sun, 09 Sep 2001 21:01:42 GMT
From: "chengkai liang" <chengkail@home.com>
Subject: Re: Arrays, References and indexes.
Message-Id: <WMQm7.58115$MK5.32127565@news1.sttln1.wa.home.com>

This like a two-level file structure. You have a section and a number of
lines in each section for a given file. For a better solution that I can
have is a hash of lists or if each line has its own key then may be a hash
of hashs will be your answer.

Suppose we have a file call sections.dat and it has the following data
within it,

[section_1]
key1 = abc
key2 = def
key3 = ghi

[section_2]
key1 = abc
key2 = def
key3 = ghi

and so on.

In Perl you can have a hash of hashs to represent this structure, which is
like below

    $hash = {
         'section_1' => {
                    'key1' => 'abc',
                    'key2' => 'def',
                    'key3' => 'ghi',
         },
         'section_2' => {
                   'key1' => 'abc',
                   'key2' => 'def',
                   'key3' => 'ghi',
        }
  };

So when retrive the data you can say,

     $val = $hash->{section_1}{key1};

which makes $val eq 'abc'.

Now the problem comes to how do you parse the whole file into a hash
structure like above?

Bellow is the code snippet that will do so.

You can easily change the code to read multi-files in and save them to a
hash of hashs of hashs
structure ...

PS: The attached file, section.txt, contains the sample data in it.
~Mike Liang

Code start here!!
---------
use strict;
use warnings;

use Data::Dumper;

# create and initlize a hash reference
my $hash = undef;

# open a file
open (FH, '<', 'section.txt')
   or die "unable to open file: section.txt for $!\n";

# the section key has to be outside of the loop; otherwise you will lost it
when
# the mached valuable $1 and $2 chnaged.
my $section_key;
while (<FH>) {
   next if /^$/;       # skip the empty line if any
   if ( $_ =~ m!\[(.*)\]! ) { # grab a section name from within '[' and ']'
       $section_key = $1;    #  hold the key we have
   }
   else {
        if (/(.*?)\s*=\s*(.*)/) { # get the second pair of key/value and
store them into a hash
            # here's the autovivification happened.
            $hash->{$section_key}{$1} = $2;
        }
   }
}

close FH;

# dump the $hash reference structure out
print Dumper ($hash);


"Sudhir Krishnan" <sudhir@newmail.net> wrote in message
news:3B9B5A80.9D2198E3@newmail.net...
> Hi,
>
> I've been using perl since a week.
>
> I need to read in a number of files and use an appropriate
> data-structure for the same.
>
> Each file is divided into a number of sections.
> Each line will be a record
>
>
>  file 1    file 2   file 3
> [     ]  [     ]  [     ]
> [     ]  [     ]  [     ]
>   ---     ---      ---
> [     ]  [     ]  [     ]
> [     ]  [     ]  [     ]
>   ----     ----    ----
> [     ]  [     ]  [     ]
> [     ]  [     ]  [     ]
>
> Something like a triple dimensional array seems to suit the purpose.
>
>
> a[i][j][k];
>
> i=file index
> j=section index in file
> k=line (record) index in (file, section)
>
>
> While iterating over the files, I'm storing it as:
>
> a[i][j][k] = $_;
>
> And it seems to work fine.
>
> Problems:
> 1) I don't really understand the underlying implementation
>    with references.
>
> 2) I use a[i][j][k] for getting/setting values, its
>    3 loops and is cumbersume.
>
> 3) I'd like to know how I can get/set values without using indexes.
>
>   i.e for a simple array:
> instead of
>    for ($i=0; $i <=$#ARR; $i++)
>
> I'd like to use
>    for $val (@ARR)
>
> But in my case, $val will be a reference until I read the 3rd level,
> right?
>
> Sample code would be really appreciated!!
>
> thanks!
> Sudhir


begin 666 section.txt
M6W-E8W1I;VY?,5T-"FME>3$@/2!A8F,-"FME>3(@/2!D968-"FME>3,@/2!G
M:&D-"@T*6W-E8W1I;VY?,ET-"FME>3$@/2!A8F,-"FME>3(@/2!D968-"FME
(>3,@/2!G:&D`
`
end



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

Date: Sun, 9 Sep 2001 16:15:57 -0400
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: Baiting Gozilla to obtain quality code for nothing!!
Message-Id: <c2Qm7.2359$2r.286869@news20.bellglobal.com>


"Helgi Briem" <helgi@NOSPAMdecode.is> wrote in message
news:3b9898ba.753992293@news.isholf.is...
> >
> Lot's of guys call themselves "Queens".
>

Until I learned that this Godzilla goes by the "name" kira and claims to be
female, that's exactly what I took the monikers to mean. Whoever this person
is, s/he definitely has some serious issues. A desperate need for attention
coupled with an underlying fear of being exposed isn't the sign of a normal
person. I've taken the route of ignoring anything it writes now because it
isn't worth the wasted effort to get through the pretentious verbosity to
see what it has to say - and anyone who hides behind pseudonyms isn't worth
debating with.

Matt




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

Date: Sun, 09 Sep 2001 19:45:26 GMT
From: tim@vegeta.ath.cx (Tim Hammerquist)
Subject: Re: CR/LF
Message-Id: <slrn9pnidq.9q.tim@vegeta.ath.cx>

Me parece que Alan J. Flavell <flavell@mail.cern.ch> dijo:
> On Sep 9, Tim Hammerquist inscribed on the eternal scroll:
> 
> > Me parece que Sean Hamilton <sh@planetquake.com> dijo:
> > > Greetings,
> > >
> > > I am assuming \r translates directly to CR, but does \n always translate to
> > > LF? Or does it translate to LF on Unix, CR on Mac, CRLF on Windows? Is it
> > > identical in behavior to C's \n escape?
> >
> > The perlport manpage discusses '\n' as the "logical" newline, silently
> > converting to and from whatever it should be, usually intelligently
> > enough.  OTOH, as perlport says, \n cannot always be trusted.
>                                       ^^^^^^^^^^^^^^^^^^^^^^^^
> I suggest that may have been an unfortunate choice of terms: the
> string "trust" doesn't appear anywhere in the copy of perlport that
> I'm looking at - though I think I see what you're getting at.  You can
> perfectly well _trust_ Perl to behave to specification on this issue:
> the important thing is to know what that specification says ;-)

You're correct re. the POD that came with my 5.6.1 dist.  I regret that
my paraphrasing is not always what it should be.

> Older versions of Perl documentation showed unfortunate signs in this
> area of having been composed by unix bigots.  But recent versions are
> more even-handed in this regard.  Unix is quite able to demonstrate
> its superiority without any need for bigotry ;-))  - and since Perl
> rightly stresses benefits of portability, its documentation clearly
> needs to reflect that fact.

Very well put. =)

> > If the
> > actual value of \n is important or even in question, it's possible you
> > should specify explicitly what you want. ("\012" for newline, "\015" for
> > carriage-return).
> 
> Indeed.  And as a general rule, if you're working with \n and \r then
> you want to open in text mode, whereas if you're working with \012 and
> \015 then you want to open with binmode().  However, it's better to
> understand what one's doing and why (based for example on that perldoc
> perlport page), in preference to applying "as a general rule"
> recipes by rote.  IMHO, of course.
> 
> good luck
> 


-- 
It is a fool's prerogative to utter
truths that no one else will speak.
    -- Morpheus, The Sandman


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

Date: Sun, 9 Sep 2001 17:05:41 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Disappearing Compiler messages
Message-Id: <Pine.LNX.4.30.0109091654340.13081-100000@lxplus023.cern.ch>

On Sep 9, Benjamin Goldberg inscribed on the eternal scroll:

> > > Try putting this somewhere near the top of your script:
> > >       use CGI::Carp qw(fatalsToBrowser);
> >
> > Quite how is this supposed to help with scripts that don't compile?
>
> Read up on the difference between 'use' and 'require', and you'll see.

Apologies for the brain-check.




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

Date: Sun, 09 Sep 2001 21:12:23 GMT
From: "Daniel Berger" <djberg96@hotmail.com>
Subject: Re: Evaluation order of object methods
Message-Id: <XWQm7.6996$Q6.777712@typhoon.mn.mediaone.net>

<snip, snip>
>>"Benjamin Goldberg" <goldbb2@earthlink.net> wrote in message
news:3B9B7C07.2D0DDE52@earthlink.net...
> Much of perl tries to DWIM.  It's better, IMHO, to look at the context,
> and guess what the user wants to do.  The reason this is reasonable is
> that when you want to get around this dweomer, you can:
> ($a, $b) = (1, scalar foo()); # force scalar context
> or
> $x = (() = foo()); # force list context
> or
> ($x) = foo(); # another way to force list context
> or
> do{foo();1} # force void context.
>
> > e.g.
> > my $len = $sao->unique()->length(); # Modifies object
> > my $len = $sao->unique(1)->length(); # Doesn't modify object
>
> I would do it as, in non-void context, always makes a new object, and in
> scalar context, always returns a reference.

<snip>

Ah, see the fairly new "Want" module by Robin Houston that lets me have my
cake and eat it, too after all.  For ease of method chaining, I can now do
"if(want('OBJECT')){ return $self }.  Looks like there are some other uses I
may have for it.  I didn't notice this module until last week, though it's
been around since mid-july apparently. :|

So, now that I just about finished what I had...I get to start over. :(

Regards,

Dan






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

Date: Sun, 09 Sep 2001 21:32:54 GMT
From: "Rob - Rock13.com" <rob_13@excite.com>
Subject: Re: free guestbook script
Message-Id: <Xns9117B27A43198rock13com@64.8.1.226>

stewie <news:9nfm1l$pp$1@news.planetinternet.be>:

> Does anyone know where i can find a free and easy to install
> guestbook script on the net.
> 
> The owner of the guestbook should be able to reply to the
> messages that are posted, so that his response appears below
> the posted message. 

See my reply to your other post.

-- 
Rob - http://rock13.com/
Web Stuff: http://rock13.com/webhelp/


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

Date: Sun, 09 Sep 2001 21:30:36 GMT
From: "Rob - Rock13.com" <rob_13@excite.com>
Subject: Re: guestbook
Message-Id: <Xns9117B2164BCA4rock13com@64.8.1.226>

stewie <news:9nflen$dh$1@news.planetinternet.be>:

You are posting upside down. Read this:
http://www.xs4all.nl/%7ewijnands/nnq/nquote.html

>> stewie wrote: 
>> >I've downloaded the perl code for a guestbook
> http://www.cougasoft.org/guestbook/index.html
>> >It works fine, but it needs one more thing:
>> >The owner of the guestbook should be able to give a reaction
>> >on the guestboard true the admin tool.

Did you suggest this to the author? What you want sounds more like 
a BBS or forum.

> I have tried to study the code, but it is too complex for me.
> I found out that it is possible to add text in the data-file
> manually. But to built in a function in the admin tool is too
> complex for me. 

Chances are the author would rather not have you mucking about 
modifying his software beyond what is necessary.

> Or: if you know where i can find a script on the net for a
> guestbook in which the guestbook
> owner can reply, i would be happy if you told me.

Check cgi-resouces.com perlarchive.com google.com

I'd offer to modify it for you, but I'm working on my own gb right 
now. And I'd rather not do it without explicit permission from the 
author.

You could skip adding a feature to the admin tool and just write 
your own script to do just what you want. Just use flock and you 
shouldn't mess anything up.
-- 
Rob - http://rock13.com/
Web Stuff: http://rock13.com/webhelp/


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

Date: Sun, 09 Sep 2001 15:27:17 +0100
From: Andrew Paul Gorton <gortona@cs.man.ac.uk>
Subject: inter process communication
Message-Id: <3B9B7C45.E2C7E1B9@cs.man.ac.uk>

Hi,

I have a client/server where the server receives requests from the
client and forks a number of processes which will continue to run until
the client sends a stop.

The client has the ability to send reconfiguration data to the server
which passes this to the relevant processes.  The server also needs the
ability to get information from the processes when asked by the client.

Therefore the server needs bi-directional communication with the
processes it has forked.  At the moment the server writes parameters to
a file, which the processes reads.  The processes then write to a file,
which the server reads to send back data to the client.  However, with a
large number of processes there will be a concurrence issue.

Is there a neater way to achieve this communication

Any help appreciated


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

Date: Sun, 09 Sep 2001 11:16:41 +0100
From: Andrew Paul Gorton <gortona@cs.man.ac.uk>
Subject: Inter-Process Communication
Message-Id: <3B9B4189.171A7C34@cs.man.ac.uk>

Hi All,

I have written a client/server application.  On the server process I
need it to parse the request from the client and run other processes
(which run continually or until the client sends a stop).  I need to be
able to pass parameters to these processes from the server and also get
information back - bi-directional communication.

At the moment I am using fork to run the other processes from the
server, which then read their parameters from a file and also write
their output to a file which the server reads and sends the info back to
the client.  This is going to cause me problems when I have several
processes running because of concurrence.  Is there another way ie could
I use pipes and is so how, I have been trying to sort this for days.

Cheers for any help 
Andy


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

Date: Sun, 09 Sep 2001 19:38:58 GMT
From: Brandon Hines <brandon_usenet@2i.com>
Subject: lost children after fork()
Message-Id: <3B9C6E2E.4080705@2i.com>

I am attempting to write some code that will run a few pools of sub 
processes.  I think I've got this fork() thing figured out but I am 
having one problem--I leave defunct children.

Here are two code samples.  I stripped out all the redundancy and have 
just enough code to demonstrate my problem.  The first one launches all 
my children, does something useful, waits a seconds, and repeats.  My 
something useful will probably be looking in a directory for new files 
to process up provide status updates.  This works great but on occasion 
leave defunct processes.  I am assuming that the signal handler gets 
stepped on when two or more children die at the same time?

So I wrote a second bit of code (OK, I just modified it).  With this 
one, instead of implementing a signal handler, I just wait at the bottom 
of my loop.  This works great, but I can only do my periodic work after 
a child dies.  In my real application this could take a few minutes. 
I'd hate to stall all my other processing for that long.

I guess my question is, is this a bug in the signal handling code in 
perl?  Is there any clean way around it?  The cleanest method I can 
think of is to use my second program and either send a signal from 
another program or spawn another child whose sole purpose is to die 
periodically.  Any advice or explanations?

BTW, the problem become really pronounced when I launch a large number 
of child processes:  for example:  'fork1.pl 100 2000'

-Brandon

Code Snippet 1
================================
#!/usr/bin/perl -w
# Test to see how this fork thing really works.
#
# Process: this program spawns a user definable number of
#   processes that perform the ever so important task of
#   counting to four with a random pause between each count.
#   When a process finishes, the main program increments
#   a counter and launches another process.
# Results: works great, but sometimes leaves defunct processes
#   with high number of sub processes.

my $max = (shift || 3); # how many concurrent processes
my $end = (shift || 9); # how many total processes
my $live = 0;           # how many processes are alive
my $value;              # name of current sub process
my $loop = 0;           # number of current sub process

print "Max number of sessions: $max \n\n";

$SIG{CHLD} = \&REAPER;

while ($loop < $end or $live) {           # if any left to crunch
    while ($live < $max and $loop < $end) {#if room for another process
       $live++;
       $value = "thing-" . $loop++;
       unless (fork) { &run($value); }
    }
    # do something useful!
    print "\t\t\t\t*** $live alive\n";
    sleep 1;
}

sub run() {
   my $value = shift;
   my $rs = 4;   # number of random seconds
   my $paws = int(rand() * $rs) + 1;
   my $x;        # work counter

   print "Opening $value [$paws]\n";
   sleep $paws;
   for ($x=0; $x<4; $x++) {
     print "\t${value}:${x}\t[$paws]\n";
     sleep $paws;
   }
   print "Closing $value\n";
   exit;
}

sub REAPER {
    $SIG{CHLD} = \&REAPER;       # is this necessary on linux?
    wait;
    $live--;
}
================================


Code Snippet 1
================================
#!/usr/bin/perl -w
# Test to see how this fork thing really works.
#
# Process: this program spawns a user definable number of
#   processes that perform the ever so important task of
#   counting to four with a random pause between each count.
#   When a process finishes, the main program increments
#   a counter and launches another process.
# Results: no defunct processes, but I only get status
#   updates when a child dies.  Will not work if I need
#   other periodic events.  Might need to signal from an
#   external program instead of scanning.

my $max = (shift || 3); # how many concurrent processes
my $end = (shift || 9); # how many total processes
my $live = 0;           # how many processes are alive
my $value;              # name of current sub process
my $loop = 0;           # number of current sub process

print "Max number of sessions: $max \n\n";

while ($loop < $end or $live) {           # if any left to crunch
    while ($live < $max and $loop < $end) {#if room for another process
       $live++;
       $value = "thing-" . $loop++;
       unless (fork) {
          &run($value);
       }
    }
    print "\t\t\t\t*** $live alive\n";
    wait;
    $live--;
}

sub run() {
   my $value = shift;
   my $rs = 4;   # number of random seconds
   my $paws = int(rand() * $rs) + 1;
   my $x;        # work counter

   print "Opening $value [$paws]\n";
   sleep $paws;
   for ($x=0; $x<4; $x++) {
     print "\t${value}:${x}\t[$paws]\n";
     sleep $paws;
   }
   print "Closing $value\n";
   exit;
}




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

Date: 9 Sep 2001 18:29:04 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: Net::Telnet.pm and the Escape Key
Message-Id: <1000060082.23873@itz.pp.sci.fi>

In article <3B91468A.481ADCF2@acm.org>, John W. Krahn wrote:
>Matthias Wegener wrote:
>> 
>> is it possible to emulate a stroke on the escape key on the keyboard via
>> the Telnet.pm? I mean, what (and how escaped) string is to be send to
>> accomplish this?
>> $telnet->cmd('???');
>
>my $ESC = "\x1b";

  $telnet->cmd("\e");

-- 
Ilmari Karonen -- http://www.sci.fi/~iltzu/
"Get real!  This is a discussion group, not a helpdesk.  You post something,
we discuss its implications.  If the discussion happens to answer a question
you've asked, that's incidental."           -- nobull in comp.lang.perl.misc



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

Date: 9 Sep 2001 10:38:33 -0700
From: ssa1701@yahoo.co.uk (shaz)
Subject: Pattern Matching
Message-Id: <23e71812.0109090938.4dbe83a@posting.google.com>

I have some text which I want to scan through and find particular
words.

The problem I am having is that if I am looking for two words that are
follwed by <NN> and are next to each other, it finds the first two.

The code below is where I need to make the changes.
-----------------------------------------------------
$look = ('<NN>');

foreach (@sentence)
{
   while (/(\w+)\s($search)\s(\w+)\s($search)/g)
   {
     print "$1 $3\n";
   }
}
------------------------------------------------------
The string is:-

hello <NN> all <AD> able <NN> and <NN> happy <NN> people <DT>.

------------------------------------------------------
The program would find "able and".

How can I best change this so that print "$1 $3\n"; would show 

able and
and happy


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

Date: Sun, 09 Sep 2001 19:34:30 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Pattern Matching
Message-Id: <3B9BC4BE.7DAE4156@acm.org>

shaz wrote:
> 
> I have some text which I want to scan through and find particular
> words.
> 
> The problem I am having is that if I am looking for two words that are
> follwed by <NN> and are next to each other, it finds the first two.
> 
> The code below is where I need to make the changes.
> -----------------------------------------------------
> $look = ('<NN>');
> 
> foreach (@sentence)
> {
>    while (/(\w+)\s($search)\s(\w+)\s($search)/g)
>    {
>      print "$1 $3\n";
>    }
> }
> ------------------------------------------------------
> The string is:-
> 
> hello <NN> all <AD> able <NN> and <NN> happy <NN> people <DT>.
> 
> ------------------------------------------------------
> The program would find "able and".
> 
> How can I best change this so that print "$1 $3\n"; would show
> 
> able and
> and happy

$ perl -e'$search = q(<NN>); $_ = "hello <NN> all <AD> able <NN> and
<NN> happy <NN> people <DT>."; print "$1 $2\n" while
/(\w+)\s$search\s(?=(\w+)\s$search)/g;'
able and
and happy



John
-- 
use Perl;
program
fulfillment


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

Date: Sun, 09 Sep 2001 23:27:35 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: Perl objects problems
Message-Id: <3B9BDEC7.2050609@post.rwth-aachen.de>

mirvine555 wrote:

>>Thus you can build a whole class-hierarchy with only one constructor.
>>An
>>easy rule: One constructor for all and each sub-class has its own
>>init-method whereas the base-class does not need one since it (often)
>>is
>>abstract and hence should not be instantiated.
>>
>>
> 
> It's all making a little more sense now, and it sounds good, but what
> about the 'empty subclass' test. Shouldn't I be able to do:
> 
> (Full Insect.pm module shown)
> package Insect;
> 
> use strict;
> use vars qw(@ISA);
> use lib qw(./);
> use Critter;
> @ISA=('Critter');
> 
> 1;
> 
> 
> And create Insects with:
> my $insect=Insect->new;

Well, what happens if you try it? I don't see any reason why it should 
not work. You should be able to create a few hundred consecutive 
subclasses without any problems. If not, check your design again. ;-)

Tassilo

-- 
$a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->
[1]+1,$b->[1],"her")];for(@{[$a,$b,$c,$d]}){for(@{$_}){$_=~/\d+/?print
(chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108
),(0x20,0x68,0x61,)]};print(map{chr($_)}@{($c->(1))});$h={a=>33*3,b=>
10**2+7,c=>"1"."0"."1",d=>0162};@h=sort(keys(%$h));for(@h){print(chr(
ord(chr($h->{$_}))))};



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

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


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