[17520] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4940 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Nov 21 14:05:45 2000

Date: Tue, 21 Nov 2000 11:05:19 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <974833519-v9-i4940@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 21 Nov 2000     Volume: 9 Number: 4940

Today's topics:
        "Broken pipe" <hollosyt@msu.edu>
    Re: "Broken pipe" (Anno Siegel)
    Re: "Broken pipe" <hollosyt@msu.edu>
    Re: "Broken pipe" rereidy@my-deja.com
    Re: "Broken pipe" nobull@mail.com
        (newB): What would cause line 1 fail? <earlie@my-deja.com>
    Re: /s and $1 <bkennedy@hmsonline.com>
        A Small Problem Any Sugestions? <infro@yahoo.com>
    Re: A Small Problem Any Sugestions? nobull@mail.com
    Re: Addition vs. concatenation [was: Beginners Blues II <geoff-at-farmline-dot-com@127.0.0.1>
    Re: Addition vs. concatenation [was: Beginners Blues II (Anno Siegel)
    Re: Closing a window (Tad McClellan)
    Re: Concatenating files (Tom Christiansen)
    Re: copying / renaming associative arrays ---or somethi <bkennedy@hmsonline.com>
    Re: default perl to execute in current dir ? (Honza Pazdziora)
    Re: desperate pls help me! <no-mailr@blabla.org>
    Re: Enumerate Existing Modules ? (David K. Wall)
    Re: Enumerate Existing Modules ? <bart.lateur@skynet.be>
    Re: Enumerate Existing Modules ? (Randal L. Schwartz)
    Re: Enumerate Existing Modules ? (David K. Wall)
    Re: Enumerate Existing Modules ? <bart.lateur@skynet.be>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Tue, 21 Nov 2000 11:50:20 -0500
From: "tch" <hollosyt@msu.edu>
Subject: "Broken pipe"
Message-Id: <8ve8s3$311l$1@msunews.cl.msu.edu>

Getting this error when trying to run a script that just does some simple
opening and closing of files, I can't isolate the error though, and it's
making me angry. That string didnt turn up any hits in the perl
documentation search engine. So I'm at a loss. Does anyone know what it
means? And yes I am closing everytime i open.
--

/.tch




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

Date: 21 Nov 2000 17:18:34 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: "Broken pipe"
Message-Id: <8veapa$1rm$1@lublin.zrz.tu-berlin.de>

tch <hollosyt@msu.edu> wrote in comp.lang.perl.misc:
>Getting this error when trying to run a script that just does some simple
>opening and closing of files, I can't isolate the error though, and it's
>making me angry. That string didnt turn up any hits in the perl
>documentation search engine. So I'm at a loss. Does anyone know what it
>means? And yes I am closing everytime i open.

"Broken pipe" isn't a Perl message, it's a common unix message.  Its
appearance may mean that your script isn't interpreted by perl, but
(probably) some shell instead.  Look at the first line, it should
be something like

#!/usr/bin/perl -w

Anno


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

Date: Tue, 21 Nov 2000 12:51:57 -0500
From: "tch" <hollosyt@msu.edu>
Subject: Re: "Broken pipe"
Message-Id: <8vecfj$76k$1@msunews.cl.msu.edu>

Actually, it's both. I think it was happening when my perl script tried to
execute a shell command, but ran into some difficulties. Thanks.

/.tch

Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote in message
news:8veapa$1rm$1@lublin.zrz.tu-berlin.de...
> tch <hollosyt@msu.edu> wrote in comp.lang.perl.misc:
> >Getting this error when trying to run a script that just does some simple
> >opening and closing of files, I can't isolate the error though, and it's
> >making me angry. That string didnt turn up any hits in the perl
> >documentation search engine. So I'm at a loss. Does anyone know what it
> >means? And yes I am closing everytime i open.
>
> "Broken pipe" isn't a Perl message, it's a common unix message.  Its
> appearance may mean that your script isn't interpreted by perl, but
> (probably) some shell instead.  Look at the first line, it should
> be something like
>
> #!/usr/bin/perl -w
>
> Anno




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

Date: Tue, 21 Nov 2000 18:06:30 GMT
From: rereidy@my-deja.com
Subject: Re: "Broken pipe"
Message-Id: <8vedj0$sjn$1@nnrp1.deja.com>

This error is a UNIX error and is probaly coming from (but we can't be
sure since you posted no code) something like:

open(F, "gzip $file |") ...

At least, this is where I have seen the problem occur.

Ron Reidy
Oracle DBA

In article <8ve8s3$311l$1@msunews.cl.msu.edu>,
  "tch" <hollosyt@msu.edu> wrote:
> Getting this error when trying to run a script that just does some
simple
> opening and closing of files, I can't isolate the error though, and
it's
> making me angry. That string didnt turn up any hits in the perl
> documentation search engine. So I'm at a loss. Does anyone know what
it
> means? And yes I am closing everytime i open.
> --
>
> /.tch
>
>


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: 21 Nov 2000 18:47:35 +0000
From: nobull@mail.com
Subject: Re: "Broken pipe"
Message-Id: <u9em0588mw.fsf@wcl-l.bham.ac.uk>

"tch" <hollosyt@msu.edu> writes:

> Getting this error when trying to run a script that just does some simple
> opening and closing of files, I can't isolate the error though, and it's
> making me angry.

Switch it off with

$SIG{PIPE}='IGNORE';

> That string didnt turn up any hits in the perl
> documentation search engine.

It's not a Perl error.

> So I'm at a loss. Does anyone know what it
> means?

It means that a program that was started by the shell is terminating
on an untrapped SIGPIPE signal.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Tue, 21 Nov 2000 17:29:22 GMT
From: earlie <earlie@my-deja.com>
Subject: (newB): What would cause line 1 fail?
Message-Id: <8vebd8$qdc$1@nnrp1.deja.com>

I am running a file that says only:
#! usr/bin/perl -wcT

and I get the following:
The specified CGI application misbehaved by not returning a complete set
of HTTP headers. The headers it did return are:

Too late for "-T"

This is on winNT

Thanks amillion in advance

earl


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Tue, 21 Nov 2000 17:52:14 GMT
From: "Ben Kennedy" <bkennedy@hmsonline.com>
Subject: Re: /s and $1
Message-Id: <iDyS5.131631$td5.19639954@news1.rdc2.pa.home.com>


<randy.galbraith@pegs.com> wrote in message
news:1103_974743149@rgalbraith...
> Hello All,
>
> I'm having some trouble understanding how 'backreferences' work in
> regular expressions.  I'm trying to modify a script that comes with
> LXR (Linux Cross Referencer) to handle K&R style declarations.
> I've paired my problem code do to this snippet...

> print "BEFORE>>$contents<<\n";
> $count = $contents =~ s/\)((\s*[A-Za-z0-9,_
> \t\*\[\]\n]{2,};)*)(\s*)\{/
> "\)".&wash($1).&wash($2)."{"/goe;
> print "AFTER>>$contents<<\n";
> print "count = $count\n";

Do you really need two sets of grouping parenthesis?  Seems like if you are
trying to match one thing (text between a ')' and a '{') you should only
need one grouping.  You can use (?:  )  to group without making a
backreference if you need to.  Perhaps if you explained the transformation
you wish to to acomplish more people can help.  You may also want to use the
'x' modifier and insert some comments into the first portion of the
substitution - makes it a lot easier to get help.

--Ben Kennedy




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

Date: Tue, 21 Nov 2000 11:02:29 -0600
From: dan <infro@yahoo.com>
Subject: A Small Problem Any Sugestions?
Message-Id: <3A1AAAA4.C681969F@yahoo.com>

Hi I have my script  working except for one problem. I am hoping some
one can help stear me in the right direction.
What I am trying to do is write into two different files. The files are
as follows:

This is leeon.txt
100|AB Smith Company|Abit Smith|info@company.com|there location
here|there url here.htm
135|johnson toys|Jane McNere|jmc@toys.com|there town|there url.htm
127|cogslys cogs|Mr. Withersmay|witer@cogs.com|spacelys
sproket|cogslys.htm

This is leeon2.txt
Big Cars|111|263|143
Small Cars|142,1",2',Red|532,-,-,-|162,_,2',Blue
Buses|314|534|121|212

Now my problem is that when I have a space in the key words for
leeon2.txt the script will not add the extra catagorys (1",2',Red). But
when I take the space out the script works fine.

The script is as follows:
#!/usr/bin/perl

print "Content-type: text/html\n\n";

if($ENV{"REQUEST_METHOD"} eq 'GET')
    {$cat = $ENV{"QUERY_STRING"};
     $cat =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
    }
else{
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

@pairs = split(/&/,$buffer);
foreach $pair(@pairs) {
  ($name, $value) = split(/=/,$pair);
  $value =~ tr/+/ /;
  $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
  $FORM{$name} = $value;}
}



open (oldfile, '>>leeons.txt');
@lee = <oldfile>;
seek(oldfile, eof, 1);
print oldfile
"$FORM{'bingo'}|$FORM{'line1'}|$FORM{'line2'}|$FORM{'line3'}|$FORM{'line4'}|$FORM{'line5'}\n";

close(oldfile);



############ Part 2 Write to temp file ###################

open (nothfile, 'leeons2.txt');
@lea = <nothfile>;
close(nothfile);

foreach $line(@lea) {
       chomp($line);
($egory, $extra, @rest) = split(/\|/,$line);
#loop1
 foreach $pair(@pairs) {
  ($name, $value) = split(/=/,$pair);
  $value =~ tr/+/ /;
  $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
  $FORM{$name} = $value;

     if ("$value" eq "$egory") {
 open (tempfile, '>>temp.txt');
 @tea = <tempfile>;
 seek(tempfile, eof, 1);
 print tempfile "$egory|$extra|$FORM{'bingo'}$FORM{\"$value\"}";

 foreach $1(@rest){ print tempfile "|$1";
 }
 print tempfile "\n";
        close(tempfile);
     }
}
}############## END OF LOOPS ##################

close(tempfile);

######### Part 3 write to main file #############################

open (tempfile2, 'temp.txt');
@tea2 = <tempfile2>;
close(tempfile2);

open (othfile, 'leeons2.txt');
@lea = <othfile>;
close(othfile);

open (othfile4, '>leeons2.txt');
@lea4 = <othfile4>;
close(othfile4);

        foreach $line(@lea) {
        chomp($line);
 ($egory, $extra, @rest) = split(/\|/,$line);

        $x=0;

 foreach $lines(@tea2) {
        chomp($lines);
 ($egory2, $extra2, @rest2) = split(/\|/,$lines);



     if ("$egory2" eq "$egory") {
 open (othfile2, '>>leeons2.txt');
 @lea2 = <othfile2>;
 seek(othfile2, eof, 1);
 print othfile2 "$egory2|$extra2";

 foreach $2(@rest2){ print othfile2 "|$2";
 }
 print othfile2 "\n";
        $x=1;
 close(othfile2);
        }

}

      if ($x==0) {
 open (othfile2, '>>leeons2.txt');
 @lea2 = <othfile2>;
 seek(othfile2, eof, 1);
        print othfile2 "$egory|$extra";
 foreach $3(@rest){ print othfile2 "|$3";}
 print othfile2 "\n";
 close(othfile2);
       }

}# end all loops

print "thanks for visiting";

exit;

####################### END ##############

Any help would  be great.

Thanks Dan








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

Date: 21 Nov 2000 18:38:42 +0000
From: nobull@mail.com
Subject: Re: A Small Problem Any Sugestions?
Message-Id: <u9hf51891p.fsf@wcl-l.bham.ac.uk>

dan <infro@yahoo.com> writes:

> Subject: A Small Problem Any Sugestions?

OK you ask for sugestions - here goes.

I suggest you use the Subject line in your posts to describe what you
are posting about rather than use it for cutsie non-information.

> 
> This is leeon.txt
> 100|AB Smith Company|Abit Smith|info@company.com|there location
> here|there url here.htm
> 135|johnson toys|Jane McNere|jmc@toys.com|there town|there url.htm
> 127|cogslys cogs|Mr. Withersmay|witer@cogs.com|spacelys
> sproket|cogslys.htm
> 
> This is leeon2.txt
> Big Cars|111|263|143
> Small Cars|142,1",2',Red|532,-,-,-|162,_,2',Blue
> Buses|314|534|121|212
> 
> Now my problem is that when I have a space in the key words for
> leeon2.txt the script will not add the extra catagorys (1",2',Red). But
> when I take the space out the script works fine.
> 
> The script is as follows:
> #!/usr/bin/perl

I suggest enabling warnings and setting strict mode.

> print "Content-type: text/html\n\n";
> 
> if($ENV{"REQUEST_METHOD"} eq 'GET')
>     {$cat = $ENV{"QUERY_STRING"};
>      $cat =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
>     }
> else{
> read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
>
> @pairs = split(/&/,$buffer);
> foreach $pair(@pairs) {
>   ($name, $value) = split(/=/,$pair);
>   $value =~ tr/+/ /;
>   $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
>   $FORM{$name} = $value;}
> }

I suggest ditching the cargo-cult CGI implementation and use CGI.pm.
 
> open (oldfile, '>>leeons.txt');

I suggest always checking the return value from open().
I suggest using all-uppercase for filehandles.

> @lee = <oldfile>;

I suggest not trying to read from a filehandle you opened write-only.

> seek(oldfile, eof, 1);

I suggest you read the documentation of "eof" and "seek".  That
statement makes no sense at all.

> print oldfile
> "$FORM{'bingo'}|$FORM{'line1'}|$FORM{'line2'}|$FORM{'line3'}|$FORM{'line4'}|$FORM{'line5'}\n";

I sujjest you remove the redunant single qoutes.
> 
> close(oldfile);
> 
> 
> 
> ############ Part 2 Write to temp file ###################
> 
> open (nothfile, 'leeons2.txt');

I suggest always checking the return value from open().
I suggest using all-uppercase for filehandles.

> @lea = <nothfile>;
> close(nothfile);
> 
> foreach $line(@lea) {

I suggest using "while(<nothfile>)" rather than slurping the whole
file into an array.

I suggest you always declare variable in the smallest scope.

>        chomp($line);
> ($egory, $extra, @rest) = split(/\|/,$line);

I suggest you always declare variable in the smallest scope.

> #loop1

I suggest you don't include comments that do nothing to aid the
reability of the code.

>  foreach $pair(@pairs) {
>   ($name, $value) = split(/=/,$pair);

I suggest you always declare variablez in the smallest scope.

>   $value =~ tr/+/ /;
>   $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
>   $FORM{$name} = $value;

I suggest that since you've done this already there's no point doing
it again.

  foreach my $name ( keys %FORM ) {
    my $value = $FORM{$value};

 ...or...

  while (my ($name,$value) = each %FORM) {
 

>      if ("$value" eq "$egory") {

I suggest you don't put redundant double qoutes arround variables. 

>  open (tempfile, '>>temp.txt');

I suggest always checking the return value from open().
I suggest using all-uppercase for filehandles.
I suggest you adopt a consistant indentation convention.

I suggest that either you should rename this file or you should be
opening it in relpace rather than append mode.

The use of "tempfile" and "temp.txt" gives the impression that this is
a temporary file.

>  @tea = <tempfile>;

I suggest not trying to read from a filehandle you opened write-only.

>  seek(tempfile, eof, 1);

I suggest you read the documentation of "eof" and "seek".  That
statement makes no sense at all.

>  print tempfile "$egory|$extra|$FORM{'bingo'}$FORM{\"$value\"}";

I suggest you remove the redundant single quotes arround 'bingo'.  

I have no idea what you expect "$FORM{\"$value\"}" to do so a can't
suggest anything there.

>  foreach $1(@rest){ print tempfile "|$1";
>  }

I suggest you don't use special variables such $1 as the loop control
variable in foreach.  Perl really should throw an error if you try.

I suggest you discover the join() function.

>  print tempfile "\n";
>         close(tempfile);
>      }
> }
> }############## END OF LOOPS ##################
> 
> close(tempfile);

I suggest only closing each file once.


> 
> ######### Part 3 write to main file #############################
> 
> open (tempfile2, 'temp.txt');

I suggest always checking the return value from open().
I suggest using all-uppercase for filehandles.

> @tea2 = <tempfile2>;
> close(tempfile2);
> 
> open (othfile, 'leeons2.txt');

I suggest always checking the return value from open().
I suggest using all-uppercase for filehandles.

> @lea = <othfile>;
> close(othfile);
> 
> open (othfile4, '>leeons2.txt');

I suggest always checking the return value from open().
I suggest using all-uppercase for filehandles.

> @lea4 = <othfile4>;

I suggest not trying to read from a filehandle you opened write-only.

> close(othfile4);
> 
>         foreach $line(@lea) {

I suggest using while() rather than slurping the whole file into an array.

>         chomp($line);
>  ($egory, $extra, @rest) = split(/\|/,$line);
> 
>         $x=0;
> 
>  foreach $lines(@tea2) {
>         chomp($lines);
>  ($egory2, $extra2, @rest2) = split(/\|/,$lines);
> 
> 
> 
>      if ("$egory2" eq "$egory") {

I suggest you don't put redundant double qoutes arround variables. 

>  open (othfile2, '>>leeons2.txt');

I suggest always checking the return value from open().
I suggest using all-uppercase for filehandles.

>  @lea2 = <othfile2>;

I suggest not trying to read from a filehandle you opened write-only.

>  seek(othfile2, eof, 1);

I suggest you read the documentation of "eof" and "seek".  That
statement makes no sense at all.

>  print othfile2 "$egory2|$extra2";
> 
>  foreach $2(@rest2){ print othfile2 "|$2";
>  }

I suggest you don't use special variables such $2 as the loop control
variable in foreach.  Perl really should throw an error if you try.

I suggest you discover the join() function.

>  print othfile2 "\n";
>         $x=1;
>  close(othfile2);
>         }
> 
> }
> 
>       if ($x==0) {

I suggext that where a variable is acting as a boolean flag you treat
it as such.  Just say 

       if ( !$x ) {
  ...or...
       unless ( $x ) {

>  open (othfile2, '>>leeons2.txt');
>  @lea2 = <othfile2>;
>  seek(othfile2, eof, 1);

By now you know what I sugest about that.

>         print othfile2 "$egory|$extra";
>  foreach $3(@rest){ print othfile2 "|$3";}
>  print othfile2 "\n";
>  close(othfile2);
>        }

I suggest that this looks very much like the previous code, perhaps
you should write a subroutine.

> 
> }# end all loops
> 
> print "thanks for visiting";
> 
> exit;
> 
> ####################### END ##############

I suggest if you want to put an end marker in your script that you use
__END__


-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Tue, 21 Nov 2000 14:31:16 -0000
From: "Geoff Winkless" <geoff-at-farmline-dot-com@127.0.0.1>
Subject: Re: Addition vs. concatenation [was: Beginners Blues II]
Message-Id: <8ve0ve$hjm$1@soap.pipex.net>

"Ilmari Karonen" <iltzu@sci.invalid> wrote in message
news:974812727.2114@itz.pp.sci.fi...
> In article <8vbjjb$alf$1@soap.pipex.net>, Geoff Winkless wrote:
> >No. Addition of numbers is associative and commutative.
>
> ..and it would make sense to expect anything that is called addition,
> or uses the addition operator "+", to follow those laws as well.

Why? It's =patently= obvious that you _cannot_ have a (useful) addition
function which follows those rules for strings. It is still clear what most
people's perception of "adding two strings together" would be.

> Of
> course you can call anything you want "addition", but if it's nothing
> like the regular kind of addition, don't expect your definition to be
> considered useful.

Your definition is restrictive. Mine is useful. :-)

> >> That might seem like nitpicking, but IMHO it's just plain silly that
> >> "$" + 2 + 3 equals "$23" in Java.
> >
> >What does "$" + (2+3) give?
>
> "$5".  Which is more or less my point.

Now we're talking about precedence of type conversion. Since both the + have
equal precedence the "$" + 2 is evaluated first. Now this involves a type
conversion to a string, which gives "$2", you then evaluate the second
option and get "$2" + 3, which gives another type conversion and gives
"$23".


> In maths, and in just about
> any place else where a "+" operator is used, a+b+c equals (a+b)+c
> equals a+(b+c).  When it doesn't, it's silly and counterintuitive.

But it's -not-. It's not -intuitive- that + is commutative, it's just
something that happens. It's -intuitive- that adding two strings together
produces a long string with the first string at the beginning and the second
string afterwards.

There's a huge difference between "fits with mathematical rules" and
"intuitive".

> Just about anyone can see why proper operator precedence is a good
> thing.  Is is so hard to see why that applies to associativity too?

Yes. Operator precedence could cause problems, you could never be sure that
a+b*c would return the answer you wanted.

No-one could ever possibly _expect_ "hello " + "there" to produce
anything -except- "hello there", unless a specific statement were made such
that in the specific language string + produced (eg) "htehlelroe " or some
insane per-character ascii addition (which would be most appropriate,
according to your rules, since that would be commutative and reversible).

> >Why is -that- silly? In -either- respect, either -(5%3) or (-5)%3 it
makes
> >perfect sense...
>
>  1. Mathematical reason: x%y should equal (x+y)%y for all x and y.

Explain to me how (-5 + 3) MOD 3 (ie -2) is not the same as (-5) MOD 3
ie -2...

The only time when this will not work is when you cross over the boundary
from positive to negative numbers, ie -1 MOD 3 gives -1 whereas (-1 + 3) MOD
3 gives 2.

Geoff




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

Date: 21 Nov 2000 16:46:16 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Addition vs. concatenation [was: Beginners Blues II]
Message-Id: <8ve8so$1o6$1@lublin.zrz.tu-berlin.de>

Ilmari Karonen  <usenet11282@itz.pp.sci.fi> wrote in comp.lang.perl.misc:
>In article <8vbjjb$alf$1@soap.pipex.net>, Geoff Winkless wrote:
>>"Ilmari Karonen" <iltzu@sci.invalid> wrote in message

>>> Almost as silly as -5%3 being -2.
>>
>>Why is -that- silly? In -either- respect, either -(5%3) or (-5)%3 it makes
>>perfect sense...
>
> 1. Mathematical reason: x%y should equal (x+y)%y for all x and y.
>
> 2. Practical reason: It's awkward to write x%y<0?x%y+y:x%y every time
>    one needs to normalize x to modulo y.  Of course, that doesn't
>    matter much unless one is writing something that involves modular
>    arithmetic, but if one isn't, then the "%" operator is of limited
>    usefulness anyway.

Treatment of singed operands by the mod operation varies wildly, and
Perl hands down what it gets.  All the while, there is a perfectly
reasonable extension of the modulo operation x%y for all real x and y:
Let x%y = x - y*floor(x/y) if y != 0, and let x%0 = x.  The theory
can be found in (where else) Knuth, _The Art..._ Vol 1, see index.

Long ago, when Perl 5 came out, I proposed a patch that implemented
this.  Of course it wasn't accepted, it breaks old code.

Anno


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

Date: Tue, 21 Nov 2000 07:48:59 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Closing a window
Message-Id: <slrn91krpr.hu3.tadmc@magna.metronet.com>

On Tue, 21 Nov 2000 13:29:50 +0100, Alan J. Flavell 
   <flavell@mail.cern.ch> wrote:
>On Tue, 21 Nov 2000 swilsonnissa@my-deja.com wrote:

>> > Your browser has no idea whether the HTML code it received was
>> > generated by a Perl script or an ASP page,
>
>> Very helpful advice, I must say! 


>This earns you a place in numerous score files, I suspect.


The Subject: had already done that  :-)


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


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

Date: 21 Nov 2000 07:20:59 -0700
From: tchrist@perl.com (Tom Christiansen)
Subject: Re: Concatenating files
Message-Id: <3a1a84cb@cs.colorado.edu>

In article <t19ul9amlf8r62@corp.supernews.com>,
Mark  <MPEDDLE@uk.ibm.com> wrote:
>I was wondering if it was at all possible to concatenate FILES in Perl, i 
>have not found a function to do this. 

Why would you expect that there might exist a function in a
general-purpose programming language to do such a special-purpose
thing?

Why does everyone ask for a function or a module or a command that
does X for all values of X?  Why don't they *program*?  This is a
programming language.  What you need is an algorith.  It is trival
to open a file, print its contents, open another file, print *its*
contents, etc.


>Do i have to read each file into an array first, and then concatenate 
>arrays - this would be very slow, especially it involved large data 
>quantities.

Rule 1: *NEVER* read the file into an array.  It's Dumb Novice
Mistake number two hundred nineteen.  This advice is not always
right, but it is better to think you should never do so than to
think you should do so in all cases.

Canonically: 

    while (<>) { print } 

But you can of course embellish, as in

    local *ARGV;
    local @ARGV = @input_files;
    while (<>) { print } 

And even more.  But the normally preferred way to do this is simply

    system("cat f1 f2 f3 f4 > fout");

Please stop asking for a turn-key, non-thinking, anti-programmer
solution to everything.  Turning blindly to shrink wrap is wrong,
because it renders one incapable of doing real work.  You have 
to think things through.  This is not Microsoft.

--tom


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

Date: Tue, 21 Nov 2000 17:26:18 GMT
From: "Ben Kennedy" <bkennedy@hmsonline.com>
Subject: Re: copying / renaming associative arrays ---or something...
Message-Id: <_eyS5.131580$td5.19636572@news1.rdc2.pa.home.com>


"Mike Hall" <mhall@****nwa.quik.com> wrote in message
news:twjS5.782$lt6.88233@nnrp2.sbc.net...
> The data is being read into an associative array for the
> calculations, which is fine if there is only one set of information, but
> what I need to do is if the "Continue" button is pressed, read in the
data,
> store it in the array

Because you are dealing with the the web, html forms, etc this is more more
of a CGI question.  Since http is a stateless protocol, you will be unable
to store the various stages of the form in perl data structures in between
requests.  Probably the easiest solution for you would be to return each set
of data back to the client as hidden form elements that will be sent along
with the next page.  Look at comp.infosystems.www.authoring.cgi for CGI
resources, and see "perldoc CGI", and try a search on Google.com for CGI
info.

> I have been through the numerous FAQ's available on the web, and I can
find
> no mention of doing this... is it not possible to do it this way?  Would
it
> be easier to keep the data as the data returned by the POST from the form
so
> that it could be stored as a single string variable like $form1, $form2,
> $form3, $form4 and then have each be parsed into the associative array and
> calculated?  I tend to make things too complicated sometimes...

Someone who says "associative array" probably doesn't have the book
"Programming Perl" (aka the Camel) - this should tell you all you need to
know about complex data structures (also see perldoc perlref).  Yes its
possible to make an array of hashes, but as I said before it won't help you
with this particular issue.

--Ben Kennedy




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

Date: Tue, 21 Nov 2000 16:18:53 GMT
From: adelton@fi.muni.cz (Honza Pazdziora)
Subject: Re: default perl to execute in current dir ?
Message-Id: <G4DunH.2G@news.muni.cz>

On Tue, 21 Nov 2000 00:09:01 GMT, dtbaker_dejanews@my-deja.com <dtbaker_dejanews@my-deja.com> wrote:
> 
> 
> I am having trouble tracking down the difference in the install or
> configuration of either windows or perl between two windows 98 PCs. One
> one PC, perl scripts execute with the working directory set to the dir
> where the script is, and on the other, it defaults to /usr/bin where
> perl.exe is installed.
> 
> I now I should not rely on the current wd, but for the sake of easy
> utility script execution on local files in a dir, I'd really like to
> configure perl to open and execute in the dir that the script is fired
> up in.
> 
> I realize this is probably a windoze issue, but I cant find a solution
> in the windows help files either....

May it be a way in which .pl is tied to the interpret? IIRC, #! is not
supported on Windows and so somehow the extension of the script is
defined to run the executable. Perhaps it's where the change is
specified as well?

Yours,

-- 
------------------------------------------------------------------------
 Honza Pazdziora | adelton@fi.muni.cz | http://www.fi.muni.cz/~adelton/
   .project: Perl, DBI, Oracle, MySQL, auth. WWW servers, MTB, Spain.
Petition for a Software Patent Free Europe http://petition.eurolinux.org
------------------------------------------------------------------------


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

Date: Tue, 21 Nov 2000 15:09:12 +0100
From: Andre H <no-mailr@blabla.org>
Subject: Re: desperate pls help me!
Message-Id: <3A1A8207.99B8F729@blabla.org>

M Lambert wrote:

> Im trying to write a cgi that will allow users to run a reporting tool and
> have the report emailed to them... the problem is the reports can take up to
> 3 hours to generate.  How do I background a process in Perl that will allow
> users to visit a cgi and leave while the pro finoishes up without them...
> ive exhausted all resources and am serioulsy considering opening a telent
> socket to THE SAME  mahcine via the Perl CGI in order to "nohup runinit &".
>
> Any ideas???
>
> system("$path/$to/$prog &");  DOES NOT work... like i said this process
> takes
> a long time to complete (3 hours)... it times out with the browser and I
> cant get it to stay alive!!!!! im very very desperate... anyone?

I have no time to test  this, but I would try somthing like

system (nohup your sql portion );

I don't know in perl, but in shell (ksh) you can close the std in, std out,
stderror and leave, the forked child will stay alive

Good luck (let us know if you find a way )

regards

--

Andre H.                      UNIX System Administrator





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

Date: 21 Nov 2000 09:15:04 -0500
From: darkon@one.net (David K. Wall)
Subject: Re: Enumerate Existing Modules ?
Message-Id: <8FF359094darkononenet@206.112.192.118>

boomer2000@my-deja.com wrote in <8vd4ec$r56$1@nnrp1.deja.com>:

>Is there a way to simply enumerate (list) all of the existing PERL
>modules on a server ?

Check out the autobundle function of CPAN.pm.  If you want to roll your 
own, you could use File::Find to scan through all the directories in @INC 
for files ending with '.pm'.  Or some other way.

(BTW, the preferred usage around here is Perl = the language, perl = the 
interpreter/compiler, PERL = ?.  Perl programmers are case-sensitive. :-)

-- 
David Wall
darkon@one.net


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

Date: Tue, 21 Nov 2000 15:24:09 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Enumerate Existing Modules ?
Message-Id: <1r4l1tsalpcj8kc3jod0ncqpefvggdmsg2@4ax.com>

Tad McClellan wrote:

>On Tue, 21 Nov 2000 06:24:16 GMT, boomer2000@my-deja.com 
>   <boomer2000@my-deja.com> wrote:
>>Is there a way to simply enumerate (list) all of the existing PERL
>>modules on a server ?
>
>#!/usr/bin/perl -w
>use strict;
>use File::Find;
>find( sub { print "$_\n" if /\.pm$/}, @INC );

I find this clumsy. Here's my version:

    use File::Find;
    {
        my $offset = 0;
        local $\ = "\n";
        find sub { 
            if($_ eq '.') {
                $offset = 1 + length $File::Find::name;
            } elsif(/\.pm$/) {
                local $_ = substr($File::Find::name, $offset);
                s/\//::/g;
                s/\.pm$//;
                print;
            }
        }, @INC;
    }

-- 
	Bart.


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

Date: 21 Nov 2000 08:51:53 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Enumerate Existing Modules ?
Message-Id: <m1bsv946ae.fsf@halfdome.holdit.com>

>>>>> "Bart" == Bart Lateur <bart.lateur@skynet.be> writes:

Bart> Tad McClellan wrote:
>> On Tue, 21 Nov 2000 06:24:16 GMT, boomer2000@my-deja.com 
>> <boomer2000@my-deja.com> wrote:
>>> Is there a way to simply enumerate (list) all of the existing PERL
>>> modules on a server ?
>> 
>> #!/usr/bin/perl -w
>> use strict;
>> use File::Find;
>> find( sub { print "$_\n" if /\.pm$/}, @INC );

Bart> I find this clumsy. Here's my version:

Bart>     use File::Find;
Bart>     {
Bart>         my $offset = 0;
Bart>         local $\ = "\n";
Bart>         find sub { 
Bart>             if($_ eq '.') {
Bart>                 $offset = 1 + length $File::Find::name;
Bart>             } elsif(/\.pm$/) {
Bart>                 local $_ = substr($File::Find::name, $offset);
Bart>                 s/\//::/g;
Bart>                 s/\.pm$//;
Bart>                 print;
Bart>             }
Bart>         }, @INC;
Bart>     }

Or you could use my trick of putting a "marker" in the directory name
(first documented at <http://www.stonehenge.com/merlyn/UnixReview/col16.html>:

    use File::Find;
    find sub {
      return unless my ($x) = $File::Find::name =~ m{\./(.*\.pm)$};
      $x =~ s,/,::,g;
      print "$x\n";
    }, map "$_/.", grep m{^/}, @INC;

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: 21 Nov 2000 12:15:27 -0500
From: darkon@one.net (David K. Wall)
Subject: Re: Enumerate Existing Modules ?
Message-Id: <8FF37CFE6darkononenet@206.112.192.118>

bart.lateur@skynet.be (Bart Lateur) wrote in 
<1r4l1tsalpcj8kc3jod0ncqpefvggdmsg2@4ax.com>:

>Tad McClellan wrote:
>
>>On Tue, 21 Nov 2000 06:24:16 GMT, boomer2000@my-deja.com 
>>   <boomer2000@my-deja.com> wrote:
>>>Is there a way to simply enumerate (list) all of the existing PERL
>>>modules on a server ?
>>
>>#!/usr/bin/perl -w
>>use strict;
>>use File::Find;
>>find( sub { print "$_\n" if /\.pm$/}, @INC );
>
>I find this clumsy. Here's my version:
>
>    use File::Find;
>    {
>        my $offset = 0;
>        local $\ = "\n";
>        find sub { 
>            if($_ eq '.') {
>                $offset = 1 + length $File::Find::name;
>            } elsif(/\.pm$/) {
>                local $_ = substr($File::Find::name, $offset);
>                s/\//::/g;
>                s/\.pm$//;
>                print;
>            }
>        }, @INC;
>    }

As long as we're playing with different versions, here's mine. :-)

use File::Find;
sub get_module_names {
    my @modules;
    my $filter_file_names = sub {
        if (/\.pm$/ && /^[^_]/) { #ignore private modules
            my $mod = $File::Find::name;
            foreach my $dir (@INC) { # remove leading path from mod name
                last if $mod =~ s|^$dir/||; # not very portable
            }
            $mod =~ s/\.pm$//;
            $mod =~ s|/|::|g; # not very portable
            push @modules, $mod;
        }
    };
    find( $filter_file_names, @INC );
    return wantarray ? @modules : "@modules";
}
my @mods = get_module_names();
@mods = sort @mods;
print join "\n", @mods;


-- 
David Wall
darkon@one.net


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

Date: Tue, 21 Nov 2000 18:12:43 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Enumerate Existing Modules ?
Message-Id: <k3el1t8utojfnhu4idp22r96ecianfe4gf@4ax.com>

Randal L. Schwartz wrote:

>Or you could use my trick of putting a "marker" in the directory name
>(first documented at <http://www.stonehenge.com/merlyn/UnixReview/col16.html>:
>
>    use File::Find;
>    find sub {
>      return unless my ($x) = $File::Find::name =~ m{\./(.*\.pm)$};
>      $x =~ s,/,::,g;
>      print "$x\n";
>    }, map "$_/.", grep m{^/}, @INC;

On Windows, I get:

invalid top directory at D:/programs/indigoperl/lib/File/Find.pm line
279.

It works on FreeBSD (Unix), but it still has a few rough edges.

 * You still have the ".pm" extension.

      return unless my ($x) = $File::Find::name =~ m{\./(.*)\.pm$};

 * What if a normal directory name ends in a dot?

      return unless my ($x) = $File::Find::name =~ m{/\./(.*)\.pm$};

or

      return unless my ($x) = $File::Find::name =~ m{.*\./(.*)\.pm$};

The latter makes use of greedy matching, and the fact that a directory
name that is part of the official module specific path (the "Foo" in
"Foo::Bar") may contain no dots.

I guess that, on Unix, even double slashes are acceptable.

    use File::Find;
    find sub {
      return unless my ($x) = $File::Find::name =~ m{.*//(.*)\.pm$};
      $x =~ s,/,::,g;
      print "$x\n";
    }, map "$_//", grep m{^/}, @INC;

This works on FreeBSD. On Windows, I still get the same error as before.

-- 
	Bart.


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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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 V9 Issue 4940
**************************************


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