[25290] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7535 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Dec 19 11:05:46 2004

Date: Sun, 19 Dec 2004 08:05:09 -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           Sun, 19 Dec 2004     Volume: 10 Number: 7535

Today's topics:
    Re: /\bf(?:o(?:o(?:b(?:a(?:r)?)?)?)?)?\b/ (Anno Siegel)
    Re: Consecutive Numbers (Anno Siegel)
    Re: FAQ 5.32: How do I close a file descriptor by numbe <usenet@morrow.me.uk>
        File statistics from web page files <j.b.l.0.2.@.hotmail.com>
    Re: File statistics from web page files <jkeen_via_google@yahoo.com>
    Re: Finding out if another copy of a CGI Perl scripts i <matternc@comcast.net>
    Re: Finding out if another copy of a CGI Perl scripts i <karlUNDERSCOREkramsch@yahooPERIODcom.invalid>
    Re: Finding out if another copy of a CGI Perl scripts i <flavell@ph.gla.ac.uk>
    Re: Finding out if another copy of a CGI Perl scripts i (Anno Siegel)
    Re: Finding out if another copy of a CGI Perl scripts i <karlUNDERSCOREkramsch@yahooPERIODcom.invalid>
    Re: Matt's formail not working outside domain <dave@dave.org.uk>
    Re: Need help with constants and package names. <usenet@morrow.me.uk>
        problem creating string from list <wyzelli@yahoo.com>
    Re: problem creating string from list <noreply@gunnar.cc>
    Re: problem creating string from list <noreply@gunnar.cc>
    Re: problem creating string from list (Anno Siegel)
    Re: Session management for cgi, ldap, oracle? <usenet@morrow.me.uk>
    Re: socket script dies <usenet@morrow.me.uk>
    Re: Some Programing Needed <flavell@ph.gla.ac.uk>
    Re: why the following HereDoc print don't work? <usenet@morrow.me.uk>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 19 Dec 2004 14:44:48 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: /\bf(?:o(?:o(?:b(?:a(?:r)?)?)?)?)?\b/
Message-Id: <cq4450$bvr$1@mamenchi.zrz.TU-Berlin.DE>

Mike  <please@send.replies.to.ng> wrote in comp.lang.perl.misc:
> 
> 
> 
> 
> I want a regexp that will match (as a "whole word") any of the
> (non-empty) prefixes of the word "foobar", i.e. "f", "fo", "foo",
> "foob", etc.  One way to do it is this:
> 
>   /\bf(?:o(?:o(?:b(?:a(?:r)?)?)?)?)?\b/ 
> 
> Yuk.  Is there a better way?

Yuk is in the eye of the beholder.

The regex isn't particularly readable, but it *is* an economical way
to match all possible prefixes, as opposed to the readable but
repetitive

    /\b(?:foobar|fooba|foob|foo|fo|f)\b/

If the pattern is generated by a well-named routine, readability of
the result doesn't matter much:

    sub prefix_pattern {
        my $pat = '';
        # build innermost pattern first
        $pat = "(?:$_$pat)?" for reverse split //, shift;
        $pat;
    }   

    my $re = prefix_pattern( $word);
    print join( ", ", 'X f YY foob ZZZ foobar' =~ /\b$re\b/g), "\n";

This prints a lot of comma-separated empty strings because it also matches
the empty prefix.  The first character is made optional like the rest of
them.  To amend this, treat the first character extra.  Using the same
prefix_pattern():

    my ( $first, $rest) = $word =~ /(.)(.*)/ or die "Word can't be empty";
    my $re = $first . prefix_pattern( $rest);
    print join( ", ", 'X f YY foob ZZZ foobar' =~ /\b$re\b/g), "\n";

Anno


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

Date: 19 Dec 2004 10:29:08 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Consecutive Numbers
Message-Id: <cq3l5k$47r$1@mamenchi.zrz.TU-Berlin.DE>

