[22028] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4250 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Dec 11 18:06:15 2002

Date: Wed, 11 Dec 2002 15:05:14 -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           Wed, 11 Dec 2002     Volume: 10 Number: 4250

Today's topics:
        "Ask Kosh" in perl? (MF Folz-Donahue)
    Re: "Ask Kosh" in perl? <het@despam.autobahn.mb.ca>
    Re: "Ask Kosh" in perl? (Tad McClellan)
    Re: @INC error in in unix <penny1482@attbi.com>
    Re: A formating problem (Jan Fure)
        Apology (Rob Richardson)
        ARG! CPAN Help <chuck.carson@syrrx.com>
    Re: ARG! CPAN Help <tony_curtis32@yahoo.com>
        Downloading images from web pages using perl. (Kawaii)
    Re: HELP.... problem splitting fields (Jay Tilton)
    Re: hidden eval variables (Malcolm Dew-Jones)
    Re: How do I find the first array element for which a c <bobx@linuxmail.org>
    Re: How do I find the first array element for which a c <uri@stemsystems.com>
        How to get GIF pixel information? (David Kurtz)
        Is this portable and safe? <sunil_franklin@hotmail.com>
    Re: Is this portable and safe? (Walter Roberson)
        multiline regex matching <zahm@uiuc.edu>
    Re: multiline regex matching (Tad McClellan)
    Re: multiline regex matching <eric.ehlers@btopenworld.com.spamoff>
    Re: open2 program dies <garry@ifr.zvolve.net>
    Re: Output Lines of 70 Characters <wsegrave@mindspring.com>
    Re: Output Lines of 70 Characters (Tad McClellan)
    Re: Re FAQ: How can I capture STDERR from an external c (Peter J. Acklam)
    Re: reg exp problem (Tad McClellan)
    Re: reg exp problem (jaya prakash)
        Regex match on string...? <bob@bobber.com>
    Re: Regex match on string...? <perl-dvd@ldschat.com>
    Re: Return a range of strings <usenet@dwall.fastmail.fm>
    Re: Return a range of strings (Tad McClellan)
    Re: Return a range of strings (Jay Tilton)
        Simplify split and s/// statement <stremitz@consultant.com>
    Re: Simplify split and s/// statement <usenet@tinita.de>
        what perl calls is the challenge <os7man@attbi.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 11 Dec 2002 11:30:51 -0800
From: mfolz@brandeis.edu (MF Folz-Donahue)
Subject: "Ask Kosh" in perl?
Message-Id: <8286b0ec.0212111130.3d94f0ca@posting.google.com>

Years ago there used to be a website that featured a program called
"ask Kosh." I seem to recall that it was written in perl. I can't seem
to find it now: www.vorlons.org apparently is using a version of that
script or something similar (every time you load /, it displays a
different koshism) but there's no info on that site about where to get
the script. There are a couple of sites using a javascript version of
"Ask Kosh" (including the website "Kosh speaks") which allows the use
of .wav files of actual koshisms. I'm not interested in that--I just
want to insert text.

Is the ask kosh program still floating around? If not, can anyone
suggest some programs I could look at that randomly insert text into a
page (from a list of possible strings, naturally). I could then modify
that to insert the words of Kosh (I'm just starting with perl
programming, so I like to see how other people have done things). I'm
also wondering if there's anywhere on the web where I could find a
complete (& accurate) list of Koshisms.

Any input is appreciated.

MF Folz-Donahue


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

Date: Wed, 11 Dec 2002 20:03:02 GMT
From: "H. E. Taylor" <het@despam.autobahn.mb.ca>
Subject: Re: "Ask Kosh" in perl?
Message-Id: <3DF7B4AC.4507@despam.autobahn.mb.ca>

In article <8286b0ec.0212111130.3d94f0ca@posting.google.com>,
<mfolz@brandeis.edu> MF Folz-Donahue wrote:
> 
> Years ago there used to be a website that featured a program called
> "ask Kosh." I seem to recall that it was written in perl. I can't seem
> to find it now: www.vorlons.org apparently is using a version of that
> script or something similar (every time you load /, it displays a
> different koshism) but there's no info on that site about where to get
> the script. There are a couple of sites using a javascript version of
> "Ask Kosh" (including the website "Kosh speaks") which allows the use
> of .wav files of actual koshisms. I'm not interested in that--I just
> want to insert text.
> 
> Is the ask kosh program still floating around? If not, can anyone
> suggest some programs I could look at that randomly insert text into a
> page (from a list of possible strings, naturally). I could then modify
> that to insert the words of Kosh (I'm just starting with perl
> programming, so I like to see how other people have done things). I'm
> also wondering if there's anywhere on the web where I could find a
> complete (& accurate) list of Koshisms.
> 
> Any input is appreciated.
> 
	Here is some 'any' input.			;-))>

	It sounds like someone used/modified (fortune) cookie.
	Your best bet for Kosh quotes is likely:
	http://www.cs.tut.fi/~albert/Quotes/B5-quotes.html
	although completeness may be questionable.

