[25598] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7842 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Mar 1 09:05:42 2005

Date: Tue, 1 Mar 2005 06:05:23 -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           Tue, 1 Mar 2005     Volume: 10 Number: 7842

Today's topics:
        Class::Date <alexj@floor.ch>
    Re: Class::Date <nobull@mail.com>
    Re: Encoding "deflate" -- how to handle? [WWW, client-s <nobull@mail.com>
    Re: How to tell if a subroutine arg is a constant <nobull@mail.com>
        perl and blobs <jmccloughlin@[remove this]hotmail.com>
    Re: perl and blobs <phaylon@dunkelheit.at>
    Re: Perl help <nobull@mail.com>
    Re: Perl help <tadmc@augustmail.com>
        perl problem with select and non-blocking sysread from  (john)
    Re: perl problem with select and non-blocking sysread f <nobull@mail.com>
    Re: Questions about Perl for Windows <nobull@mail.com>
    Re: Questions about Perl for Windows <bart.lateur@pandora.be>
    Re: Regexp small question <nobull@mail.com>
    Re: Regexp small question <bernard.el-haginDODGE_THIS@lido-tech.net>
    Re: Regexp small question (Anno Siegel)
    Re: Regexp small question <do-not-use@invalid.net>
    Re: Regexp small question <nobull@mail.com>
    Re: Regexp small question <nobull@mail.com>
    Re: webpage <noreply@gunnar.cc>
    Re: where is my magic (XS related) <nobull@mail.com>
    Re: where is my magic (XS related) <joe+usenet@sunstarsys.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 01 Mar 2005 12:25:07 +0100
From: Alexandre Jaquet <alexj@floor.ch>
Subject: Class::Date
Message-Id: <d01jed$ck9$1@news.hispeed.ch>

Hi again, I can't understand why when I do the following code :

sub getTime {
	
	my $date = new Class::Date ();
	$Class::Date::DATE_FORMAT="%H%M%S%X%Y";
	warn "date hour test ->".now;
	$date = now;
	return $date;
}

I got the following output :
date hour test ->12033612:03:362005

I'm trying to get 12:03:362005

My second question is why when I calculate the difference between two 
dates I only got the difference :

sub differenceBetweenHour {
	my $time_start = shift || '';
	my $time_end = shift || '';
	$Class::Date::DATE_FORMAT="%H%M%S%X%Y";
	my $result = $time_end - $time_start;
	warn "test minus $result";
	return $result;

}

I got : test minus 1 (it doesn't calculte difference between miilisecond)

thx


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

Date: Tue, 01 Mar 2005 12:30:56 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Class::Date
Message-Id: <d01mvt$c8d$1@sun3.bham.ac.uk>



Alexandre Jaquet wrote:

> Hi again, I can't understand why when I do the following code :
> 
> sub getTime {
>     
>     my $date = new Class::Date ();
>     $Class::Date::DATE_FORMAT="%H%M%S%X%Y";
>     warn "date hour test ->".now;
>     $date = now;
>     return $date;
> }
> 
> I got the following output :
> date hour test ->12033612:03:362005

That's what to asked for.  Hours, minutes, seconds, then the full time 
again.

> I'm trying to get 12:03:362005

Then remove from your DATE_FORMAT the extra leading guff that generates 
the '120336'.

> 
> My second question is why when I calculate the difference between two 
> dates I only got the difference :
> 
> sub differenceBetweenHour {
>     my $time_start = shift || '';
>     my $time_end = shift || '';
>     $Class::Date::DATE_FORMAT="%H%M%S%X%Y";
>     my $result = $time_end - $time_start;
>     warn "test minus $result";
>     return $result;
> 
> }
> 
> I got : test minus 1 (it doesn't calculte difference between miilisecond)

Please produce a minmal but complete script to illustrate your point.

What do you think is the purpose of the || '' in the above code?   If 
you don't think it has any purpose (I don't think it has any) then 
remove it.  Remember always write less code unless this would make your 
code less readable.

Note: if you manipulate globals inside subroutines then you should 
usually use local().  Not that I can understand why you manipulate 
$Class::Date::DATE_FORMAT at all since nothing in that subroutine 
involves the stringification of Class::Data objects.



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

Date: Tue, 01 Mar 2005 11:46:07 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Encoding "deflate" -- how to handle? [WWW, client-side]
Message-Id: <d01kbs$b4e$1@sun3.bham.ac.uk>

Maciej Pilichowski wrote:

>   I am fetching some WWW pages via LWP::UserAgent with Accept-Encoding
> set to "gzip, deflate". When the page is uncompressed
> /content_encoding not defined/ I just get the content, when the
> content_encoding is set to "gzip" I use Compress::Zlib::memGunzip, but
> what should I do when content_encoding is set to "deflate"?
>   I tried to use "uncompress" method but it didn't work.
> 
>   Any ideas?

The Alpha version of the next generation version (which handles 
Content-encoding for you) uses Compress::Zlib.

http://search.cpan.org/src/GAAS/LWPng-alpha-0.24/lib/LWP/Sink/deflate.pm



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

Date: Tue, 01 Mar 2005 13:06:40 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: How to tell if a subroutine arg is a constant
Message-Id: <d01p2r$d2t$2@sun3.bham.ac.uk>



Mintcake wrote:

> If the caller wanted to pass -abc as a variable (as in your example)
> then it wold be treated as such.  What would not be allowed is if the
> caller did not want the -abc to to be treated as a special case - in
> which case simply not accidently passing -abc as a literal should do
> the trick.  What I'm saying is that -abc would only be treated as a
> special case if it was coded as a literal - and that is entirely under
> the programmers control.

Yeah, but it's still a real ugly API.



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

Date: Tue, 1 Mar 2005 11:36:38 -0000
From: "Sokar" <jmccloughlin@[remove this]hotmail.com>
Subject: perl and blobs
Message-Id: <38j2e6F5p7l8qU1@individual.net>

Hello,

I have a perl script that needs to generate an e-mail every day.  What it
does it connects to a database and reads in a stored jpg which was in a blob
field to a variable called $pic

What I need to be able to do is e-mail this variable as a jpg to a person.

Does anyone know how I can do this without actually creating a .jpg file on
the server?

Thanks and regards




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

Date: Tue, 01 Mar 2005 12:44:24 +0100
From: phaylon <phaylon@dunkelheit.at>
Subject: Re: perl and blobs
Message-Id: <pan.2005.03.01.11.44.24.777167@dunkelheit.at>

Sokar wrote:

> Does anyone know how I can do this without actually creating a .jpg file
> on the server?

Search CPAN for MIME, the first (MIME::Tools) seems to be what you're
looking for.

-- 
http://www.dunkelheit.at/
thou shallst fear...



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

Date: Tue, 01 Mar 2005 12:14:35 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Perl help
Message-Id: <d01m18$bmm$1@sun3.bham.ac.uk>

Mukesh wrote:

> Subject: Perl help

Please put the subject of your post in the Subject of your post.

>  $host=`hostname`
> $date=`date +%b%d%g`
> $logdir="$LOGBASEDIR/$date/$host"
> i have set the logdir like this but it is not printing the date & host but just
> displaying the host & date variables.

That statement makes no sense.

And as Anno points out even if we try to guess what it means, any 
possible interpretation must refer to some other code since the code you 
post would have no observable behaviour.

Hint: Remember that `` returns the _whole_ output of the command, 
including any control characters, like say, a newline at the end.



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

Date: Tue, 1 Mar 2005 07:13:12 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Perl help
Message-Id: <slrnd28qj8.66n.tadmc@magna.augustmail.com>

Mukesh <mukesh.d.tupe@gmail.com> wrote:

> Subject: Perl help


Please put the subject of your article in the Subject of your article.

There are a hundred messages a day here, nearly *all* of
them wanting Perl help.

Your subject contains no useful information nor does it indicate
what your article is about.

Have you seen the Posting Guidelines that are posted here frequently?


> $host=`hostname`


Syntax error, no semicolon.

We must see the *actual code* if we are to debug the code!

You should copy/paste working code into your article.

Have you seen the Posting Guidelines that are posted here frequently?


> $date=`date +%b%d%g`


To do that in native Perl instead of shelling out:

   perldoc -f localtime


> $logdir="$LOGBASEDIR/$date/$host"
> i have set the logdir like this but it is not printing 


Of course it isn't, there are no print() statements in your code!

You must have some statements in your code that generate output
before you will see any output from your program.


> the date & host but just
> displaying the host & date variables.


Huh?

It is not "printing" them, but it *is* "displaying" them?

What is the difference?


> how to set them.


How to set what?

How to set the hostname or how to set the $host variable?

How to set the date or how to set the $date variable?


> Please help me.


Help us help you by giving us what we need to help you, namely
real code that we can run that duplicates the problem.

You will eventually also need to know about:

   perldoc -f chomp


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


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

Date: 1 Mar 2005 03:33:54 -0800
From: lqueryvg@yahoo.com (john)
Subject: perl problem with select and non-blocking sysread from multiple pipes
Message-Id: <9c8511e0.0503010333.464f5663@posting.google.com>

select() fails with "Bad file number".
I think that the children are dieing before
the output becomes available.

I'm trying to write a program which forks multiple children and reads
their output asynchronously.  The children could take some time to
produce their output and it could arrive in fits and spurts, so I
don't want to block on any individual child; instead I want to read
whatever data each child has available (up to a buffer limit) and then
move on to the next child.

To simulate this behaviour, the children in the testcase below each
produce output, sleep, produce more output, sleep then produce final
output before exiting.  If the sleep is set to 1 second for all
children, then the testcase sometimes finishes successfully, but if
the sleep is set to longer, or variable lengths of time (as below),
then it select will fail with a "Bad file number".

Example output:

 ./testcase   
parent: startTask(), task 1, pid=21348
parent: startTask(), task 2, pid=12538
parent: startTask(), task 3, pid=26482
parent: startTask(), task 4, pid=28482
parent: startTask(), task 5, pid=29770
parent: pollForOutput(), nfound=4
OUTPUT(task 4): (fileno=6) first sleep 4...
OUTPUT(task 1): (fileno=3) first sleep 1...
OUTPUT(task 3): (fileno=5) first sleep 3...
OUTPUT(task 2): (fileno=4) first sleep 2...
parent: pollForOutput(), nfound=3
OUTPUT(task 1): (fileno=3) second sleep 1...
OUTPUT(task 1): (fileno=3) finished
OUTPUT(task 2): (fileno=4) second sleep 2...
OUTPUT(task 5): (fileno=7) first sleep 5...
parent: pollForOutput(), nfound=4
OUTPUT(task 4): (fileno=6) second sleep 4...
OUTPUT(task 1): (fileno=3)eof
parent: closing reader for task 1
OUTPUT(task 3): (fileno=5) second sleep 3...
OUTPUT(task 2): (fileno=4) finished
select: Bad file number at testcase line 66.

From the example above, you can see that the program didn't get to
read all of the child output before select() fails. I suspect that the
children are dieing before their output can be captured by the parent.

Does anyone have any idea why this is happening and how I can prevent
it ? I'm running out of ideas.

I've reproduced the problem on the following platforms:

AIX 5.3, This is perl, v5.8.2 built for aix-thread-multi
Linux Red Hat 2.4.21-4.ELsmp, This is perl, v5.8.0 built for
i386-linux-thread-multi
SunOS 5.8, This is perl, version 5.005_03 built for sun4-solaris
  # Need to put no strict 'refs'; at top of file on Solaris.


Testcase is as follows:

#!/usr/bin/perl

use strict;
use IO;

my $eofsFound = 0;
my $eofsExpected = 5;
my $taskNum = 0;

my $readBits = '';      # "bitlist" of parent reader filehandles
my($fh) = ('fh0000');   # indirect filehandle names, yuk
my %readers;            # store parent reader for each task

sub startTask() {

  $taskNum++;

  $readers{$taskNum} = $fh++;           # parent reader for this task
  my $cw = $fh++;                       # child write filehandle
  {
    no strict 'refs';
    pipe($readers{$taskNum}, $cw) or die 'pr/cw pipe';
  }

  my $pid;
  if ($pid = fork) {

    # Parent

    print "parent: startTask(), task $taskNum, pid=$pid\n";
    close $cw;                          # close child writer
#    $readers{$taskNum}->blocking(0);   # stop sysread() from blocking
    vec($readBits, fileno($readers{$taskNum}), 1) = 1;

  } elsif ($pid ne undef) {

    # Child

    close $readers{$taskNum};   # close parent reader
    open(STDOUT, ">&$cw") or die "STDOUT open: $!";
    STDOUT->autoflush(1);

    my $sleep = $taskNum;       # set this to 1 and it'll probably
work

    print "first sleep $sleep...\n";
    select(undef, undef, undef, $sleep);

    print "second sleep $sleep...\n";
    select(undef, undef, undef, $sleep);

    print "finished\n";
    close(STDOUT);
    exit(0);

  } else {
    die 'fork failed: $!';
  }
}

sub pollForOutput {

  my($rbits, $nfound); 

  $nfound = select($rbits = $readBits,undef,undef,2);
  if ($nfound == -1) {
    die "select: $!";
  }
  print "parent: pollForOutput(), nfound=$nfound\n";
  return if $nfound == 0;

  my @task_list = keys %readers;

  # Work through bitmask to see which filehandles are ready.
  NEXT_FH:
  while ($nfound > 0) { 

    my $taskNum = shift @task_list; 
    my $fh = $readers{$taskNum}; 

    if (vec($rbits, fileno($fh),1) == 0){ 
      # if no incoming data from this client
        next NEXT_FH; 
    } 
    $nfound--; 

    # parent's read filehandle

    my $buf;
    my $n = sysread($fh, $buf, 1024);
    if ($n > 0) {
      chomp $buf;
      my @lines = split(/\n/, $buf);
      foreach my $line (@lines) {
        print "OUTPUT(task $taskNum): (fileno=" . fileno($fh) . ")
$line\n";
      }
    }
    if ($n == 0) {
      $eofsFound++;
      print "OUTPUT(task $taskNum): (fileno=" . fileno($fh) .
")eof\n";
      print "parent: closing reader for task $taskNum\n";
      close($fh) or die "close failed: $!";
      vec($readBits, fileno($fh), 1) = 0;       # select() no longer
interested in this fh
    }
  }
}

sub main {

  startTask();
  startTask();
  startTask();
  startTask();
  startTask();

  while ($eofsFound < $eofsExpected) {
    &pollForOutput();
    sleep 2
  }

  print "Finished\n";
}

main();


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

Date: Tue, 01 Mar 2005 12:50:36 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: perl problem with select and non-blocking sysread from multiple pipes
Message-Id: <d01o4p$cpv$1@sun3.bham.ac.uk>



john wrote:

> select() fails with "Bad file number".
> I think that the children are dieing before
> the output becomes available.

I do not think that should cause this problem.

> 
> I'm trying to write a program which forks multiple children and reads
> their output asynchronously.  The children could take some time to
> produce their output and it could arrive in fits and spurts, so I
> don't want to block on any individual child; instead I want to read
> whatever data each child has available (up to a buffer limit) and then
> move on to the next child.
> 
> To simulate this behaviour, the children in the testcase below each
> produce output, sleep, produce more output, sleep then produce final
> output before exiting.  If the sleep is set to 1 second for all
> children, then the testcase sometimes finishes successfully, but if
> the sleep is set to longer, or variable lengths of time (as below),
> then it select will fail with a "Bad file number".
> 
> Example output:
> 
> ./testcase   
> parent: startTask(), task 1, pid=21348
> parent: startTask(), task 2, pid=12538
> parent: startTask(), task 3, pid=26482
> parent: startTask(), task 4, pid=28482
> parent: startTask(), task 5, pid=29770
> parent: pollForOutput(), nfound=4
> OUTPUT(task 4): (fileno=6) first sleep 4...
> OUTPUT(task 1): (fileno=3) first sleep 1...
> OUTPUT(task 3): (fileno=5) first sleep 3...
> OUTPUT(task 2): (fileno=4) first sleep 2...
> parent: pollForOutput(), nfound=3
> OUTPUT(task 1): (fileno=3) second sleep 1...
> OUTPUT(task 1): (fileno=3) finished
> OUTPUT(task 2): (fileno=4) second sleep 2...
> OUTPUT(task 5): (fileno=7) first sleep 5...
> parent: pollForOutput(), nfound=4
> OUTPUT(task 4): (fileno=6) second sleep 4...
> OUTPUT(task 1): (fileno=3)eof
> parent: closing reader for task 1
> OUTPUT(task 3): (fileno=5) second sleep 3...
> OUTPUT(task 2): (fileno=4) finished
> select: Bad file number at testcase line 66.
> 
> From the example above, you can see that the program didn't get to
> read all of the child output before select() fails. I suspect that the
> children are dieing before their output can be captured by the parent.
> 
> Does anyone have any idea why this is happening and how I can prevent
> it ? I'm running out of ideas.
> 
> I've reproduced the problem on the following platforms:
> 
> AIX 5.3, This is perl, v5.8.2 built for aix-thread-multi
> Linux Red Hat 2.4.21-4.ELsmp, This is perl, v5.8.0 built for
> i386-linux-thread-multi
> SunOS 5.8, This is perl, version 5.005_03 built for sun4-solaris
>   # Need to put no strict 'refs'; at top of file on Solaris.
> 
> 
> Testcase is as follows:
> 
> #!/usr/bin/perl
> 
> use strict;

Consider warnings too.

> use IO;
> 
> my $eofsFound = 0;
> my $eofsExpected = 5;
> my $taskNum = 0;
> 
> my $readBits = '';      # "bitlist" of parent reader filehandles
> my($fh) = ('fh0000');   # indirect filehandle names, yuk

Yes, yuk - this is not necessary in 5.6.1 and later - is compatability 
with earlier Perl really needed?

> my %readers;            # store parent reader for each task
> 
> sub startTask() {
> 
>   $taskNum++;
> 
>   $readers{$taskNum} = $fh++;           # parent reader for this task
>   my $cw = $fh++;                       # child write filehandle
>   {
>     no strict 'refs';
>     pipe($readers{$taskNum}, $cw) or die 'pr/cw pipe';
>   }

The above is more simply:

sub startTask() {
      pipe($readers{++$taskNum}, my $cw) or die 'pr/cw pipe';

>       close($fh) or die "close failed: $!";
>       vec($readBits, fileno($fh), 1) = 0;

What are you expecting fileno() to return for a filehandle that has been 
close()d?  Write a small script to test this expectation :-)



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

Date: Tue, 01 Mar 2005 12:01:36 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Questions about Perl for Windows
Message-Id: <d01l8s$bdh$1@sun3.bham.ac.uk>

al2048@aol.com wrote:

 > Newsgroup: comp.lang.perl, [ ...]

I suggest you break into the office of your NNTP admin and remove 
his/her skeleton.  The newsgroup comp.lang.perl has not existed since 
sometime in the last millenium.

> I am running Windows Millennium Edition on a Pentium 4, 1400 MHz
> computer from Gateway.
> 
> If I download IndigoPerl at the site
> http://www.indigostar.com/indigoperl.htm ,
> will I get perl AND the apache web server in one download?
> 
> How reliable is the above download?

I stopped using Indigo and went back to ActiveState because Indigo was 
not shipping an Apache1.x+mod_perl1+perl5.8.x bundle.

Apache2+mod_perl2 (Indigo or not) crashes periodically on Win32 and 
although it does an auto restart this takes quite literally several 
minutes of CPU thrashing.

Note: All the above is based on observations made a few months ago. 
Things could have changed.

I currently use Apache1 + mod_perl1 + ActiveState Perl5.8.x on Win32 
boxes.  (And various conbination including Apache2+mod_perl2+perl5.8.x 
on Unix).



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

Date: Tue, 01 Mar 2005 12:16:33 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: Questions about Perl for Windows
Message-Id: <t0n821hsqar9g4ro9v5ti441o7n1dn7p9b@4ax.com>

al2048@aol.com wrote:

>If I download IndigoPerl at the site
>http://www.indigostar.com/indigoperl.htm ,
>will I get perl AND the apache web server in one download?

Yes. And mod_perl too, in one go.

>How reliable is the above download?

Good.

>If I download ActivePerl at the site
>http://www.activestate.com/Products/ActivePerl/ ,
>will I have to download Apache in a separate download?

Yes.

>Is ActivePerl reliable?

Yes. ActivePerl is pretty much *the* perl for Windows... though
technically, it and Indigoperl are virtually identical. Precompiled
modules for ActivePerl (AKA PPM distributions) will work just as well
for for both, too. The main difference between the two is what comes
with it for modules, and the module installation script itself that
comes with it. Each has a custom written script, comletely different
from that of the other.

>Also, at my job, I will have the Unix operating system. If I write a
>Perl program on Unix, will this program run on
>IndigoPerl or ActivePerl on Windows Millennium Edition?

Mostly, yes. It depends on what commands you use.

-- 
	Bart.


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

Date: Tue, 01 Mar 2005 12:06:16 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Regexp small question
Message-Id: <d01lhk$bdh$2@sun3.bham.ac.uk>

Bernard El-Hagin wrote:

> if ($str =~ m/^[\w.-]+$/) {

That works but it's also a common idiom to simplify this by inverting 
the char-class and the condition.

  if ($str !~ /[^\w.-]/) {




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

Date: Tue, 1 Mar 2005 13:32:21 +0100
From: "Bernard El-Hagin" <bernard.el-haginDODGE_THIS@lido-tech.net>
Subject: Re: Regexp small question
Message-Id: <Xns960C89B9FD62elhber1lidotechnet@62.89.127.66>

Brian McCauley <nobull@mail.com> wrote:

> Bernard El-Hagin wrote:
> 
>> if ($str =~ m/^[\w.-]+$/) {
> 
> That works but it's also a common idiom to simplify this by
> inverting the char-class and the condition.
> 
>   if ($str !~ /[^\w.-]/) {


Really? That's a common idiom? Personally, I that is absolutely horrid. 
I would *never* use it and I most certainly wouldn't call it a 
simplification. I guess it's a matter of what one is used to, but 
inverting *two* things to get a result one get get without inverting 
*any*thing seems...perverse to me. :-)


-- 
Cheers,
Bernard


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

Date: 1 Mar 2005 12:51:29 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Regexp small question
Message-Id: <d01ogh$fbe$2@mamenchi.zrz.TU-Berlin.DE>

Bernard El-Hagin <bernard.el-haginDODGE_THIS@lido-tech.net> wrote in comp.lang.perl.misc:
> Brian McCauley <nobull@mail.com> wrote:
> 
> > Bernard El-Hagin wrote:
> > 
> >> if ($str =~ m/^[\w.-]+$/) {
> > 
> > That works but it's also a common idiom to simplify this by
> > inverting the char-class and the condition.
> > 
> >   if ($str !~ /[^\w.-]/) {
> 
> 
> Really? That's a common idiom? Personally, I that is absolutely horrid. 
> I would *never* use it and I most certainly wouldn't call it a 
> simplification. I guess it's a matter of what one is used to, but 
> inverting *two* things to get a result one get get without inverting 
> *any*thing seems...perverse to me. :-)

I agree with brian here (hey, it happens :).  I find it perfectly natural
to go from "consists entirely of ..." to "contains nothing outside of ...".  
Since the latter doesn't need anchoring and a quantifier, I often prefer
it.

Anno


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

Date: 01 Mar 2005 13:54:01 +0100
From: Arndt Jonasson <do-not-use@invalid.net>
Subject: Re: Regexp small question
Message-Id: <yzdr7izwmqe.fsf@invalid.net>


"Bernard El-Hagin" <bernard.el-haginDODGE_THIS@lido-tech.net> writes:
> Brian McCauley <nobull@mail.com> wrote:
> 
> > Bernard El-Hagin wrote:
> > 
> >> if ($str =~ m/^[\w.-]+$/) {
> > 
> > That works but it's also a common idiom to simplify this by
> > inverting the char-class and the condition.
> > 
> >   if ($str !~ /[^\w.-]/) {
> 
> 
> Really? That's a common idiom? Personally, I that is absolutely horrid. 
> I would *never* use it and I most certainly wouldn't call it a 
> simplification. I guess it's a matter of what one is used to, but 
> inverting *two* things to get a result one get get without inverting 
> *any*thing seems...perverse to me. :-)

You can switch the following clauses if the "!=" offends you:

        if ($str =~ /[^\w.-]/) {
                # bad string
        } else {
                # good string
        }

(To me, it _is_ a simplification in that the ^...+$ makes the other
construction more error-prone.)

However, what about empty strings? The two constructions don't treat
empty strings the same way. Replacing the '+' with '*' would make them
equivalent.


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

Date: Tue, 01 Mar 2005 13:25:00 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Regexp small question
Message-Id: <d01q58$dl8$1@sun3.bham.ac.uk>

Anno Siegel wrote:

> Bernard El-Hagin <bernard.el-haginDODGE_THIS@lido-tech.net> wrote in comp.lang.perl.misc:
> 
>>Brian McCauley <nobull@mail.com> wrote:
>>
>>
>>>Bernard El-Hagin wrote:
>>>
>>>
>>>>if ($str =~ m/^[\w.-]+$/) {
>>>
>>>That works but it's also a common idiom to simplify this by
>>>inverting the char-class and the condition.
>>>
>>>  if ($str !~ /[^\w.-]/) {
>>
>>
>>Really? That's a common idiom? Personally, I that is absolutely horrid. 
>>I would *never* use it and I most certainly wouldn't call it a 
>>simplification. I guess it's a matter of what one is used to, but 
>>inverting *two* things to get a result one get get without inverting 
>>*any*thing seems...perverse to me. :-)
> 
> 
> I agree with brian here (hey, it happens :).  I find it perfectly natural
> to go from "consists entirely of ..." to "contains nothing outside of ...".  
> Since the latter doesn't need anchoring and a quantifier, I often prefer
> it.

The OP was expressed "check a string that will not contain some 
characters", so, in fact, it is Bernard's solution that is a double 
invertion relative to the OP.



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

Date: Tue, 01 Mar 2005 13:28:38 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Regexp small question
Message-Id: <d01qc2$du0$1@sun3.bham.ac.uk>



Arndt Jonasson wrote:

> "Bernard El-Hagin" <bernard.el-haginDODGE_THIS@lido-tech.net> writes:
> 
>>Brian McCauley <nobull@mail.com> wrote:
>>
>>
>>>Bernard El-Hagin wrote:
>>>
>>>
>>>>if ($str =~ m/^[\w.-]+$/) {
>>>
>>>That works but it's also a common idiom to simplify this by
>>>inverting the char-class and the condition.
>>>
>>>  if ($str !~ /[^\w.-]/) {

> However, what about empty strings? The two constructions don't treat
> empty strings the same way. Replacing the '+' with '*' would make them
> equivalent.

Yes, I hadn't spotted that Bernard's solution did the wrong thing with 
respect to empty strings.  For that matter it also does the wrong thing 
with respect to strings with a terminal newline.



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

Date: Tue, 01 Mar 2005 13:06:50 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: webpage
Message-Id: <38j494F5m7tujU1@individual.net>

Anno Siegel wrote:
> <erdem.ultanir@gmail.com> wrote in comp.lang.perl.misc:
>> I have a question about webpages. I see all around some webpages
>> that contain cooking recipes, and at the same time people can enter
>> their recipes on that website,o r they can review it and put
>> comments. What I would like to do is something similar, but a very
>> simple form. I just want to get information from people and publish
>> on the web
> 
> [...]
> 
> That has nothing to do with the programming language Perl.

A rather confusing answer IMO.

To the OP: A lot of such web apps are written in Perl, so Perl is indeed
one possible programming language.

However, this is not the right place to look for ready-to-go programs.
You'd better use Google for that, or you can for instance go here:

     http://cgi.resourceindex.com/Programs_and_Scripts/Perl/

If you decide to write such an app in Perl, and encounter a Perl
problem, this may be a place to ask for advice.

> You should ask your question in a group in the comp.infosystems.www.*
> hierarchy.

That's not the right place to look for ready-to-go programs, either. But
if you decide to write such an app, and encounter CGI related problems,
for instance, comp.infosystems.www.authoring.cgi may be a place to ask
for advice.

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


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

Date: Tue, 01 Mar 2005 13:04:00 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: where is my magic (XS related)
Message-Id: <d01ott$d2t$1@sun3.bham.ac.uk>



Pavel Hlavnicka wrote:
> Abstract: If I assign some magic to a value returned from FIRSTKEY (tie 
> method) this magic is not present as this value is passed to NEXTKEY.

Abstract: AFAIK, magic applies to lvalues not to rvalues.  When the the 
lvalue is resolved to and rvalue, such as when value of the magic SV is 
copied to another SV it looses it's magic.

I don't know what would happen if you try to return an value with magic 
from a function that's expected to return an rvalue.  The behaviour is 
probably undefined.

If you want something like magic but which is preserved as the value is 
copied from SV to SV you need to go for an object with overload.  I've 
never done this from XS.



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

Date: Tue, 01 Mar 2005 08:42:17 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: where is my magic (XS related)
Message-Id: <87ll97bhza.fsf@gemini.sunstarsys.com>

Pavel Hlavnicka <pavel@gingerall.cz> writes:

> Abstract: If I assign some magic to a value returned from FIRSTKEY
> (tie method) this magic is not present as this value is passed to
> NEXTKEY. 
>
> My XS provides functions for hash 'tie' magic (TIEHASH, FETCH...), all
> went fine until I started with FIRSTKEY and NEXTKEY. My extension
> works with a complex C++ library and for a hash iteration I need to
> keep some library specific iteration key. My idea was to use `~` or
> `U` magic and associate it with a key returned from FIRSTKEY and use
> it later in NEXTKEY. Like this: 

Try adding it to the object instead of the key.  MAGIC isn't 
preserved across an assignment, which is what perl must do here: 
it makes an internal copy of FIRSTKEY's (mortal) RETVAL, to 
eventually pass to NEXTKEY as "last".

-- 
Joe Schaefer


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

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


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