Abigail  <abigail@abigail.nl> wrote in comp.lang.perl.misc:
> Anno Siegel (anno4000@lublin.zrz.tu-berlin.de) wrote on MMMMCXXVII
> September MCMXCIII in <URL:news:cq1b2q$o4u$1@mamenchi.zrz.TU-Berlin.DE>:
> ??  Matija Papec  <perl@my-header.org> wrote in comp.lang.perl.misc:
> ?? > X-Ftn-To: Anno Siegel 
> ?? > 
> ?? > >> sub is_arithmetic_sequence2 {
> ?? > >>     my $delta = shift;
> ?? > >>     while ( @_ > 1 ) {
> ?? > >>         (shift) + $delta == $_[ 0] or return 0;
> ?? > >
> ?? > >This is arguably wrong.  The Perl interpreter is free to evaluate
> ?? > >subexpressions in any order, so there is no guarantee that shift()
> ?? > >has happened before $_[ 0] is evaluated.  The result of the expression

[...]

> ??  Btw, the problem is worse in languages that have macro capabilities,
> ??  like C.  A macro can hide the fact that a subexpression appears more
> ??  than once.  The standard example is
> ??  
> ??      #define SQUARE( x, y) ((x)*(x))
> ??      int i = 1;
> ??      printf( "%d is not 4\n", SQUARE( ++i));
> ??  
> ??  That looks entirely innocent, yet it prints "6 is not 4".
> 
> Well, the latter is bad because it has a side-effect - not because the
> order of evaluation isn't fully defined. If you replace '++ i' in the
> expression above with a function call that adds 1 to i and then returns
> it, the order of evaluation is fully defined - but it will still print 6.

It's true, the macro problem is only related by association.  I was
rambling.

>    my $qr =  qr/^.+?(;).+?\1|;Just another Perl Hacker;|;.+$/;
>       $qr =~  s/$qr//g;
> print $qr, "\n";

Ah... A quine reproduces itself, including a payload.  This cleans itself
from everything but the payload.  It's an anti-quine.

Anno


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

Date: Sat, 18 Dec 2004 00:03:41 +0000
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: FAQ 5.32: How do I close a file descriptor by number?
Message-Id: <tn8c92-ni9.ln1@osiris.mauzo.dyndns.org>


Quoth Michele Dondi <bik.mido@tiscalinet.it>:
> On Thu, 16 Dec 2004 11:03:00 +0000 (UTC), PerlFAQ Server
> <comdog@panix.com> wrote:
> 
> >        require 'sys/syscall.ph';
> 
> Out of curiosity, is the answer to this question still up to date?

I would have thought POSIX::close would work just as well. Messing
around with syscall is Nasty(TM): I'd rather recommend writing an XS or
Inline::C module (if necessary) than using it.

Ben

-- 
        I must not fear. Fear is the mind-killer. I will face my fear and
        I will let it pass through me. When the fear is gone there will be 
        nothing. Only I will remain.
ben@morrow.me.uk                                          Frank Herbert, 'Dune'


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

Date: Sun, 19 Dec 2004 14:41:22 GMT
From: jbl <j.b.l.0.2.@.hotmail.com>
Subject: File statistics from web page files
Message-Id: <o12bs05bqic3m2385us299j1r5ihkc2js8@4ax.com>

I want to be able to get file statistics from a "friendly" server.
Currently from the browser I see a list of .pdf files.

http://welcome.brochurearchive.com/pdfs  not actual

eg;
Directory handle: Resource id #2 Files: .
 ..
XiGh_II-p4302-c3837-UK-1.pdf
XiGh_II-p4302-c3837-NO-1.pdf
XiGh_II-p4302-c3837-SE-1.pdf
XiGh_II-p4302-c3837-DK-1.pdf

Is there a perl way to get the creation/modification date of the pdf
files without having to download the entire page?

Not asking for someone to code it but just a general idea of how to

Thanks
jbl


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

Date: Sun, 19 Dec 2004 15:37:15 GMT
From: Jim Keenan <jkeen_via_google@yahoo.com>
Subject: Re: File statistics from web page files
Message-Id: <Lehxd.3455$152.507@trndny01>

jbl wrote:
> I want to be able to get file statistics from a "friendly" server.
> Currently from the browser I see a list of .pdf files.
> 
> http://welcome.brochurearchive.com/pdfs  not actual
> 
> 
> Is there a perl way to get the creation/modification date of the pdf
> files without having to download the entire page?
> 

perldoc -f stat

But this assumes you have appropriate permissions to read file/directory 
information on the server.

Jim Keenan


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

Date: Sun, 19 Dec 2004 07:27:24 -0500
From: Chris Mattern <matternc@comcast.net>
Subject: Re: Finding out if another copy of a CGI Perl scripts is running?
Message-Id: <YoSdnYOqqbUw7ljcRVn-oQ@comcast.com>

Alan Mead wrote:

> Star date: Sat, 18 Dec 2004 15:45:03 -0800, Lisa's log:
> 
>> OK, but I do not want the second iteration to wait for a lock I want it
>> to recognize the existance of the previously running version still
>> being active and to exit gracefully.
> 
> exit if ( -x $lockfile );
> 
> '-x' is from memory...

Race condition.  The testing & creation of the lockfile is not an
atomic function.  One could have a situation where program A 
tests for $lockfile's existence, finds it doesn't exist, is
interrupted, and then program B tests for $lockfile's existence,
finds it doesn't exist.  Boom.

Granted, from the problem description is chances this will happen
in the OP's situation is about nil, but one should avoid race
conditions as general good programming practice.  And one can
never be sure when the circumstances surrounding the lock might
change...

The proper way to do it is a lock *directory*, because mkdir
fails if the directory already exists. 

exit if (! mkdir($lockfile));

This tests and acquires the lock in one kernel call.
-- 
             Christopher Mattern

"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"


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

Date: Sun, 19 Dec 2004 14:08:45 +0000 (UTC)
From: KKramsch <karlUNDERSCOREkramsch@yahooPERIODcom.invalid>
Subject: Re: Finding out if another copy of a CGI Perl scripts is running?
Message-Id: <cq421d$ebn$1@reader2.panix.com>

In <1103437288.177230.209620@c13g2000cwb.googlegroups.com> "Lisa" <dlr93612@yahoo.com> writes:

>Here is what I have been trying and it does not work as I expexcted it
>to.

>if(-e "LockFile.txt"){
>print "LockFile already exists",br();
>exit;
>}else{
>if(open("LOCKFILE",">LockFile.txt")){
>print "opening LockFile",br();
>print LOCKFILE "1";
>close LOCKFILE;
>}else{
>die "Can't open LockFile";
>}
>}

>sleep(20)
>unlink("LockFile.txt");

>print "Done",br();
>exit


>If I comment out the sleep and unlink commands,  and let the script end
>without deleting the file, then the next run of the script finds the
>file and exits. However if I leave the sleep unlink in the script and
>run two iterations of the script they both run instead of the second
>one exiting because the first one is sleeping and has not unlinked the
>lock file as I expect it to.

It works fine for me (once I fixed the missing ; after sleep(20)
and defined br):

% ./locking_script.pl & ; sleep 1; ./locking_script.pl &
[3] 9593
opening LockFile
[4] 10126
LockFile already exists
[4]  - done       ./locking_script.pl
% Done

[3]  - done       ./locking_script.pl
%

The printing of "Done" occurs only once.

	Karl

-- 
Sent from a spam-bucket account; I check it once in a blue moon.  If
you still want to e-mail me, cut out the extension from my address,
and make the obvious substitutions on what's left.


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

Date: Sun, 19 Dec 2004 14:32:45 +0000
From: "Alan J. Flavell" <flavell@ph.gla.ac.uk>
Subject: Re: Finding out if another copy of a CGI Perl scripts is running?
Message-Id: <Pine.LNX.4.61.0412191419290.30690@ppepc56.ph.gla.ac.uk>

On Sun, 19 Dec 2004, KKramsch wrote:

[..snip..]

> It works fine for me 

"For some small values of the term 'works' "

The method is fundamentally unsound.  The proper way to do 
locking is based on an /atomic/ operation.

The only alternative - and it's hard, very hard, to be sure you can 
get it right - is some kind of iterative locking procedure.  This one 
had neither.

Merlyn's columns have covered the topic of locking several times: at 
least one of the articles (though I can't put my fingers on the right 
one just now) has covered a way of iteratively trying to get control 
of an exclusive resource - backing-off if the attempt failed - and 
finally reaching a state in which one participant can be confident 
that they have exclusive control of the resource.

http://www.stonehenge.com/merlyn/columns.html

Some of those articles are quite old now and I'm sure the author would 
agree there are some points on which the style could be updated; but 
the fundamentals are sound, and one can learn a lot from them.  
Especially when one's tempted once again to re-invent the wheel :-}


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

Date: 19 Dec 2004 15:02:51 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Finding out if another copy of a CGI Perl scripts is running?
Message-Id: <cq456r$bvr$2@mamenchi.zrz.TU-Berlin.DE>

Alan Mead  <amead@comcast.net> wrote in comp.lang.perl.misc:
> Star date: Sat, 18 Dec 2004 15:45:03 -0800, Lisa's log:
> 
> > OK, but I do not want the second iteration to wait for a lock I want it
> > to recognize the existance of the previously running version still
> > being active and to exit gracefully.
> 
> exit if ( -x $lockfile );
> 
> '-x' is from memory...

Wrong in all respects.  Brian (with capital "B" :) was talking about
locking a file (a safe way of ensuring mutual exclusion), not of
using a lock file, which is an unsafe approximation if done naively,
and still suffers from stale locks if done right.

Also, you remember wrong about "-x", it tests for executability.  Please
don't post information you *know* may be wrong.  Look it up and get it
right.

Anno


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

Date: Sun, 19 Dec 2004 15:07:09 +0000 (UTC)
From: KKramsch <karlUNDERSCOREkramsch@yahooPERIODcom.invalid>
Subject: Re: Finding out if another copy of a CGI Perl scripts is running?
Message-Id: <cq45es$fcb$1@reader2.panix.com>

In <Xns95C41E095AAF9asu1cornelledu@132.236.56.8> "A. Sinan Unur" <1usa@llenroc.ude.invalid> writes:
>Other suggested reading:

>http://tinyurl.com/6q2gc


In this post you propose the following:
 
> use Fcntl qw(:flock);
> 
> sub update {
> 
>   # ...
> 
>   open my $lock, '>', 'lockfile'
>            or die "Cannot open lockfile: $!";
>   flock $lock, LOCK_EX
>            or die "Cannot obtain exclusive lock on lockfile: $!";
> 
>   # Do the updating etc.
> 
> }

One thing that confuses me about this code is that whether flock
succeeds or not, lockfile gets clobbered by the open.  The lock is
"advisory"; it does not block the open.  I think this may be why
the docs use sysopen with O_RDWR instead of open $fh, ">file": 

    use Fcntl;

    # ...

    sysopen my $lock, 'lockfile', O_RDWR|O_CREAT
      or die "Can't open lockfile: $!\n";

    # I suppose the sysopen above could be replaced with
    # open my $lock, '+<lockfile'

    flock $lock, LOCK_EX|LOCK_NB 
      or die "Can't obtain exclusive lock on lockfile: $!\n";

    truncate $lock, 0
      or die "Can't truncate lockfile: $!\n";

    # etc.

    close $lock
      or die "Can't close lockfile: $!\n";

    flock $lock, LOCK_UN
      or die "Can't unlock lockfile: $!\n";



	Karl

-- 
Sent from a spam-bucket account; I check it once in a blue moon.  If
you still want to e-mail me, cut out the extension from my address,
and make the obvious substitutions on what's left.


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

Date: Sun, 19 Dec 2004 09:16:47 +0000
From: Dave Cross <dave@dave.org.uk>
Subject: Re: Matt's formail not working outside domain
Message-Id: <pan.2004.12.19.09.16.47.245967@dave.org.uk>

On Sat, 27 Nov 2004 18:55:23 -0500, Sherm Pendley wrote:

> Michele Dondi wrote:
> 
>> Matt himself is now redirecting people to better replacements which
>> IIRC are available at <http://mms.sourceforge.net>
> 
> Typo. That should be <http://nms.sourceforge.net>.

Or, actually, <http://nms-cgi.sourceforge.net>.

Dave...



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

Date: Fri, 17 Dec 2004 23:13:16 +0000
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Need help with constants and package names.
Message-Id: <cp5c92-ni9.ln1@osiris.mauzo.dyndns.org>


Quoth Brian McCauley <nobull@mail.com>:
> Sherm Pendley wrote:
> > Terry wrote:
> > 
> >> Something I didn't find in the perldoc was how to export a hash using
> >> the 'use constant' pragma. 
<snip>
> 
> It works just fine if you pay proper attension to run-time v.
> compile-time issues.
> 
> > I haven't found a way to do that either - and believe me I've tried.
> 
> BEGIN {
>    my %constants = (
>     one => 1 ,
>     two => 2 ,
>     # ...
>    );
>    require constants;
>    import constants %constants;
>    push @EXPORT => keys %constants;
> }

That BEGIN is unnecessary if there is no other code in the file: the
require is happening at BEGIN time anyway, and before import is called.

If there *is* other code in the file, it won't have access to the
constants.

Ben

-- 
don't get my sympathy hanging out the 15th floor. you've changed the locks 3
times, he still comes reeling though the door, and soon he'll get to you, teach
you how to get to purest hell. you do it to yourself and that's what really
hurts is you do it to yourself just you, you and noone else ** ben@morrow.me.uk


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

Date: Sun, 19 Dec 2004 09:09:49 GMT
From: "Peter Wyzl" <wyzelli@yahoo.com>
Subject: problem creating string from list
Message-Id: <xzbxd.78781$K7.42114@news-server.bigpond.net.au>

I have been playing around with this for a while now and am clearly missing 
something...

__SAMPLE__

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

my $word = 'foobar';

my $string = substr $word,0,1;
$string = join '|', $string, substr $word,0,$_ for 2..length $word;

print $string;

__END SAMPLE__

prints 'f|fo|foo|foob|fooba|foobar' (sans quotes)

But!

changing to:

$string = join '|', substr$word,0,$_ for 1..length $word;

prints 'foobar'

Why is this discarding all but the last value from the list?

Whilst this:

$string = join '|', substr $word,0,1, substr$word,0,$_ for 2..length $word;

prints 'f'

why is this discarding all but the first value from the list?

Even more puzzling to me is why these are syntax errors:

$string = join '|', (substr $word,0,$_ for 1..length $word);
$string = join '|', [substr $word,0,$_ for (1..length $word)];

(and several other variants with braces)

Specifically I don't understand what the scalar variable $string is doing in 
the first version that makes this work.  I played with parens trying to 
force list context but that is when I hit the syntax errors.

$string = join '|', (substr $word,0,$_ for (1..length $word));

causes the error:
syntax error at test.pl line 7, near "$_ for "

Scratching my head with that one...

-- 
Confused Wyzelli 




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

Date: Sun, 19 Dec 2004 10:39:22 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: problem creating string from list
Message-Id: <32l0vsF3kuajsU1@individual.net>

Peter Wyzl wrote:
> I have been playing around with this for a while now and am clearly missing 
> something...
> 
> __SAMPLE__
> 
> #!/usr/bin/perl -w
> use strict;
> 
> my $word = 'foobar';
> 
> my $string = substr $word,0,1;
> $string = join '|', $string, substr $word,0,$_ for 2..length $word;
> 
> print $string;
> 
> __END SAMPLE__
> 
> prints 'f|fo|foo|foob|fooba|foobar' (sans quotes)
> 
> But!
> 
> changing to:
> 
> $string = join '|', substr$word,0,$_ for 1..length $word;
> 
> prints 'foobar'
> 
> Why is this discarding all but the last value from the list?

<snip>

To me it's more surprising that your first expression works. Use the 
map() function instead:

     my $string = join '|', map { substr $word,0,$_ } 1..length $word;

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: Sun, 19 Dec 2004 13:49:55 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: problem creating string from list
Message-Id: <32lc8oF3o0k30U1@individual.net>

Peter Wyzl wrote:
> I have been playing around with this for a while now and am clearly missing 
> something...
> 
> __SAMPLE__
> 
> #!/usr/bin/perl -w
> use strict;
> 
> my $word = 'foobar';
> 
> my $string = substr $word,0,1;
> $string = join '|', $string, substr $word,0,$_ for 2..length $word;
> 
> print $string;

You may be missing that what's happening can be written as:

     my $string = substr $word,0,1;
     for ( 2..length $word ) {
         $string = join '|', $string, substr $word,0,$_;
     }

or maybe as:

     my $string = substr $word,0,1;
     $string .= '|' . substr $word,0,$_ for 2..length $word;

> $string = join '|', substr$word,0,$_ for 1..length $word;
> 
> prints 'foobar'
> 
> Why is this discarding all but the last value from the list?

Write it like this, and it gets obvious:

     my $string;
     for ( 1..length $word ) {
         $string = join '|', substr $word,0,$_;
     }

But, as I said in another post, use map() instead.

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: 19 Dec 2004 13:46:05 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: problem creating string from list
Message-Id: <cq40mt$a89$1@mamenchi.zrz.TU-Berlin.DE>

Peter Wyzl <wyzelli@yahoo.com> wrote in comp.lang.perl.misc:
> I have been playing around with this for a while now and am clearly missing 
> something...

It seems to me you are conflating the actions of "map" and "for".

> __SAMPLE__
> 
> #!/usr/bin/perl -w
> use strict;
> 
> my $word = 'foobar';
> 
> my $string = substr $word,0,1;
> $string = join '|', $string, substr $word,0,$_ for 2..length $word;
> 
> print $string;
> 
> __END SAMPLE__
> 
> prints 'f|fo|foo|foob|fooba|foobar' (sans quotes)

You appear to think that join() puts together the substrings in one
go, but it doesn't.  join() is called repeatedly and each time only
joins two elements (and one '/'): the string constructed so far, and
one new substring.  It gets clearer when join() is written with
parentheses like this:

    my $string = substr $word,0,1;
    $string = join( '|', $string, substr $word,0,$_) for 2..length $word;

Join is called with three arguments each time.  You want "map" to
construct the list of substrings and join them in one go:

   my $string = join '|', $string, map substr( $word,0,$_), 1 ..length $word;

Now you don't have to initialize the string anymore, "map" (starting at 1
now) produces all the parts, and "join" puts them all together.

> But!
> 
> changing to:
> 
> $string = join '|', substr$word,0,$_ for 1..length $word;
> 
> prints 'foobar'
> 
> Why is this discarding all but the last value from the list?

It assigns to $string length($string) times, each time overwriting the
previous value.  "join", being called with two arguments, is really a
no-op there.  Only the final assignment of substr( $word, 0, length $word)
remains.

> Whilst this:
> 
> $string = join '|', substr $word,0,1, substr$word,0,$_ for 2..length $word;
> 
> prints 'f'
> 
> why is this discarding all but the first value from the list?

Again, the list you think it works on isn't there, you have multiple
assignments.  Here it's the four-argument form of substr() that is
fooling you.  The line is parsed as

    $string = join( '|', substr( $word,0,1, substr($word,0,$_))), "\n") for
        2..length $word;