<have fun>
-het

	

--
"The avalanche has already begun,  
and it is too late for the pebbles to vote." -Kosh

Energy Alternatives: http://www.autobahn.mb.ca/~het/energy.html
H.E. Taylor  http://www.autobahn.mb.ca/~het/


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

Date: Wed, 11 Dec 2002 16:14:33 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: "Ask Kosh" in perl?
Message-Id: <slrnavfe69.2do.tadmc@magna.augustmail.com>

MF Folz-Donahue <mfolz@brandeis.edu> wrote:

> can anyone
> suggest some programs I could look at that randomly insert text into a
                                             ^^^^^^   ^^^^^^
> page (from a list of possible strings, naturally).


The Perl FAQ is your friend.


   perldoc -q random

      "How do I select a random element from an array?"

      "How do I select a random line from a file?"


   perldoc -q insert

      "How do I change one line in a file/delete a line in a
       file/insert a line in the middle of a file/append to the
       beginning of a file?"


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


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

Date: Wed, 11 Dec 2002 22:45:50 GMT
From: "Dick Penny" <penny1482@attbi.com>
Subject: Re: @INC error in in unix
Message-Id: <yePJ9.325416$WL3.105526@rwcrnsc54>


"Abernathey Family" <family2@aracnet.com> wrote in message
news:3DF69F63.8165D24F@aracnet.com...
> Brian McCauley wrote:
> >
> > "Sunil" <sunil_franklin@hotmail.com> writes:
> >
> > > (@INC contains:
> > >  'some directory I don't even have'
> > >  .....
> > >   'some other directory I don't even have'  .
> > > ) at myprg.pl line 53.
> > >
> > >
> > > The default perl in my path is of an older version and I was running
my
> > > program by using
> > >         /full/path/to/561/perl/bin/perl myprg.pl  -Idir
> > > /full/path/to/561/perl/lib/5.6.1
> >
> > You have made two careless mistakes in reading the perlrun manpage.
> --snip--
> Christmas is coming and Santa is going to put you on the naughty list if
> you don't learn to leave your vitrol out of your "help".

Aw come on, Brian didn't use much "vitrol" here, twas just a gentle nudge.
Try some of Perlie Gurlie's stuff if you want to see vitrol.
Dick Penny




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

Date: 11 Dec 2002 13:44:02 -0800
From: jan_may2002_fure@attbi.com (Jan Fure)
Subject: Re: A formating problem
Message-Id: <e47a84bf.0212111344.22513acb@posting.google.com>

tadmc@augustmail.com (Tad McClellan) wrote in message 
> 
> Yes it does. What makes you think it doesn't?
The boxplot reoutine using @points as input failed!
> 
> Did you print out the structure to see what was built?
I tried, but I only got hexadesimal numbers which I guess reprecent
array references. i didn't know how to use Data::Dumper until I saw
your code.
> 
> Did you miss autovivification creating another level of
> array for you in the push() statement?
Yes I missed it.

I realize after looking at my own message and Tad's reply that it
looks like I am critisizing Jeff or Jeff's code. That is not my
intention, and Jeff or anybody else I might have upset have my
sincerest appology. I am allways thankful when somebody spends effort
to help me or explain something to me.

> 
> 
> > The @points array needs to be an array of
> > arrays, where the first element (the keys) is an array, and the second
> > element is an array of arrays, with one element per key, and each
> > element is an array containing the data points for the corresponding
> > key.
> 
> 
> That describes the structure that Jeff's code builds...
> 

