[27092] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 8978 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Feb 21 14:05:38 2006

Date: Tue, 21 Feb 2006 11:05:05 -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, 21 Feb 2006     Volume: 10 Number: 8978

Today's topics:
    Re: Alternate for buzzers in a competition xhoster@gmail.com
    Re: Alternate for buzzers in a competition <ebohlman@omsdev.com>
        Help me get "Directory" out of full windows path name? <Random@Task.be>
    Re: Help me get "Directory" out of full windows path na <1usa@llenroc.ude.invalid>
        Implementing a "pull" (?) interface in perl <nomail@sorry.com>
    Re: Inline::C and multiple platforms xhoster@gmail.com
    Re: Inline::C and multiple platforms <bart.lateur@pandora.be>
        Reading Mac / Unix / DOS text files <january.weiner@gmail.com>
        UNICODED string into array <pipi.melhiad@yahoo.com>
    Re: www.perlservices.net <tadmc@augustmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 21 Feb 2006 14:32:59 GMT
From: xhoster@gmail.com
Subject: Re: Alternate for buzzers in a competition
Message-Id: <20060221093513.732$wa@newsreader.com>

rgompa@steel.ucs.indiana.edu (Raghuramaiah Gompa) wrote:
> We are hosting a math fair. We have teams competing.
> I am just wondering whether there is anyway we could use
> laptops to serve as buzzers.  Laptops can be connected to
> a central computer through wireless.  Team can press a
> button when they are ready.  Can we write a perl code to
> do this on the computers?  Please help. .. Raghu

Yes.  See IO::Socket::INET and IO::Select.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: 21 Feb 2006 17:29:21 GMT
From: Eric Bohlman <ebohlman@omsdev.com>
Subject: Re: Alternate for buzzers in a competition
Message-Id: <Xns97717464CD60Eebohlmanomsdevcom@130.133.1.4>

xhoster@gmail.com wrote in news:20060221093513.732$wa@newsreader.com:

> rgompa@steel.ucs.indiana.edu (Raghuramaiah Gompa) wrote:
>> We are hosting a math fair. We have teams competing.
>> I am just wondering whether there is anyway we could use
>> laptops to serve as buzzers.  Laptops can be connected to
>> a central computer through wireless.  Team can press a
>> button when they are ready.  Can we write a perl code to
>> do this on the computers?  Please help. .. Raghu
> 
> Yes.  See IO::Socket::INET and IO::Select.

That was my first thought too, but then I realized a simpler way would be 
just to set up an HTTP server on the central computer and run a CGI script 
that would deliver a very simple HTML form to each laptop and then record 
when each submit button was pressed.  That way you don't need to write 
client software for the laptops.


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

Date: Tue, 21 Feb 2006 12:12:30 -0500
From: Random Task <Random@Task.be>
Subject: Help me get "Directory" out of full windows path name?
Message-Id: <1SHKf.1285$XZ3.142971@news20.bellglobal.com>

Hi i am trying to get $tmpdir to contain the "directory" instead of a 
fully pathed file name ... i.e. truncate the file name.

I am trying the below code ... but $1 is always empty ... help please :-)

my $tmpdir = $file;
if ( $tmpdir =~/([.]*)[\\]{1}/)
   {
     print("MATCH\n");
     $tmpdir = $1;
     print ("[--->]".$1."<----]\n");
   }
else
   {
     print("NO MATCH\n");
     $tmpdir = $tmpdir;
   }


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

Date: Tue, 21 Feb 2006 18:50:25 +0000 (UTC)
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Help me get "Directory" out of full windows path name?
Message-Id: <Xns97718CCACB326asu1cornelledu@132.236.56.8>

Random Task <Random@Task.be> wrote in news:1SHKf.1285$XZ3.142971
@news20.bellglobal.com:

> Hi i am trying to get $tmpdir to contain the "directory" instead of a 
> fully pathed file name ... i.e. truncate the file name.
> 
> I am trying the below code ... but $1 is always empty ... help please 
:-)

Why are you reinventing the wheel?

See

http://search.cpan.org/~nwclark/perl-5.8.8/lib/File/Basename.pm

See also splitpath and splitdir in 

http://search.cpan.org/~kwilliams/PathTools-3.16/lib/File/Spec.pm

There is immense value to doing this kind of thing portably.

> my $tmpdir = $file;
> if ( $tmpdir =~/([.]*)[\\]{1}/)

What are you fascinated with square brackets

Do you know what [.]* means? Dot is not special in a character class. So 
[.]* means "match a dot zero or more times" before matching a character 
class containing a slash exactly one time. Of course, you need not 
specify a quantifier if you only want something to match exactly once.

The regex automatically matches nothing followed by a slash in the path 
name, and nothing is captured as you specified.

You need to read perldoc perlre.

You also need to anchor the regex to the end of the path:

#!/usr/bin/perl

use strict;
use warnings;

chomp(my @paths = <DATA>);

for my $p ( @paths ) {
    if ( $p =~ m{ \A ( .+ (?:/|\\) ) }x ) {
        print "$1\n";
    }
}

__DATA__
C:\
C:\Home\asu1\Dload\gvim.exe
C:\Home\asu1\src\usenet\.test
But\Please\use\File\Spec\.

Sinan


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