Like before, "join" does nothing.  Four-arg substr() returns the (unchanged)
substring described by the first three arguments, and replaces it by the
fourth argument.  That means, $word is changed around in the loop.  However,
the first character of $word remains "f", and so $string is set to "f"
five times, and that's what it is after the loop.

What a mess...

> Even more puzzling to me is why these are syntax errors:
>
> $string = join '|', (substr $word,0,$_ for 1..length $word);
> $string = join '|', [substr $word,0,$_ for (1..length $word)];

"for" is a *statement modifier*.  It doesn't have a (list) value
like map.  Not even the modified statement has a value, it is just
executed multiple times, the way "for" describes.  So what should
be the third argument of substr() is a (modified) statement, not
an expression.  That is no valid syntax.

You ought to acquaint yourself with some basic debugging techniques
that help finding out what's going on when you get unexpected results.
The most basic one is printing intermediate results.  In your first
example

    my $string = substr $word,0,1;
    $string = join '|', $string, substr $word,0,$_ for 2..length $word;

simply printing the result of each assignment

    print( $string = join '|', $string, substr $word,0,$_, "\n") for
        2..length $word;

would have told you a lot.  The same goes for the other two.

Another technique is (re-)reading the documentation of the functions
you are using.  The four-argument form of substr() that tripped you
up is sneaky, but reading about it again might have alerted you.