I think I caused a misunderstanding, because the way I described the
input data was not specific enough in the sense that the input is not
typed such that it can be copied and incerted into perl code. I saw
the Dumper output, and it is different from the Dumper output I get.
But it is not clear to me how you realize the

  while (<DATA>) { 

instruction step. Is DATA a filehandle?

In my specific code, the data being processed has a tab as delimiter,
and is allready in array form, and I changed 'split' to 'split /\t/',
but still could not get the code to work.

In the code included below, the sample data is specified exactly like
the real data my code has to process, and the code using hash to store
the data returns many 'undef' values. My perl is 'activestate'.

I have a solution to my specific problem, the reason for this post
(other than appologizing)is that I want to lern to do the data
processing the perl way. Objectively speaking, my script is very much
like a basic program using perl.

#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;

my @data1=(
"A1\t0.1233",
"A1\t1.234",
"A1\t0.34",
"A1\t3",
"C3\t1.4321",
"A5\t1.24555",
"A5\t23",
"A5\t2",
"A5\t5"
);
#I am looking for a way to change the data above into the format:
my @data1_out = (
         ["A1", "A5", "C3"],
         [ [0.1233, 0.34, 1.234, 3], [1.24555, 2, 5, 23], [1.4321]]
      	  );

# Algorithm 1, using hashes

# step 1 -- read the file into a hash of array-references:
  my (%data, @points);

  while (<@data1>) {
    my ($field, $val) = split /\t/;
    push @{ $data{$field} }, $val;
  }

  # step 2 -- convert hash of array-references
  # into array of array-references

  @points = (
    [ keys %data ],
    [ values %data ],
  );

# End Algorithm 1

# Algorithm 2, using a somewhat cludgy loop

my @data2 = sort @data1;
(my $Key, my $Discard) = split /\t/, $data2[0];
my @Keys;
$Keys[0]=$Key;
my $NewKey;
my $InstanceData;
my $n4=0;
my $data3;
my @AccumulatedData;
my @FinalData;
foreach $data3 (@data2){
	($NewKey, $InstanceData) = split /\t/, $data3;
	if($NewKey ne $Key){
		push @FinalData, [ @AccumulatedData ];
		print "Key = $Key NewKey = $NewKey \n";
		$n4++;
		$Keys[$n4]=$NewKey;
		@AccumulatedData=();
	}
	$Key=$NewKey;
	push @AccumulatedData, $InstanceData;
}
push @FinalData, [ @AccumulatedData ];
my @points_loop=(
[@Keys],
[@FinalData]
);

use Data::Dumper;
print "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
print "Using Hash\n";
print Dumper(\@points), "\n";
print "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
print "Using Loop\n";
print Dumper(\@points_loop), "\n";
print "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
print "Using Original Set\n";
print Dumper(\@data1_out), "\n";
print "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";


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

Date: 11 Dec 2002 13:54:21 -0800
From: therobs@n2net.net (Rob Richardson)
Subject: Apology
Message-Id: <f79bc007.0212111354.78cfc7bf@posting.google.com>

tadmc@augustmail.com (Tad McClellan) wrote in message news:<slrnavd8dv.49c.tadmc@magna.augustmail.com>...
> Rob Richardson <therobs@n2net.net> wrote:
> > 
> > No thanks to Tad.  
> 

Tad, please accept my apology for this thoughtless and offensive
comment.  Thank you for your assistance.  I will keep this
embarassment in mind as I write future posts.

Rob


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

Date: Wed, 11 Dec 2002 11:43:00 -0800
From: Chucky <chuck.carson@syrrx.com>
Subject: ARG! CPAN Help
Message-Id: <3DF79544.4060606@syrrx.com>


I have a newly installed Solaris 9 box, and am trying to use CPAN  to 
isntall various modules. However, I have gcc-3.2 installed, and all the 
CPAN modules are looking for cc. I tried hacking some makefiles to use 
gcc isntead, but more errors resulted.

Anyone have any ideas?

Thx,
CC



-----------== Posted via Newsfeed.Com - Uncensored Usenet News ==----------
   http://www.newsfeed.com       The #1 Newsgroup Service in the World!
-----= Over 100,000 Newsgroups - Unlimited Fast Downloads - 19 Servers =-----


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

Date: Wed, 11 Dec 2002 13:48:41 -0600
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: ARG! CPAN Help
Message-Id: <87adjc8hgm.fsf@limey.hpcc.uh.edu>

>> On Wed, 11 Dec 2002 11:43:00 -0800,
>> Chucky <chuck.carson@syrrx.com> said:

> I have a newly installed Solaris 9 box, and am trying to
> use CPAN to isntall various modules. However, I have
> gcc-3.2 installed, and all the CPAN modules are looking
> for cc. I tried hacking some makefiles to use gcc
> isntead, but more errors resulted.

You should probably get and build your own up-to-date
perl.  Perl propagates its compiler settings through to
module builds (for hopefully obvious reasons).  You can
then build your own 5.8 release with gcc throughout.

Also see

    http://www.science.uva.nl/pub/solaris/solaris2.html#q3.75

hth
t


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

Date: 11 Dec 2002 14:40:46 -0800
From: kawaii@networkduels.com (Kawaii)
Subject: Downloading images from web pages using perl.
Message-Id: <186949a0.0212111440.4df7ed8a@posting.google.com>

Hello everyone.
I am trying to get or request Images from web pages and often I find
the program
putting html source code into a .jpg or .gif file. (with the name of
the image)

I have tried,

use LWP::Simple;
$image = get ("ftp://images.cosplay.com/data/566/1dsc02111.jpg");
open (FILEHANDLE, ">image.jpg");
binmode FILEHANDLE; ## With or without this, does nothing to help.
print FILEHANDLE $image;
close (FILEHANDLE);

(this is on a unix machine, solaris)


I've tried the mirror option within lwp, which returns a 0 byte file.
I've tried the Request option, which is basicly another get done by
another module.
If you simply paste the URL listed above, You get the image all by
itself.
(The image is an example, but not a bad image just the same.)

Can anyone, in a few lines of perl code, get the above image to
actually download and save into the specified file. Alot of the images
I am trying to aqcuire are in php or ez board's, but again, I simply
need to insert the above url into a browser and voila. Just the raw
image.

Any help would be great.
(Please do not suggest wget)


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

Date: Wed, 11 Dec 2002 22:35:02 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: HELP.... problem splitting fields
Message-Id: <3df7b9cb.87994944@news.erols.com>

Garry Williams <garry@ifr.zvolve.net> wrote:

: On Tue, 10 Dec 2002 22:50:17 GMT, Jay Tilton <tiltonj@erols.com> wrote:
: >     $phone = ~ s/^(.{1,10})/$1,/;
:               ^
:               ^
: The space is not allowed!

Sure it is.  It changes the binding operator into an assignment, but
it's legal.

You caught me, brother.  Not just that, but "use warnings;" wouldn't
have helped, since $_ was indeed given a value in the original code.

Wouldn't it be fun to have 429-496-7294 as your telephone number, just
to tell whoever calls that their programmer has made that mistake.  :)



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

