[22956] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5176 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jul 4 00:06:15 2003

Date: Thu, 3 Jul 2003 21:05:06 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 3 Jul 2003     Volume: 10 Number: 5176

Today's topics:
    Re: "Word too long" ? And exactly WHAT word might that  <grazz@pobox.com>
    Re: A little regex help? <bdonlan@bd-home-comp.no-ip.org>
    Re: A little regex help? <emschwar@pobox.com>
    Re: A little regex help? <abigail@abigail.nl>
    Re: A little regex help? <uri@stemsystems.com>
    Re: Alternative to use vars <mgjv@tradingpost.com.au>
    Re: Apache/Perl segfaulting on system calls (Jeff)
    Re: boolean expression regexp <ebohlman@earthlink.net>
    Re: Call parent method indirectly <grazz@pobox.com>
    Re: detecting links <abigail@abigail.nl>
    Re: installing perl modules via ftp <flavell@mail.cern.ch>
    Re: need assistance understanding multilevel hashes. <sten@beyond.the.sun.org>
    Re: need assistance understanding multilevel hashes. (Jay Tilton)
    Re: need assistance understanding multilevel hashes. <Sturmgewehr@DYPyX56w.com>
    Re: perl script generates sendmail NOQUEUE: connect fro (Per Hedeland)
    Re: pipe - non blocking read? (fork/Win32) <ben.goldberg@hotpop.com>
    Re: renaming badly named files... (Randal L. Schwartz)
    Re: script for unrestricted permutation (Bryan Castillo)
        using pipe & perl's ARGV filehandle ? (stu7)
    Re: using pipe & perl's ARGV filehandle ? <uri@stemsystems.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 04 Jul 2003 00:20:38 GMT
From: Steve Grazzini <grazz@pobox.com>
Subject: Re: "Word too long" ? And exactly WHAT word might that be? Curious
Message-Id: <qL3Na.12768$U23.8235@nwrdny01.gnilink.net>

news@roaima.freeserve.co.uk wrote:
> Sara <genericax@hotmail.com> wrote:
> > I have a script that runs fine, but on invocation in csh or bash or
> > tcsh or ksh, the script reports:
> >    Word too long 

> [...] However, my gut feeling is that this is a OS/shell 
> issue.  What I suspect is happening is that your shell 
> (csh, or whatever) is seeing the #! line and trying to pass 
> the file to the named interpreter (i.e. perl) itself.

The shell never looks at the shebang -- that's handled by
the kernel during execve().

But since Perl doesn't have a "Word too long" diagnostic,
you're probably correct that a shell is being invoked by
mistake.

-- 
Steve


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

Date: Thu, 03 Jul 2003 19:38:58 -0400
From: "bd" <bdonlan@bd-home-comp.no-ip.org>
Subject: Re: A little regex help?
Message-Id: <pan.2003.07.03.23.38.58.579769@bd-home-comp.no-ip.org>

On Thu, 03 Jul 2003 11:45:27 -0600, Eric Schwartz wrote:

[snip]
> $ perl -i -pe 's/print\((.+?)(\\n)?"\);/print($1\\n");/g' input

Wouldn't \1 be more efficient, as it does not turn on the $n variables for
all the regexes?

$ perl -i -pe 's/print\((.+?)(\\n)?"\);/print(\1\\n");/g' input

-- 
Freenet distribution not available
Pick another fortune cookie.



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

Date: 03 Jul 2003 18:00:54 -0600
From: Eric Schwartz <emschwar@pobox.com>
Subject: Re: A little regex help?
Message-Id: <etobrwbqhxl.fsf@wormtongue.emschwar>

"bd" <bdonlan@bd-home-comp.no-ip.org> writes:
> On Thu, 03 Jul 2003 11:45:27 -0600, Eric Schwartz wrote:
> [snip]
> > $ perl -i -pe 's/print\((.+?)(\\n)?"\);/print($1\\n");/g' input
> 
> Wouldn't \1 be more efficient, as it does not turn on the $n variables for
> all the regexes?

No.  You also need to re-read perlre, specifically the section
"Warning on \1 vs $1".  

Just for kicks, though, I benchmarked the two approaches:

$ cat /tmp/testbackref 
#!/usr/bin/perl
use warnings;
use strict;
use Benchmark;