The last advice is repeated here often, but that's because it is often
neglected.

Anno


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

Date: Fri, 17 Dec 2004 23:43:14 +0000
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Session management for cgi, ldap, oracle?
Message-Id: <ih7c92-ni9.ln1@osiris.mauzo.dyndns.org>


Quoth Christopher Nehren <apeiron+usenet@coitusmentis.info>:
> -----BEGIN xxx SIGNED MESSAGE-----

DON'T do that.

> Apparently you missed the large thread about Solaris and Perl. It was
> mentioned numerous times that the 5.005 version of Perl shipped with
> Solaris is required for compatability with the Perl scripts that ship
> with Solaris.

Apparently *you* missed the bit that said that /usr/bin/perl on said Sun
boxen is a symlink to /use/perl5/bin/perl or some such, and all the
system scripts that need that perl use the latter path directly, so you
can install a new perl anywhere sensible and even symlink it from
/usr/bin/perl and everything will work Just Fine (TM).

Ben

-- 
Like all men in Babylon I have been a proconsul; like all, a slave ... During
one lunar year, I have been declared invisible; I shrieked and was not heard,
I stole my bread and was not decapitated.
~ ben@morrow.me.uk ~                   Jorge Luis Borges, 'The Babylon Lottery'


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

Date: Fri, 17 Dec 2004 23:21:16 +0000
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: socket script dies
Message-Id: <c86c92-ni9.ln1@osiris.mauzo.dyndns.org>