Date: 11 Dec 2002 12:23:44 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: hidden eval variables
Message-Id: <3df79ed0@news.victoria.tc.ca>

Anno Siegel (anno4000@lublin.zrz.tu-berlin.de) wrote:
: According to Tassilo v. Parseval <tassilo.parseval@post.rwth-aachen.de>:
: > Also sprach Anno Siegel:
: > 
: > > According to Tassilo v. Parseval <tassilo.parseval@post.rwth-aachen.de>:
: > 
: > >>     use strict;
: > >>     {
: > >>         # ordinary script
: > >>         ...
: > >>         call_eval();
: > >>     }
: > >>     sub call_eval { 
: > >>         eval <STDIN>;
: > >>     }
: > >> 
: > >> Thus you can protect all lexical variables from the upper block. They
: > >> will be invisible within call_eval() as long as they are declared with
: > >> my().
: > > 
: > > ...except for possible file-global lexicals that happen to be declared
: > > before the "sub call_eval ..." statement, so this sub should be one of
: > > the first things in the file.  The peculiar placement deserves a comment.
: > 
: > Good point. I was aware of the problem with declared globals but had no
: > real solution for that so I left that off (hoping that 'use vars' and
: > possibly our() wouldn't be that common anyway). The re-placement of the
: > subroutine is an obvious solution that escaped me.

: Ah, but this isn't about "use vars" and "our()".  Package variables
: will always be accessible from anywhere, only lexicals can be protected.

If you know what package variables you are using then do a `local varname'
for each one before the eval.  That way the package variable will still
be protected. 


	use vars qw( $my_package_var );

	sub my_eval 
	{ my $your_code = shift;

	  local $my_package_var = $my_package_var; # protect my version

	  eval $your_code ;
	  
	... etc ...


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

Date: Wed, 11 Dec 2002 20:46:15 GMT
From: "Bob X" <bobx@linuxmail.org>
Subject: Re: How do I find the first array element for which a condition is true?
Message-Id: <ruNJ9.1498$uV4.1114731@news2.news.adelphia.net>

Question:  How often are the FAQ's checked for accuracy and/or updated?

Bob




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

Date: Wed, 11 Dec 2002 21:06:16 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: How do I find the first array element for which a condition is true?
Message-Id: <x7smx4gta0.fsf@mail.sysarch.com>

>>>>> "BX" == Bob X <bobx@linuxmail.org> writes:

  BX> Question:  How often are the FAQ's checked for accuracy and/or updated?

as they get posted by the faqbot, people who read them may post comments
and such. the faq maintainer (brian d foy) is actively following those
and edits as he sees fit.

and you should ignore any comments by the resident troll. between never
following any faq advice and babbling some entries she has no useful
remarks.

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


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

Date: 11 Dec 2002 11:21:07 -0800
From: d0@earthlink.net (David Kurtz)
Subject: How to get GIF pixel information?
Message-Id: <f39ae2ff.0212111121.2a9f3c31@posting.google.com>

I'd like to find the most simple way to pack the colors of an image
into an array or variable, for use elsewhere. I don't need to display
the image, but I need to get the color values for each individual
pixel as it might be displayed.

I'm looking over Image::Magick right now, but I haven't yet 1)
determined whether it will do what I need, and  2) decided whether I
want to install a completely separate program (other than a Perl
module) to do this.

Any ideas?


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

Date: Thu, 12 Dec 2002 00:51:30 +0530
From: "Sunil" <sunil_franklin@hotmail.com>
Subject: Is this portable and safe?
Message-Id: <PhMJ9.6$mk.167@news.oracle.com>

system << "EOF" ;
    sqlplus  scott/tiger\@iasdb.local  \@test.sql 1>test.log
EOF


Thanks,
Sunil.





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

Date: 11 Dec 2002 20:38:10 GMT
From: roberson@ibd.nrc.ca (Walter Roberson)
Subject: Re: Is this portable and safe?
Message-Id: <at87ni$1s6$1@canopus.cc.umanitoba.ca>

In article <PhMJ9.6$mk.167@news.oracle.com>,
Sunil <sunil_franklin@hotmail.com> wrote:
:system << "EOF" ;
:    sqlplus  scott/tiger\@iasdb.local  \@test.sql 1>test.log
:EOF

Safe? What if the user has an 'sqlplus' in their path earlier than
the 'sqlplus' that you were expecting? What if the user isn't
in the directory you are expecting? What if the user has set the
IFS shell variable to deliberately cause the line to be mis-parsed?

perldoc -f system

   If there is only one scalar argument, the
   argument is checked for shell metacharacters, and if
   there are any, the entire argument is passed to the
   system's command shell for parsing (this is "/bin/sh
   -c" on Unix platforms, but varies on other
   platforms).  If there are no shell metacharacters in
   the argument, it is split into words and passed
   directly to "execvp", which is more efficient.

'>' is a shell metacharacter so you are exposed to all the security
risks involved in running a shell script.
--
Can a statement be self-referential without knowing it?


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

Date: Wed, 11 Dec 2002 15:30:21 -0600
From: "Robert Zahm" <zahm@uiuc.edu>
Subject: multiline regex matching
Message-Id: <b5OJ9.5375$Vf3.55469@vixen.cso.uiuc.edu>

I am trying to match patterns that may or may not have embedded newlines in
them, and I am still unsure how to do this after looking through a couple of
sources (including perlfaq6).  Basically, I am trying to implement this
line:
s/A{3}/match/g
I want this to match a couple of different things, including:
AAA
BBB

BAA
ACC

BBA
AAC

A
A
A

So there may or may not be an embedded newline anywhere in the sequence.
I've looked at the /m and /s modifiers, but unless I am missing something, I
don't see how they can help, since I'm not particularly looking to match at
the beginning or end of a line.  I know that I can parse through the
sequence and just substitute the embedded newlines with "", but I would like
to avoid this if possible.  Can somebody please point me in the right
direction?  Thanks.

Rob




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

Date: Wed, 11 Dec 2002 16:09:42 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: multiline regex matching
Message-Id: <slrnavfdt6.2do.tadmc@magna.augustmail.com>

Robert Zahm <zahm@uiuc.edu> wrote:

> I am trying to match patterns that may or may not have embedded newlines in
> them, 

> I want this to match a couple of different things, including:
> AAA
> BBB
> 
> BAA
> ACC
> 
> BBA
> AAC
> 
> A
> A
> A
> 
> So there may or may not be an embedded newline anywhere in the sequence.


   s/(A\s*?){3}/match/g;


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


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

Date: Wed, 11 Dec 2002 22:41:37 +0000 (UTC)
From: "eric" <eric.ehlers@btopenworld.com.spamoff>
Subject: Re: multiline regex matching
Message-Id: <at8ev1$rsl$1@knossos.btinternet.com>

> I've looked at the /m and /s modifiers, but unless I am missing something,
I
> don't see how they can help, since I'm not particularly looking to match
at
> the beginning or end of a line.  I know that I can parse through the

the /s modifier tells . to match the newline character just like any other
character - that's exactly what you need here.  the code below should send
you in the right direction.  you'd need to replace the  .*s with something
more restrictive if you wanted, say, to prevent matches against strings
containing more than three As.

eric

===========================================

use strict;
use warnings;

my @matches=("AAA\nBBB","BAA\nACC","BBA\nAAC","A\nA\nA");
my @nomatches=("ABC","AA\nBBB");

for (@matches,@nomatches) {
 print "testing string:\n|$_|\n";
 if (/.*A.*A.*A.*/s) {
  print "matched!\n\n"
 } else {
  print "didn't match!\n\n"
 }
}




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

Date: Wed, 11 Dec 2002 19:58:54 -0000
From: Garry Williams <garry@ifr.zvolve.net>
Subject: Re: open2 program dies
Message-Id: <slrnavf67u.3c7.garry@zfw.zvolve.net>

On 11 Dec 2002 05:51:43 -0800, Mike Wilson <mike_wilson@m-petfilm.com> wrote:
> hi,
> i am using open2 to read and write to another process. Everything
> works fine, except if the process dies or something. If i write to the
> write handle after that, my program dies. Is there some way for me to
> check, before i write. I would rather not run some system command such
> as ps every time i write. I have tried IO::Select with has_exception
> or writeable, but without success.

You probably want to catch SIGPIPE.  See perlcar and look at the %SIG
entry.  

For example: 

  $SIG{PIPE} = sub {
      warn "child seems to have exited...";
      $child_exited = 1;
  };

Or maybe you will read the child's stdout and get end of file
eventually.  In that case, you may want to ignore SIGPIPE and rely on
EOF: 

  $SIG{PIPE} = 'IGNORE';

-- 
Garry Williams


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

Date: Wed, 11 Dec 2002 13:15:50 -0600
From: "William Alexander Segraves" <wsegrave@mindspring.com>
Subject: Re: Output Lines of 70 Characters
Message-Id: <at83v6$69m$1@slb4.atl.mindspring.net>

"David Tian" <yuanxi80@hotmail.com> wrote in message
news:da930649.0212082227.6061d88d@posting.google.com...
> I am writing a Perl program. Given an input of some lines of text as a
> string with no newline chars, where each line contains some
> combination of:
>  alphabetic symbols, either upper case or lower case
>  punctuation symbols: '.' ',' ';' ':' '!' '?'
>  spaces
>
> The program should output lines of 70 characters on standard output,
> so that:
> each line should start with the beginning of a word (no word splits
> across lines);
> Each line contain as many words as possible within limits.
> The lines are left aligned.

You should be able to do this with built-in formatting ( format)
capabilities of Perl
(See Chapter 11, pp. 116-128 of _Learning perl, 2nd Ed.). See esp. p.123,
about suppression indicator, which should give you a hint about how to
generate multiple continuation lines automatically.

Hint: Write to a temp file, then print that to STDOUT.

Cheers.

Bill Segraves

P.S. Also, see perlform manpage.










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

Date: Wed, 11 Dec 2002 16:25:44 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Output Lines of 70 Characters
Message-Id: <slrnavfer8.2do.tadmc@magna.augustmail.com>

William Alexander Segraves <wsegrave@mindspring.com> wrote:

> You should be able to do this with built-in formatting ( format)
> capabilities of Perl

> Hint: Write to a temp file, then print that to STDOUT.


What is the hint supposed to help with?

Is there a problem with using

   write;
or
   write STDOUT;

??


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


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

Date: 11 Dec 2002 20:38:51 +0100
From: pjacklam@online.no (Peter J. Acklam)
Subject: Re: Re FAQ: How can I capture STDERR from an external command?
Message-Id: <bs3s73ck.fsf@online.no>

Benjamin Goldberg <goldbb2@earthlink.net> wrote:

> Peter J. Acklam wrote:
> > 
> > Benjamin Goldberg <goldbb2@earthlink.net> wrote:
> [snip]
> > > In what way do FIFO files seem cleaner?
> > 
> > I was scared by the all the warnings in the docs for
> > Net::Open3.  There seems to be so much that can go wrong
> > (deadlocks etc.),
> 
> Except that those exact same deadlocks would still occur if you
> used fifos instead of pipes.

I will never be writing to stdin, only reading from stdout and
stderr, so I didn't think deadlocks would happen in that case,
when I used FIFOs, but I am rather new to IPC, so I might be
confused.

> > and I don't yet have that much experience with IPC, so I was
> > worried about screwing things up.  Separating stdout and
> > stderr is so easy in the shell, but seems to be so complicated
> > in Perl.
> 
> Sending stdout and stderr to two seperate files is quite easy,
> in both shell and perl.

Most things are easy when you know how to do them...  :-)

> But simultaneously processing both stdout and stderr can be
> quite complicated, in both shell and perl.
> 
> How would you do it in the shell, if you consider it to be so
> easy?

In the shell I would just do

   command 1> log.stdout 2> log.stderr

but doing the same in Perl requires a _lot_ more work, unless I am
mistaken.

> > I'll probably just redirect stdout and stderr to the same
> > place and avoid all the hassle.
> 
> If you don't explicitly need to deal them *seperately*, then
> joining stdout and stderr certainly simplifies things; After
> all, what could be easier than the following?
> 
>    open( my ($fh), "-|", "some program and args 2>&1" ) or die horribly;

True.  I would prefer to have them in separate files, but I doubt
it is worth the trouble.

Peter

-- 
#!/local/bin/perl5 -wp -*- mode: cperl; coding: iso-8859-1; -*-
# matlab comment stripper (strips comments from Matlab m-files)
s/^((?:(?:[])}\w.]'+|[^'%])+|'[^'\n]*(?:''[^'\n]*)*')*).*/$1/x;


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

Date: Wed, 11 Dec 2002 13:26:13 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: reg exp problem
Message-Id: <slrnavf4al.260.tadmc@magna.augustmail.com>

jaya prakash <prakashrj@hotmail.com> wrote:
>> 
>> 
>> Use this in your loop instead:
>> 
>>     pos($sequence) = pos($sequence) - 1;
> 
> That should help me get what I expected.


But only for the particular datum that you've shown.

Wouldn't you expect:

abcabcabcabcabcabcabcabc
bcbcbcbcbcbcbcbc

with: my $sequence = "xyzabcabcabcabcabcabcabcabcbcbcbcbcbcbcbcxyz";

??

The code modification above won't get you that...


>> But I'm pretty sure that that will prove unsatisfactory as well...


Which is what I had in mind when I said that.


> Thanks again for helping me out.


You're welcome, but your problem is not yet "solved".   :-)


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


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

Date: 11 Dec 2002 14:26:19 -0800
From: prakashrj@hotmail.com (jaya prakash)
Subject: Re: reg exp problem
Message-Id: <ee5d9.0212111426.373c0810@posting.google.com>

> But only for the particular datum that you've shown.
> 
> Wouldn't you expect:
> 
> abcabcabcabcabcabcabcabc
> bcbcbcbcbcbcbcbc
> 
> with: my $sequence = "xyzabcabcabcabcabcabcabcabcbcbcbcbcbcbcbcxyz";
> 
> ??
> 
> The code modification above won't get you that...

Do you see nay problems with the following modification. 

pos($sequence) = pos($sequence) - 3;

If there is any other elegant please let me know. Thanks again.
> 
> 
> >> But I'm pretty sure that that will prove unsatisfactory as well...
> 
> 
> Which is what I had in mind when I said that.
> 
> 
> > Thanks again for helping me out.
> 
> 
> You're welcome, but your problem is not yet "solved".   :-)


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

Date: Wed, 11 Dec 2002 20:38:12 GMT
From: Bob <bob@bobber.com>
Subject: Regex match on string...?
Message-Id: <3DF7A234.1060801@bobber.com>

Hi,

I have a string that is structured like this:
<a href=$somelink>Jobid is 834342888</a><br>

There may be a series of these, i.e.:
<a href=$somelink>Jobid is 834342888</a><br><a href=$somelink>Jobid is 
665234534</a><br><a href=$somelink>Jobid is 123433355</a>

I would like to yank out the digits (jobids) and store them in an array. 
  How can I get one, if there is only one, two if there are two, etc, 
etc, and store them in an array in the order they are found?

So my array for the first example would be:
("834342888")

and the second would be
("834342888", "665234534", "123433355")

Thanks!
B



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

Date: Wed, 11 Dec 2002 13:56:38 -0700
From: "David" <perl-dvd@ldschat.com>
Subject: Re: Regex match on string...?
Message-Id: <TxNJ9.7948$K5.5234@fe01>

"Bob" <bob@bobber.com> wrote in message
news:3DF7A234.1060801@bobber.com...
> Hi,
>
> I have a string that is structured like this:
> <a href=$somelink>Jobid is 834342888</a><br>
>
> There may be a series of these, i.e.:
> <a href=$somelink>Jobid is 834342888</a><br><a href=$somelink>Jobid is
> 665234534</a><br><a href=$somelink>Jobid is 123433355</a>
>
> I would like to yank out the digits (jobids) and store them in an
array.
>   How can I get one, if there is only one, two if there are two, etc,
> etc, and store them in an array in the order they are found?
>
> So my array for the first example would be:
> ("834342888")
>
> and the second would be
> ("834342888", "665234534", "123433355")
>
> Thanks!
> B

my $string = qq^
<a href=$somelink>Jobid is 834342888</a><br>
<a href=$somelink>Jobid is 665234534</a><br>
<a href=$somelink>Jobid is 123433355</a>
^;
my @ids = $string =~ /Jobid is (\d+)/g;

Works with or without line breaks in the $string var

Regards,
David





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

Date: Wed, 11 Dec 2002 19:08:51 -0000
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Re: Return a range of strings
Message-Id: <Xns92E18FEA68EDBdkwwashere@216.168.3.30>

jim ryan <ryan@jimryan.com> wrote on 11 Dec 2002:

> I want to parse the output from a command and find a particular
> string, "foo".  When this string is found I want to return it as
> well as x number of strings above it, and y number of strings
> below it.  I was thinking I could use the grep function, but it
> only returns the string found, or the number of times it occurs.
> 
> So if the output from the command is...
> 
> this is
> the output
> from 
> the command
> I sent
> to the 
> command interperter
> 
> ...and I search for "I sent" and I want to return 1 line below and
> 3 lines above I should get...
> 
> 
> the output
> from 
> the command
> I sent
> to the 
> 
> Also, I might want to return something 3 lines above, and not
> return the string found at all.
> 
> What is one way I could attack this?

If the output is short, you could just throw memory at the problem: 
slurp all the lines into an array, then loop over the array.

<code>

use strict;
use warnings;

my $before = 3;
my $after  = 1;

my @lines = `command`;

for (my $i = 0; $i < @lines; $i++ ) {
    if ( $lines[$i] =~ /I sent/ ) {
        print @lines[($i-$before) .. ($i+$after)];
        last;
    }
}

</code>

-- 
David K. Wall - usenet@dwall.fastmail.fm
"Oook."


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

Date: Wed, 11 Dec 2002 13:14:52 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Return a range of strings
Message-Id: <slrnavf3lc.22n.tadmc@magna.augustmail.com>

jim ryan <ryan@jimryan.com> wrote:

> ...and I search for "I sent" and I want to return 1 line below and 3
> lines above


----------------------------------
#!/usr/bin/perl
use strict;
use warnings;

my @buffer;   # a queue data structure

while ( <DATA> ) {
   if ( /I sent/ ) {
      print @buffer;          # 3 lines before
      print;                  # the matching line
      print scalar(<DATA>);   # 1 line following
      last;                   # all done
   }
   push @buffer, $_;
   shift @buffer if @buffer > 3;
}


__DATA__
this is
the output
from
the command
I sent
to the
command interperter
----------------------------------


Or, if you have access to GNU grep(1):

   grep -B3 -A1 'I sent' files...


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


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

Date: Wed, 11 Dec 2002 22:51:05 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Return a range of strings
Message-Id: <3df7bd9c.88971936@news.erols.com>

ryan@jimryan.com (jim ryan) wrote:

: I want to parse the output from a command and find a particular
: string, "foo".  When this string is found I want to return it as well
: as x number of strings above it, and y number of strings below it.

Some time ago, Randal Schwartz shared code to do something very
similar.  It should be transparent enough and flexible enough to be
made to fit your current task, and many others in future.

Message-ID: <m11yovzo4u.fsf@halfdome.holdit.com>

Which brings to mind the value of a good subject line.

I remember being impressed by the code.  I also remember silently
cursing the abysmally generic subject chosen by the OP.  Somebody
unaware of the thread's details has little hope of finding the gem
now.



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

Date: Wed, 11 Dec 2002 17:33:04 -0500
From: Alexander Stremitzer <stremitz@consultant.com>
Subject: Simplify split and s/// statement
Message-Id: <3DF7BD20.8050406@consultant.com>

I am using the following code segment in my program. The code does what 
it is supposed to do. However, it looks somewhat cludgy.
Is there a way to simplify the statement below ? The goal is to remove 
the trailing white space from all fields.

my ($pat_name,$pat_id,$birth_date,$accnbr,$study_date) = split (/\|/, 
$PDS_LINE);
    $pat_name =~ s/\s*$//;        # remove trailing white space
    $pat_id =~ s/\s*$//;        # remove trailing white space
    $birth_date =~ s/\s*$//;    # remove trailing white space
    $accnbr =~ s/\s*$//;        # remove trailing white space
    $study_date =~ s/\s*$//;    # remove trailing white space

__DATA__
Patient name          |patient id       |1926.02.02|123456789     
 |2002.10.12

Thanks for helping me to improve my Perl code writing,
Alex

-- 
All man's miseries derive from not being able to sit quietly in a room alone. (Pascal)



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

Date: 11 Dec 2002 22:46:26 GMT
From: Tina Mueller <usenet@tinita.de>
Subject: Re: Simplify split and s/// statement
Message-Id: <at8f82$11fpqg$1@fu-berlin.de>

Alexander Stremitzer <stremitz@consultant.com> wrote:
> I am using the following code segment in my program. The code does what 
> it is supposed to do. However, it looks somewhat cludgy.
> Is there a way to simplify the statement below ? The goal is to remove 
> the trailing white space from all fields.

> my ($pat_name,$pat_id,$birth_date,$accnbr,$study_date) = split (/\|/, 
> $PDS_LINE);
>     $pat_name =~ s/\s*$//;        # remove trailing white space
>     $pat_id =~ s/\s*$//;        # remove trailing white space
>     $birth_date =~ s/\s*$//;    # remove trailing white space
>     $accnbr =~ s/\s*$//;        # remove trailing white space
>     $study_date =~ s/\s*$//;    # remove trailing white space

my ($pat_name,$pat_id,$birth_date,$accnbr,$study_date)
      = split /\s*(?:\||$)/, $PDS_LINE;

hth, tina
-- 
http://www.tinita.de/        \  enter__| |__the___ _ _ ___
http://Movies.tinita.de/      \     / _` / _ \/ _ \ '_(_-< of
http://PerlQuotes.tinita.de/   \    \ _,_\ __/\ __/_| /__/ perception


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

Date: Wed, 11 Dec 2002 22:16:41 GMT
From: Eric Osman <os7man@attbi.com>
Subject: what perl calls is the challenge
Message-Id: <3DF7B95E.D32CE1FC@attbi.com>


Hi,

My challenge seems to be with the things my perl
script is calling, rather than perl itself.

So, when you read this question and feel I need to
be asking "elsewhere" and you can suggest a useful
newsgroup, please let me know.

I'm having trouble getting the following perl (excerpt
only shown) to work :

	#!/usr/bin/perl
	%postInputs = readPostInput();
	$dateCommand = "date";
	$time = `$dateCommand`;
	open (MAIL, "|/usr/sbin/sendmail -t") || return 0;
	select (MAIL);
        . . .