Date: Tue, 21 Feb 2006 09:28:28 -0800
From: Arvin Portlock <nomail@sorry.com>
Subject: Implementing a "pull" (?) interface in perl
Message-Id: <dtfiju$i67$1@agate.berkeley.edu>

I'm writing a module to parse an XML file of records. It
will be used by a variety of different applications, e.g.,
loading into a relational database, etc. I'll be using
a SAX based approach, ExpatXS, as the XML files can be
very large.

In the past I've written such modules by assembling a huge
data structure in memory then returning it to the calling
application as, say, a reference to an array of hashes.
This was tremendously convenient yet very very slow. Some
applications would take hours to execute. This time around
I'd like to learn something new and approach it differently.

Is there some way to design this, module plus application,
so that as a record is read the application can process it
immediately? Is this what is know as a pull-based architecture?
How does the application "know" when a new record is available?
Does it listen for something that the module emits? I'm
thinking maybe it can be done with a callback. The callback
subroutine is written in the calling application and when
the end of the record is parsed, that subroutine is called.

I'm sure this is a basic question but it's new to me. Is my
callback idea worth exploring? Are there any design patterns
people can point me to? Example programs? Articles online?

Thanks!

Arvin



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

Date: 21 Feb 2006 14:50:55 GMT
From: xhoster@gmail.com
Subject: Re: Inline::C and multiple platforms
Message-Id: <20060221095309.991$uV@newsreader.com>

"Andrei Alexandrescu (See Website For Email)"
<SeeWebsiteForEmail@moderncppdesign.com> wrote:
> I'd like to put a Perl script using Inline::C on a shared filesystem.
> Users might invoke the script from Linux or Solaris systems.
>
> Now the problem is, the Inline module will use an MD5 digest and caching
> to ensure that the C part is recompiled if changed. However, that also
> means that the the mechanism won't detect that the script is being
> invoked under different operating systems, so it will erroneously
> attempt to use the Linux shared lib on Solaris or vice versa.
>
> How can I avoid that in an elegant manner?

I wouldn't exactly call it elegant, but....

my $arch_version;
BEGIN {
  use Config;
  $arch_version = "./_Inline_" .
  $Config{'archname'}.'-'.$Config{'version'};
  mkdir $arch_version or die $! unless -d $arch_version;
};

use Inline C=> 'DATA', DIRECTORY => $arch_version;


Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: Tue, 21 Feb 2006 15:29:44 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: Inline::C and multiple platforms
Message-Id: <bvbmv1955k8orl8mseb0aumbhmubved1mv@4ax.com>

Andrei Alexandrescu (See Website For Email) wrote:

>I'd like to put a Perl script using Inline::C on a shared filesystem. 
>Users might invoke the script from Linux or Solaris systems.
>
>Now the problem is, the Inline module will use an MD5 digest and caching 
>to ensure that the C part is recompiled if changed. However, that also 
>means that the the mechanism won't detect that the script is being 
>invoked under different operating systems, so it will erroneously 
>attempt to use the Linux shared lib on Solaris or vice versa.
>
>How can I avoid that in an elegant manner?

I think it sounds like a bug in Inline. What it does, is create a
subdirectory ".Inline/lib/auto" and place the compiled module under a
custom sudirectory. What it *should* do, IMO, is place the subdirectory
under ".Inline/lib/$Config{archname}/auto", where %Config is the hash
from Config.pm, or perhaps even throwing in $Config{version} as well.

-- 
	Bart.


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

Date: Tue, 21 Feb 2006 16:53:06 +0100 (CET)
From: January Weiner <january.weiner@gmail.com>
Subject: Reading Mac / Unix / DOS text files
Message-Id: <dtfd12$m4k$1@sagnix.uni-muenster.de>

Hi, I'm sure this is a common problem:

I'd like my script to treat text files coming from various systems alike.
More specifically, I'd like to recognize ends of line as one of: \r, \l,
\r\l.  Is there a more elegant way than doing the obvious?:

  while(<IF>) {
    s/\r?\l?$// ; # is this correct anyway? will an end of line be
                  # recognized with a Mac file?
    #...
  }

I would expect that there is some weird variable out there (like the $/)
that changes the behaviour of chomp to be more promiscous. 

The problem, of course, is, that this cannot be set platform- or
scriptwide. One file might contain DOS eols, another one would come from
Mac.

j.

-- 


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

Date: Tue, 21 Feb 2006 19:04:20 +0100
From:  <pipi.melhiad@yahoo.com>
Subject: UNICODED string into array
Message-Id: <MPG.1e657492d945db5f98969c@news.siol.net>

Hi !

I have an issue where I have to process string character by character
and when special character occurs I need to make some action.

The problem is that the string consists
unicode characters as well so when I do something like
@a = split //, $mystring  
I get multiple entries (from two to 4 bytes).

What I need to do is mostly to replace those characters with some normal
character (X for example)

Let's say I have unicode character with the code 010f.

$mystring=~s/\u{010f}/X/g   doesn't work.

Any idea ? Should I use some speciall library to do that ?


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

Date: Tue, 21 Feb 2006 12:20:09 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: www.perlservices.net
Message-Id: <slrndvmmep.3i5.tadmc@magna.augustmail.com>

Jeremy Clulow <jeremy@websNOSPAMwonder.co.uk> wrote:

> Hi Sinane,
> 
> Thanks for you help. You have changed my life with your wisdom


And thank you for identifying yourself as someone who can
be safely ignored forevermore.

So long!


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


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

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


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