Quoth Larry <dontmewithme@got.it>:
> 
> eureka!
> 
> it seems like i've sorted it out!

Do you usually talk to yourself? :)

> at first, I tried this:
> 
> #!/perl
> 
> @nomi = keys(%SIG);
> for my $nomesig (@nomi) {$SIG{$nomesig} = 'IGNORE';}

YEUCH! You'll ignore all sorts of signals that you really shouldn't
(like SIGTERM, for example).

> but i found that this would be better:
> 
> #!/perl
> 
> sub handleruniversale
> {
>   print "\ngot a signal $_[0]\n";
>   $SIG{$_[0]} = \&handleruniversale;
> }
> 
> @nomi = keys(%SIG);
> for my $nomesig (@nomi) {$SIG{$nomesig} = \&handleruniversale;}

Hmmm... this is little better, except for testing.

> so i discovered that i gotta put this on my script:
> 
> local $SIG{NUM13} = 'IGNORE';
> 
> what the hell is $SIG{NUM13} ???

On my system (linux 2.6/i686) signal number 13 is SIGPIPE, so it looks
like when your perl was built it couldn't get hold of the signal names.
I would suggest rebuilding perl, and making sure you watch for any
errors of that sort.

Ben

-- 
Heracles: Vulture! Here's a titbit for you / A few dried molecules of the gall
   From the liver of a friend of yours. / Excuse the arrow but I have no spoon.