This example is suggested in  "writing your first program"
in my perl book.  If you want to see the entire
program, it's on this web page :

      ftp://ftp.sybex.com/2200/Perllist1.pdf

My environment is windows 98 with indigoperl .

I'll present my MAIN challenge first, then a more
minor one.

The main one is with

	open (MAIL, "|/usr/sbin/sendmail -t")  . . .

From looking around in my indigoperl documentation
and folder, I don't think "sendmail" is included
anywhere.

I'm sure "sendmail" is standard on unix systems, but
should I be using something else in indigoperl on
windows 98 ?

Or am I supposed to be installing "sendmail" from
some independently different place ?  (what do you
suggest ?) .

(should I perhaps be attempting to interface my
indigoperl to cygwin ? or is this too much to hope
for ?)

The more minor challenge is with this morsel:

	$dateCommand = "date";
	$time = `$dateCommand`;


That was HANGING my script, because on windows 98,
the "date" command not only displays the date but asks
you to type in a new one !!!!

I'm trying to get around it with this:

	$dateCommand = "date < c:\\temp\\blank.txt";
	$time = `$dateCommand`;
       
where the contents of "blank.txt" is just an empty
line.

Is that hacky or what ?  What should I be using instead.

But, as I say, the "sendmail" issue is of more concern
to me.

Thanks for any ideas.

/Eric


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

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


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