timethese(1000000, {
        '$n variables' => sub { 
                                my $bob = 'print("foo");';
                                $bob =~ s/print\((.+?)(\\n)?"\);/print($1\\n");/g;
                              },
        '\n backrefs' => sub { 
                                my $bob = 'print("foo");';
                                $bob =~ s/print\((.+?)(\\n)?"\);/print(\1\\n");/g;
                              },
});

After running it a few times to cache as much as possible:

$ perl /tmp/testbackref 
\1 better written as $1 at /tmp/testbackref line 13.
Benchmark: timing 1000000 iterations of $n variables, \n backrefs...
$n variables: 10 wallclock secs (10.42 usr +  0.00 sys = 10.42 CPU) @ 95969.29/s (n=1000000)
\n backrefs: 10 wallclock secs (10.34 usr +  0.00 sys = 10.34 CPU) @ 96711.80/s (n=1000000)

So even if it weren't incorrect (note the warning), it doesn't seem to
do you any noticable good-- and that's over a million iterations.
With Perl, you're much better off looking for better algorithms than
cool language tricks as a rule; the overhead of running Perl generally
swamps such infinestimal efficiencies anyhow.

> $ perl -i -pe 's/print\((.+?)(\\n)?"\);/print(\1\\n");/g' input

That's a nasty habit you really should get rid of one of these days.

-=Eric
-- 
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
		-- Blair Houghton.


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

Date: 04 Jul 2003 00:02:19 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: A little regex help?
Message-Id: <slrnbg9h0b.poc.abigail@alexandra.abigail.nl>

bd (bdonlan@bd-home-comp.no-ip.org) wrote on MMMDXCIII September MCMXCIII
in <URL:news:pan.2003.07.03.23.38.58.579769@bd-home-comp.no-ip.org>:
))  On Thu, 03 Jul 2003 11:45:27 -0600, Eric Schwartz wrote:
))  
))  [snip]
)) > $ perl -i -pe 's/print\((.+?)(\\n)?"\);/print($1\\n");/g' input
))  
))  Wouldn't \1 be more efficient, as it does not turn on the $n variables for
))  all the regexes?

No. The fact \1 "works" is a special hack. Usually, \1 means "^B",
but for the replacement part of substitutions, an exception is
made for \1 .. \9. To make people coming from 'sed' feel at home.

The $N variables will be "turned" on only for those regexes that 
use parenthesis. If you want to use \1, you need to have parens,
and hence you will have $1.



Abigail
-- 
perl -we 'print q{print q{print q{print q{print q{print q{print q{print q{print 
               qq{Just Another Perl Hacker\n}}}}}}}}}'    |\
perl -w | perl -w | perl -w | perl -w | perl -w | perl -w | perl -w | perl -w


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

Date: Fri, 04 Jul 2003 00:03:25 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: A little regex help?
Message-Id: <x73chnyx85.fsf@mail.sysarch.com>

>>>>> "b" == bd  <bdonlan@bd-home-comp.no-ip.org> writes:

  b> On Thu, 03 Jul 2003 11:45:27 -0600, Eric Schwartz wrote: [snip]
  >> $ perl -i -pe 's/print\((.+?)(\\n)?"\);/print($1\\n");/g' input

  b> Wouldn't \1 be more efficient, as it does not turn on the $n
  b> variables for all the regexes?

where did you get that perl legend from? it is not true and using \1 in
the REPLACEMENT string is deprecated. \1 is meant only to be used in the
regex itself. the $n vars are fine in the replacement string or
afterwards (provided you tested the result of the regex).

i think you might be confusing that with the problem of $& which will
cause a slowdown in all regexes, regardless if they grab or not. if you
explicitly grab in s///, you will force a copy to be made so you can
refer back to the grabbed parts with $n.

uri

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


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

Date: 04 Jul 2003 00:04:39 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Alternative to use vars
Message-Id: <slrnbg9h4p.1ge.mgjv@verbruggen.comdyn.com.au>

On 3 Jul 2003 10:33:08 GMT,
	Tassilo v. Parseval <tassilo.parseval@rwth-aachen.de> wrote:
> Also sprach Eric J. Roode:
> 
>> gbacon@hiwaay.net (Greg Bacon) wrote in news:vg5mmas61oi489
>> @corp.supernews.com:
>> 
>>> You can also declare the globals with our:
>>> 
>>>     our $scalar;
>>>     our @array;
>>>     our %hash;
>>> 
>>> See the perlfunc documentation on our for details.
>> 
>> Maybe I'm dense.... I have yet to grasp the advantage of 'our' over 'use 
>> vars'.
> 
> You are not the only one trying to grasp that. The concept of lexically
> scoped global (that is, dynamic) variables truely escapes me. The only
> advantage I see is that you can introduce new global variables
> everywhere easily like so:

You can limit (with our) where that global variable is accessible:


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

{
    use vars qw/$var/;
    $var = "var";
    our $our = "our";

    print "var: $var\n";
    print "our: $our\n";
}

print "var: $var\n";
# print "our: $our\n"; # impossible
sub_needing_global();

sub sub_needing_global
{
    our $our;
    print "our: $our\n";
}

while $var is accessible to all code in this program, $our is only
available to the lexical scopes that have C<our $our>. This means that
you need to specifically state that you are planning on using $our in
a block, and can't accidentally use it in other places.

In a single file, the same effect can be achieved with C<my>, but in
multi-file projects that require a shared global, you can't use C<my>
for the same purpose.

Many people would say that it's better to avoid globals alltogether,
but sometimes globals can make life a lot easier, and code much
cleaner. In those cases, our is much preferable over C<use vars>
because of the more finegrained control it gives you about the
accessibility of that variable. It can prevent accidental access of
globals in the same way that C<my> lexical scoping does.


Of course, if you declare a list of variables at the start of a file,
with C<our>, the effect is the same as a C<use vars>. If that's all
you ever do, then you wouldn't knotice a difference.

C<use vars> is still deprecated, so it's probably better (unless you
have to write code for 5.005) to not use it anymore.

Martien
-- 
                        | 
Martien Verbruggen      | If it isn't broken, it doesn't have enough
Trading Post Australia  | features yet.
                        | 


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

Date: 3 Jul 2003 19:18:09 -0700
From: me@jeffsu.com (Jeff)
Subject: Re: Apache/Perl segfaulting on system calls
Message-Id: <b7ad4a98.0307031818.588268b8@posting.google.com>

The apache child sporadically dies at any type of system call in any
context that we use (perl module, HTML::Mason)

open IN, "swift -d $file | " or warn "could not execute swift $file";
my $usage = `du -Sh $rootDir`;
my $n = system("rsync $src $dest");

I tried looking in the error logs... I'm getting lines that look like
this:
[Thu Jul  3 18:57:03 2003] [notice] child pid 389 exit signal
Segmentation fault (11)

I've also tried to setting the MaxRequestPerChild in apache to 0 but
that didn't work either. I don't think it has anything to do with the
way perl cleans up.

-Jeff

"J. Gleixner" <glex_nospam@qwest.net> wrote in message news:<xV0Na.43$hO4.88593@news.uswest.net>...
> Jeff wrote:
> > I seem to be getting sporadic segfaults when I make system calls in
> > mod_perl.  They are happening when I use backticks, the system
> > command, and/or the open command with a pipe.  Would anyone please
> > help me out?
> > 
> > Here's what I'm using...
> > 
> > OS: Red Hat Linux 8.0 (Psyche)
> > Perl: v5.8.0 i386-linux-thread-multi
> > Apache: 1.3.27
> > 
> > Thanks,
> > -Jeff
> 
> Some code would be helpful.  Also, check your error log to see if 
> anything useful is in there.


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

Date: 3 Jul 2003 23:44:39 GMT
From: Eric Bohlman <ebohlman@earthlink.net>
Subject: Re: boolean expression regexp
Message-Id: <Xns93ADBF52D4199ebohlmanomsdevcom@130.133.1.4>

zatan@myway.com (zm) wrote in 
news:efc65930.0307021344.25cd6e40@posting.google.com:

> Hello,
> 
> Does anyone know of any tool or code to convert a boolean expression
> like:
> (Aword and Bword* and (Dword or Cword*) into a regexp?
> 
> A, B ...are literal words, and * means that it can be part of another
> word?
> 
> An final user of our tool is able to write the boolean expression, but
> not the regexp one.

Text::Query.


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

Date: Fri, 04 Jul 2003 03:04:19 GMT
From: Steve Grazzini <grazz@pobox.com>
Subject: Re: Call parent method indirectly
Message-Id: <T86Na.1015$Ha.402@nwrdny02.gnilink.net>

Eric J. Roode <REMOVEsdnCAPS@comcast.net> wrote:
> Malte Ubl <ubl@schaffhausen.de> wrote:
>>
>> my $super = "SUPER::$method";
>> $self->$super(@args)
> 
> Interesting.  I will try it.

You can also do:

  $self->can("SUPER::$method")->(@args);

-- 
Steve


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

Date: 03 Jul 2003 23:09:22 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: detecting links
Message-Id: <slrnbg9dt2.poc.abigail@alexandra.abigail.nl>

jsowers@csc.com (jsowers@csc.com) wrote on MMMDXCIII September MCMXCIII
in <URL:news:be1rto$864$1@lore.csc.com>:
%%  Is there any simple way to determine if a reference returned via readdir 
%%  is a soft- or hardlink rather than a directory or filename. 
%%  None of my perl books seem to show any way of telling.


I think you misunderstand what a hardlink is. A "hardlink" is just the
mapping from a filename to an inode number. So, if you create a file
"fnord", that's a hardlink. If you then link "fnord" to "womble", then
"womble" maps to the same inode as "fnord". They are both hardlinks.
The OS treats both "fnord" and "womble" equally. It's not that one is
the file and the other the link - no, they are both links. That is,
"fnord" and "womble" are two, different, names for the same file.



Abigail
-- 
perl -we '$_ = q ;4a75737420616e6f74686572205065726c204861636b65720as;;
          for (s;s;s;s;s;s;s;s;s;s;s;s)
              {s;(..)s?;qq qprint chr 0x$1 and \161 ssq;excess;}'


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

Date: Fri, 4 Jul 2003 00:12:34 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: installing perl modules via ftp
Message-Id: <Pine.LNX.4.53.0307032351340.27445@lxplus069.cern.ch>

On Thu, Jul 3, Gunnar Hjalmarsson inscribed on the eternal scroll:

> > I must admit I'm sceptical.  Sure, there are many cases where it
> > would work, but you're trying to help someone who can probably be
> > rated as a relative beginner, so it'll be hard to explain that it's
> > OK for some modules and not OK for others, and to set out the
> > various possible issues.  They might be led into wasting a lot of
> > time and effort before working out that they're dealing with a case
> > where it isn't feasible.
>
> It's true that you would need to explain when it works and when it
> doesn't, and yes, occassionally someone might misunderstand.

I'm sorry if I sounded too negative; but experience shows (I think
it's fair to say) that writing CGI script (at least for deployment in
a WWW situation) is a serious enterprise, and calls for a serious
attitude to the task.

Since this is precisely the context where this problem arises, I
honestly think there's no harm in challenging the typical questioner
to not expect a trivial answer to their problem.  A "simple and
straightforward solution", yes, by all means..., but 'trivial', not.

But if that 'straightforward' solution demands a particular
infrastructure (in this case, a service provider who allows the
correct solution - a solidly peer-reviewed and supported module -
rather than cargo-cult perl4-flavoured stuff) then I think the right
thing to do is to say so, firmly, or else we're all doomed to be stuck
with sub-optimal solutions, as service providers progressively apply
the lowest common denominator[1] and freeze-out the good stuff, and
users fiddle around trying to bypass their service providers'
unwillingless to support the right solution, leading to pointless
additional complexity for people who are, as you say, relative
beginners, while apparently favouring those who stuff-in the
relatively dangerous cargo-cult perl4-ish solutions that they can pick
up off the dark side of the web.

> Nevertheless, I believe it would
>
> 1) increase the Perl user base and
>
> 2) encourage the use of modules
>
> both of which I thought were good things.

I take your point, indeed.

> You are right that I'm trying to help relative beginners. I'm counting
> myself to that category, and yes, I appreciate proper documentation
> that I'm able to understand and follow. Besides, we are all beginners
> to start with, right? ;-)

That too, for sure.

all the best

[1] anyone who happens to be familiar with my web pages will know that
the term 'LCD' was used ironically.


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

Date: Thu, 03 Jul 2003 22:22:52 GMT
From: Sten <sten@beyond.the.sun.org>
Subject: Re: need assistance understanding multilevel hashes.
Message-Id: <53a9gvk3644a4qn8us7qe3qvmic61p20i1@4ax.com>

On Thu, 03 Jul 2003 13:02:48 GMT, Allen Wooden
<allen.wooden@educate.invalid> wrote:

>On Wed, 02 Jul 2003 22:20:41 GMT, tiltonj@erols.com (Jay Tilton)
>wrote:

>
>printf "tag value for customer $cust is: $hash1{tag}\n"; 
jeez, nuther typo.  
should have been printf "tag for customer $cust is:  %s \n",
$hash1{tag};

or even
 print "tag for customer $cust is: $hash1{tag}\n";

Is it the method in which I'm trying to access the hash that's wrong?





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

Date: Thu, 03 Jul 2003 22:28:39 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: need assistance understanding multilevel hashes.
Message-Id: <3f04a466.44128109@news.erols.com>

Allen Wooden <allen.wooden@educate.invalid> wrote:

: Code:
: #!/usr/local/bin/perl -w
: #$Id: find_hashes,v 1.2 2003/06/25 18:54:02 awooden Exp $
: use strict;
: use diagnostics;
: our ($v,$cust,%hash1,$data,$who,$field,$keys,$values,%hash,@a);
: $cust = $ARGV[0];
: 
: do '/export/home/awooden/snippets/test.cfg';
: open(FILE,"< /export/home/awooden/snippets/test.cfg") or die "Error:
: $!";
: @a = grep(/\%/,<FILE>); # only read in hashes from config file.
: close FILE;
: foreach  (@a) {
:         $data =(split/\ \=\ \(/)[1]; 
:         $data =~ s/\)\;//;      
:         $who = (/^\%(\w+) /); 
:         $who = "$1";
:         print "WHO: $who\n";
:         print "DATA: $data\n";
:         for $field ( split(/,/,$data) ) {
:         print "The fields are: $field\n";
:         ($keys, $values) = split /=\>/, $field;
:         print "the keys are $keys\n";
:         print "the values are $values\n";
:         $hash{$who}{$keys} = $values;
:         }

Naw, man.  You're making things harder than they need to be.
Look at some of what ends up in %hash:

      'foo' => {
        ' "page_num" ' => ' "1" 
    ',
        ' "rate" ' => ' "0"',
        ' "ports" ' => ' "1"',
        ' "rrd0" ' => ' \'some_path\'',
        ' "tag" ' => ' \'Foo Co.\''
      }

All the keys and values still have their quotes.
$hash{foo}{'tag'} does not exist, but $hash{foo}{' "tag" '} does.

Let perl parse Perl.

New test.cfg:

    %foo = (
        "ports" => "1", "rrd0" => 'some_path', "rate" => "0", 
        "tag" => 'Foo Co.', "page_num" => "1"
    );
    %bar = ( "ports" => "1", "rrd0" => 'some_path_x', 
        "rrd1" => 'some_path_x1', "rate" => "1000000", 
        "tag" => 'Bar Co.', "page_num" => "2" 
    );
    %hash = ( foo => \%foo, bar => \%bar );

New code:

    #!/usr/local/bin/perl -w
    use strict;
    use diagnostics;
    our %hash;
    my $cust = $ARGV[0];
    die "usage: $0 [customer name]\n"
      unless defined $cust;
    my $ret = do 'test.cfg';
    unless( defined $ret ) {
        die "eval failed: $@" if $@;
        die "do failed: $!";
    }
    die "unknown customer '$cust'\n"
      unless defined $hash{$cust};
    my %hash1 = %{ $hash{$cust} };

    for( keys %hash1) {
        print "keys are: $_\n";
        print "value for $_ \= $hash1{$_}";
        print "\n";
    }

    my $v = $hash1{tag};
    print "$v\n";



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

Date: Fri, 04 Jul 2003 01:14:54 GMT
From: Sturmgewehr <Sturmgewehr@DYPyX56w.com>
Subject: Re: need assistance understanding multilevel hashes.
Message-Id: <iik9gvonvrfencqtgf8u5agelr76rb6ghd@4ax.com>

On Thu, 03 Jul 2003 22:28:39 GMT, tiltonj@erols.com (Jay Tilton)
wrote:


>
>New test.cfg:
>

>    %hash = ( foo => \%foo, bar => \%bar );

And the smoke clears..
this is going to make things alot easier..

Thanks




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

Date: Thu, 3 Jul 2003 23:27:49 +0000 (UTC)
From: per@hedeland.org (Per Hedeland)
Subject: Re: perl script generates sendmail NOQUEUE: connect from root@localhost
Message-Id: <be2e5l$1h66$4@hedeland.org>

In article <d6888173.0307030358.585caf3c@posting.google.com>
multiverse@hotmail.com (Jhary-a-Conel) writes:
>When this script is run it generates the following output in
>/var/log/maillog:
>
>Jul  3 04:26:45 prod sendmail[8843]: NOQUEUE: connect from
>root@localhost
>Jul  3 04:26:45 prod sendmail[8843]: h63BQjj08843: from=root,
>size=150, class=0, nrcpts=1,
>msgid=<200307031126.h63BQjj08843@www.domain.com>, relay=root@localhost
>Jul  3 04:26:45 prod sendmail[8846]: h63BQjj08843:
>to=admin.report@domain.com, ctladdr=root (0/0), delay=00:00:00,
>xdelay=00:00:00, mailer=local, pri=30150, dsn=2.0.0, stat=Sent
>Jul  3 04:26:45 prod sendmail[8846]: h63BQjj08843: done;
>delay=00:00:00, ntries=1
>
>My research indicates that when a client doesn't close a connection
>properly with Sendmail it throws the NOQUEUE line into the logs. 

You need to redo your research then - the FAQ says:

   Note 1: The significant part of the message isn't the NOQUEUE, but
   the "Null connection from ...". In particular, NOQUEUE isn't an error
   indication, but just a "place-holder" when no queue ID has been
   assigned, typically because message collection hasn't started
   (yet). It can occur in other messages too, and there too the
   significant part is what comes after the NOQUEUE.

>I'd like to eliminate this report message, but have a feeling the
>NOQUEUE message is inconsequential.  When I reduce the logging level,
>the message stops being recorded.  Should I ignore this and get on
>with my life or what?

Right, the message does not occur at the standard/default LogLevel 9:

	if (LogLevel > 9)
	{
		/* log connection information */
		sm_syslog(LOG_INFO, NULL, "connect from %s", authinfo);
	}

By raising the LogLevel from the default, you get more logging
(surprise:-), some of it more or less of a debugging nature - so you're
just getting what you asked for...

--Per Hedeland
per@hedeland.org


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

Date: Thu, 03 Jul 2003 19:35:25 -0400
From: Benjamin Goldberg <ben.goldberg@hotpop.com>
Subject: Re: pipe - non blocking read? (fork/Win32)
Message-Id: <3F04BDBD.9633257@hotpop.com>

Greg Bacon wrote:
[snip]
>         my @ready = $sel->can_read(0);
>         foreach my $fh (@ready) {
[snip]
>                 if (my $input = <$fh>) {

Don't do that.

-- 
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}


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

Date: Fri, 04 Jul 2003 02:18:40 GMT
From: merlyn@stonehenge.com (Randal L. Schwartz)
To: Naran Hirani <N.Hirani@hgmp.mrc.ac.uk>
Subject: Re: renaming badly named files...
Message-Id: <39c7df9bae54406f9216795680083f60@free.teranews.com>

>>>>> "Naran" == Naran Hirani <N.Hirani@hgmp.mrc.ac.uk> writes:

Naran> I am looking for a perl code fragment, or utility that will enable me
Naran> to rename badly named files and/or dir elements to such files, by
Naran> replacing the dubious character with an underscore.  It would nice if
Naran> such a utility worked recursively through unix dirs and also had a
Naran> mode where by it just shows what would be renamed.

"I have a column on that", he says, usually...

  http://www.stonehenge.com/merlyn/LinuxMag/col45.html


-- 
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: 3 Jul 2003 17:58:01 -0700
From: rook_5150@yahoo.com (Bryan Castillo)
Subject: Re: script for unrestricted permutation
Message-Id: <1bff1830.0307031658.57f0b756@posting.google.com>

tiltonj@erols.com (Jay Tilton) wrote in message news:<3f040319.2828824@news.erols.com>...
> weberh@zedat.fu-berlin.de (weberh) wrote:
> 
> : Alright, but it is slow, no?
> 
> It is customary to provide some context by quoting relevant material
> from the article you are replying to.
> 
> recap of bd's code:
> 
>     while($indices[0] < @elements){
>         foreach my $index (@indices) {
>             print "$elements[$index] ";
>         }
>         print "\n";
>         $indices[-1]++;
>         for($_ = $#indices; $_ > 0; $_--){
>             if($indices[$_] >= @elements){
>                 $indices[$_] = 0;
>                 $indices[$_ - 1]++;
>             }
>         }
>     }
> 
> Sure it's slower.  But the idea is readily adapted to give it much
> more flexibility.
> 

I came up with almost the same code BD had last night.  I was
surprised
to see how much faster the eval version is.  It is significantly
faster.
It continues to be faster (exponentially) as you produce larger sets.

I ran a test from 1 to 10 place holders using 7 values.  The eval
version went though most of them pretty easy, once the non-eval
version got to 7 place holders it really started taking time.

You could modify the eval version to be more flexible.  It wouldn't be
too
hard to add callback support instead of printing, or support for
returning the
whole set.  You could actually be more flexible by generating
different
code depending on the parameters.

Although the eval version would be harder to maintain.


(Anyway, the 2nd version is easier to understand and maintain
 but the 1st benefits enough from the speed increase, that I 
 would go with that one.)


> It's essentially a base-n counter, where n is the number of permutable
> items.  By changing it from a counter to a decimal-to-base-n
> converter, it can be used to obtain any arbitrary permutation without
> having to generate the entire set.
> 
>     my($count, @elements) = @ARGV;
>     my $permutation = sub {
>         use integer;
>         my($i) = @_;
>         my @indices = ($elements[0]) x $count;
>         my $c = $count;
>         while($c && $i) {
>             $indices[--$c] = $elements[ $i % @elements ];
>             $i /= @elements;
>         }
>         @indices;
>     };
>     print $permutation->($_), "\n"
>       for 0 .. @elements ** $count -1;


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

Date: 3 Jul 2003 17:56:52 -0700
From: stuseven@hotmail.com (stu7)
Subject: using pipe & perl's ARGV filehandle ?
Message-Id: <d7dd90b0.0307031656.45dad85@posting.google.com>

Uri and Tad seemed frustrated when I asked about...

> perl first.pl | perl second.pl   something, something  ARGV fh ?

   I didn't specify what first.pl or second.pl contain, BE-cause,
 according to what I was told, PERL's built-in function...
 ... the ARGV filehandle... will automatically contain the
 content and/or arguments from the first script in this kind of
 piping situation... in other words, those scripts could contain 
 anything.
   I was told, with no exception, this kind of script-to-script
 data is automatically available via the built-in ARGV function, 
 sort-of like a  @_  

    Can anybody show me an example of this working ?

    For the sake of discussion, first.pl could be:
 
           $a = 4 ; $b = 5 ; $c = ($a + $b) ;

  ...in second.pl, I would want to print $c... or even $a and $b...

            print <> ; ### ?
            print <ARGV> ; ### ?

   Sorry... I'm clueless as to how it might work... I could have
 been lied to, but this is how it was suggested.
   It doesn't make sense to me already, please don't remind me :)


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

Date: Fri, 04 Jul 2003 01:57:57 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: using pipe & perl's ARGV filehandle ?
Message-Id: <x7vfujxdcr.fsf@mail.sysarch.com>

>>>>> "s" == stu7  <stuseven@hotmail.com> writes:

  s> Uri and Tad seemed frustrated when I asked about...
  >> perl first.pl | perl second.pl something, something ARGV fh ?

  s>    I didn't specify what first.pl or second.pl contain, BE-cause,
  s> according to what I was told, PERL's built-in function...  ... the
  s> ARGV filehandle... will automatically contain the content and/or
  s> arguments from the first script in this kind of piping
  s> situation... in other words, those scripts could contain anything.
  s> I was told, with no exception, this kind of script-to-script data
  s> is automatically available via the built-in ARGV function, sort-of
  s> like a @_

who told you this nonsense? 

ARGV is not a function. you call it a handle and then a function.

and it is a special handle only if you use the magic <> operator.

  s>     Can anybody show me an example of this working ?

  s>     For the sake of discussion, first.pl could be:
 
  s>            $a = 4 ; $b = 5 ; $c = ($a + $b) ;

  s>   ...in second.pl, I would want to print $c... or even $a and $b...

huh?

how can one script print vars from another?

you need to learn some perl (and programming) basics.


  s>    Sorry... I'm clueless as to how it might work... I could have
  s> been lied to, but this is how it was suggested.  It doesn't make
  s> sense to me already, please don't remind me :)

you were lied to. and you should get a good perl book like learning
perl.

pipes have nothing to do with variables. pipes are for i/o between
programs and on that pipe there is only raw data, no variables. if you
want to communicate variable type of information on a pipe, you have to
encode it in the writer and decode it in the reader.

uri

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


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

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


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