(Ted Hughes,        [ Heracles shoots Vulture with arrow. Vulture bursts into ]
 /Alcestis/)        [ flame, and falls out of sight. ]         ben@morrow.me.uk


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

Date: Sun, 19 Dec 2004 11:44:53 +0000
From: "Alan J. Flavell" <flavell@ph.gla.ac.uk>
Subject: Re: Some Programing Needed
Message-Id: <Pine.LNX.4.61.0412191141370.30655@ppepc56.ph.gla.ac.uk>

On Sun, 19 Dec 2004, Joe Smith wrote:

> Murray J wrote:

[yet another copy of the question already seen multiposted in some
c.i.w.a.* groups]

> That's pretty trivial.  What have you tried?

The subject line looked like a job offer to me.  Not a promising 
start.


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

Date: Fri, 17 Dec 2004 22:08:58 +0000
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: why the following HereDoc print don't work?
Message-Id: <q02c92-8n8.ln1@osiris.mauzo.dyndns.org>


Quoth Sherm Pendley <spamtrap@dot-app.org>:
> Ben Morrow wrote:
> 
> > No, Solution 1: get a real text editor.
> > 
> > Solution 2: persuade the one you've got to create a proper text file by
> > apparently putting a blank line on the end.
> 
> Are you seriously suggesting that Perl *should* refuse to run a file, 
> simply because the file doesn't end with a blank line?

*IT ISN'T A BLANK LINE*. The "\n" is the end of the line.

> That's ridiculous 
> - if I believed that whitespace-as-syntax nonsense, I'd be using Python.

This has nothing to do with Perl (so I shall not continue the discussion
any further). It has to do with what is, and what isn't, a text file.

Ben

-- 
   If you put all the prophets,   |   You'd have so much more reason
   Mystics and saints             |   Than ever was born
   In one room together,          |   Out of all of the conflicts of time.
ben@morrow.me.uk                                    The Levellers, 'Believers'


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

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.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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


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