[16084] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3496 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jun 28 00:05:30 2000

Date: Tue, 27 Jun 2000 21:05:12 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <962165112-v9-i3496@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 27 Jun 2000     Volume: 9 Number: 3496

Today's topics:
    Re: "Bare words" <jeffp@crusoe.net>
    Re: Arbitrary function calling in module <sun_tong_001@yahoo.com>
    Re: binary and regular expressions <phill@modulus.com.au>
    Re: Encryption <jimmy@blackhole-designs.com>
        expired page <wryseREMOVETHIS@earthlink.net>
    Re: Finding the directory of the current script <sumus@aut.dk>
    Re: Golf (Was: Re: HELP ME PLEASE !!!!) <sumus@aut.dk>
    Re: Help with 'If' condition - newbie <stephenk@cc.gatech.edu>
        LWP::UserAgent blocking problem <ke77le@my-deja.com>
        module return value <sun_tong_001@yahoo.com>
        newbie REGEX problem (Jason Goodrow)
    Re: newbie REGEX problem (Keith Calvert Ivey)
    Re: newbie REGEX problem <stephenk@cc.gatech.edu>
    Re: Number of Unique Values (Gwyn Judd)
    Re: Perl/cgi newbie questions (Mark P.)
    Re: Persistence problem (Mark P.)
    Re: Problem writing a binary file to another location (David Efflandt)
    Re: Question on integers (Abigail)
        regex brain teaser <nomail@nomail.com>
    Re: regex brain teaser <stephenk@cc.gatech.edu>
    Re: regex brain teaser (Keith Calvert Ivey)
    Re: regex brain teaser <stephenk@cc.gatech.edu>
        shift in sub <sun_tong_001@yahoo.com>
    Re: shift in sub (Maurice E. Jarrell)
    Re: shift in sub <sun_tong_001@yahoo.com>
    Re: shift in sub (Keith Calvert Ivey)
    Re: shift in sub <stephenk@cc.gatech.edu>
    Re: split regex (Tad McClellan)
    Re: split regex (Charles DeRykus)
    Re: Teen Volenteers WANTED (Martien Verbruggen)
    Re: Teen Volenteers WANTED (Abigail)
    Re: Using link checking scripts with Dynamo server (new <bellamy_walton@my-deja.com>
        Would the function win32::AdminMisc::ScheduleAdd works  <chkwok@unitechnetworks.com>
        XS and C structures question <damani@world.std.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Tue, 27 Jun 2000 22:56:39 -0400
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: "Bare words"
Message-Id: <Pine.GSO.4.21.0006272248400.25169-100000@crusoe.crusoe.net>

[posted & mailed]

On Jun 28, Keith Calvert Ivey said:

>SPAM+indigo@dimensional.com (Tim) wrote:
>
>>    %h = (x => 'abc'); # Always correct
>>    $h{x} = 'abc';     # Less correct
>>    $x = abc;          # Bad developer, no cookie
>
>I'd say that the first and the second are at exactly the same
>level of correctness (which is "Always correct").  They're very
>similar, generally hash-related autoquoting.  What makes you
>think there's a difference?

There is no SPECIFIC hash relation.  A bareword inside braces is assumed
to be a single quoted string, and a bareword to the left of => is assumed
to be a single quoted string.  It just so happens that this is damn useful
when dealing with hashes.

  %hash = (
    foo => 'bar',
    blit => 'blat',
  );
  print $hash{foo};

One note of interest (a Perl bug) is that if there is a newline between
the bareword and the =>, Perl does not treat the bareword as a single
quoted string.  There is a patch for that, though.

  %hash = ( time
  => 'now');
  print $hash{time};    # you're out of luck
  print $hash{time()};  # you might be lucky, if no time has passed ;)

It is deliberate that a bareword in braces is a single-quoted string --
Perl does the conversion at compile-time:

  jeffp@friday [10:53pm] ~ #714> perl -MO=Deparse
  print time
  => time => 1;
  print $b{foobar}, $b{time};
  __END__
  - syntax OK
  print time, 'time', 1;
  print $b{'foobar'}, $b{'time'};

In fact, I've often seen that quoting hash keys leads to problems for new
Perl programmers that don't understand the "nested 'quotes' problem".

  print "Hello, $user{"FirstName"}.\n";

And while using single quotes around FirstName helps, it's much easier to
say

  print "Hello, $user{FirstName}.\n";

-- 
Jeff "japhy" Pinyan     japhy@pobox.com     http://www.pobox.com/~japhy/
PerlMonth - An Online Perl Magazine            http://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc.    http://www.perlarchive.com/
CPAN - #1 Perl Resource  (my id:  PINYAN)        http://search.cpan.org/



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

Date: 27 Jun 2000 23:39:40 -0300
From: * Tong * <sun_tong_001@yahoo.com>
Subject: Re: Arbitrary function calling in module
Message-Id: <sa8aeg634wj.fsf@sun_tong_001.personal.yahoo.com>

"Dan Manion" <news@webneeds.com> writes:

> Hope this helps!

Hi, Dan:

It doesn't help much --  It helps A LOT! :-) 

Thanks

-- 
Tong (remove underscore(s) to reply)
  http://members.xoom.com/suntong001/
  - All free contribution & collection & music from the heavens


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

Date: Wed, 28 Jun 2000 12:13:15 +1000
From: Peter Hill <phill@modulus.com.au>
Subject: Re: binary and regular expressions
Message-Id: <39595F3B.14F0@modulus.com.au>

Tad McClellan wrote:
> 
> On 27 Jun 2000 14:43:50 EDT, Abigail <abigail@delanet.com> wrote:
> 
> [ snip "why don't these match?" ]
> 
> >@@ "m" =~ /(chr(109))/
> >
> >Because "m" does not start with a left parenthesis.
> 
> Errr, better make that:
> 
>    Because "m" does not start with a 'c'.
> 
> :-)
> 
Or, for the really pernickity,

	Because "m" does not contain a 'c'.
;^)
-- 
Peter Hill,
Modulus Pty. Ltd.,
http://www.modulus.com.au/


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

Date: Wed, 28 Jun 2000 01:12:50 GMT
From: Jimmy Humphrey <jimmy@blackhole-designs.com>
Subject: Re: Encryption
Message-Id: <39595198.3A551E9B@blackhole-designs.com>

Thanks for the help guys with the "binmode" function. However, I still
get problems with the ms word docs.  Although it did fix the reason why
 .txt type files did not print a \n char (or however win32 systems print
it). Anybody out there know why translating these ms word files into
ansii code and such is causing problems?

Jimmy

Jimmy Humphrey wrote:
> 
> I made a very basic encryption tool in perl. However, I noticed some
> problems.  For "some" .doc files, and such, the encryption tool seems to
> corrupt. I use pack("c") & unpack("c") to translate my strings into
> ASCII code. But for some reason, when I decrypt the message, on "some"
> .doc files, it makes them become corrupt. This program works with
> regular text files. Could anybody explain why this might happen? Using
> Win32 activestate perl (latest version).
> 
> Jimmy
> 
> --
> Jimmy Humphrey <jimmy@blackhole-designs.com>
> Web Designer - Black Hole Designs - http://www.blackhole-designs.com

-- 
Jimmy Humphrey <jimmy@blackhole-designs.com>
Web Designer - Black Hole Designs - http://www.blackhole-designs.com


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

Date: Wed, 28 Jun 2000 03:31:32 GMT
From: mkm <wryseREMOVETHIS@earthlink.net>
Subject: expired page
Message-Id: <39597236.3BC6F084@earthlink.net>

I am getting an expired page error when I hit the back button.  

I am sure this isn't stricly a Perl issue, but it isn't happening with
pages I generated via servlet or jsp, only Perl.

Also, this isn't happening in Netscape, only IExplore.

It is not a cookie issue (no cookies).  Is there some other security
config that can be adjusted to allow reload html from cache?  It seems
to be trying to submit and generate the form again.

Any pointers are tremendously appreciated.

Thanks,
mkm

Here is the exact text of the message:

Warning: Page has Expired The page you requested was created using
information you submitted in a form. This page is no longer available.
As a security precaution, Internet Explorer does not automatically
resubmit your information for you. 

To resubmit your information and view this Web page, click the Refresh
button.


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

Date: 28 Jun 2000 03:36:23 +0200
From: Jakob Schmidt <sumus@aut.dk>
Subject: Re: Finding the directory of the current script
Message-Id: <8zvqoaco.fsf@macforce.sumus.dk>

conic@bigpond.com writes:

> Is there a way for a script to realise what directory it is in?  I want
> to examine files that are in the same directory as the script, but also
> to be able to move the script to any directory without changing it.

Usually you can just use '.':

opendir MYDIR, '.' or die "Couldn't. $!";

Apparantly * can be used as default handle for reading the contents of
a scripts own dir - but I just learned this the other day and I havn't
found where its documented yet:

while ( <*> ) { print "$_ is in my dir\n" }

-- 
Jakob


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

Date: 28 Jun 2000 03:12:14 +0200
From: Jakob Schmidt <sumus@aut.dk>
Subject: Re: Golf (Was: Re: HELP ME PLEASE !!!!)
Message-Id: <bt0mobgx.fsf@macforce.sumus.dk>

Uri Guttman <uri@sysarch.com> writes:
> 
> in the tpc4 tournament, every char is counted. so knowing how to
> eliminate unnecessary white space is a very useful skill in perl
> golf. some other simple tricks include using y/// instead of tr/// and
> length, using an expression instead of a block in map/grep, removing
> white space before vars as the $/@/% will end a previous token, etc.

Golf is nastier than I thought :-/

-- 
Jakob


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

Date: Tue, 27 Jun 2000 23:12:21 -0400
From: Stephen Kloder <stephenk@cc.gatech.edu>
Subject: Re: Help with 'If' condition - newbie
Message-Id: <39596D15.285E28DF@cc.gatech.edu>

Mtshupp wrote:

> Hello,
>
> Perl newbie here -- I'm attempting to modify a script;  I'm trying to describe
> a condition such that if a subtotal is less than 6.00, a shipping fee is 2.00;
> 6.00 - 9.99, shipping fee is 3.00;  ...and so forth.  The amounts are
> arbitrarily set.
>
>

<code snipped>

>
>  Subtotal is:       Shipping is:
>
>   0.00 -  5.99              2.00
>   6.00 -  9.99              3.00
> 10.00 - 14.99              3.50
> 15.00 - 19.99              4.00
> 20.00 - up                 5.00
>

Your code works, but what if rules change?  This method is reusable (just change
the values in @mins and @rates):

#!c:\perl\bin\perl -w
@mins = (6,10,15,20);
@rates = (2,3,3.5,4,5);
while(<>) {
  chomp;
  print shipping($_), "\n";
}

sub shipping {
  $value = shift;
  foreach(0..$#mins) {
    return $rates[$_] if $value < $mins[$_];
  }
  return $rates[-1];
}


Of course, the assumption is made that there are no gaps in the shipping policy,
so only minima (or maxima) need to be stored.

--
Stephen Kloder               |   "I say what it occurs to me to say.
stephenk@cc.gatech.edu       |      More I cannot say."
Phone 404-874-6584           |   -- The Man in the Shack
ICQ #65153895                |            be :- think.




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

Date: Wed, 28 Jun 2000 02:28:05 GMT
From: Kostis <ke77le@my-deja.com>
Subject: LWP::UserAgent blocking problem
Message-Id: <8jbnr6$csl$1@nnrp1.deja.com>

Hi all.

I'm writing a little app which retrieves data from a web server and
I've decided to use the CPAN modules which seem to work fine apart from
a little problem...

The problem is that if the webserver I'm trying to connect to is down
the part of the code that actually make the request i.e.:

my $response = $ua->request($request);

blocks for ages!!!

I tried calling:
$ua->timeout(60);

But this didn't seem to have any effect.

I'm pretty sure (* see note below) the underlying code found in the
UserAgent module blocks when it tries to connect to the server (if the
server is down) but I don't know how to solve this.


Can anyone help?

Maky Thanks,
Kostas

* I think the strace I did proves this:
connect(10, {sin_family=AF_INET, sin_port=htons(80), sin_addr=inet_addr
("some.ip.add.ress")}, 16


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


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

Date: 28 Jun 2000 00:40:37 -0300
From: * Tong * <sun_tong_001@yahoo.com>
Subject: module return value
Message-Id: <sa81z1i322y.fsf@sun_tong_001.personal.yahoo.com>

Hi,

I saw many modules end with "1;". Is that the return value for the
module? 

When I checked the template provided in perlmod, I found no such
return values. So, do I need it? 

BTW, the END {} section of the module, is it executed just before
program is closed?

thanks

-- 
Tong (remove underscore(s) to reply)
  http://members.xoom.com/suntong001/
  - All free contribution & collection & music from the heavens


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

Date: 27 Jun 2000 22:37:44 -0400
From: goodrow@panix.com (Jason Goodrow)
Subject: newbie REGEX problem
Message-Id: <8jbodo$kcp$1@panix3.panix.com>
Keywords: newbie regex

I want to say:

put the charicters after '/' and before '.' into $out.

foreach $line (@array){
if (/stuff/) {
$out = m#/.*\.#;
print "$line - $out\n";}
}

$out = 1 (?) testing positive for match(?) 
and $line is printed without matching /stuff/ (??)

any help / tutorial URLs

thanks in advance
goodrow@panix.com






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

Date: Wed, 28 Jun 2000 03:38:29 GMT
From: kcivey@cpcug.org (Keith Calvert Ivey)
Subject: Re: newbie REGEX problem
Message-Id: <395a7141.12704605@nntp.idsonline.com>

goodrow@panix.com (Jason Goodrow) wrote:

>put the charicters after '/' and before '.' into $out.
>
>foreach $line (@array){
>if (/stuff/) {
>$out = m#/.*\.#;
>print "$line - $out\n";}
>}
>
>$out = 1 (?) testing positive for match(?) 
>and $line is printed without matching /stuff/ (??)

You're using $line as your loop variable but then checking $_ in
the matches; use one or the other.  Also, you're setting $out to
the match result (true or false) rather than capturing the
segment of interest.

Here's one rewrite:

    foreach (@array) {
        if (/stuff/) {
            my($out) = m#/(.*)\.#;
            print "$_ - $out\n";
        }
    }

-- 
Keith C. Ivey <kcivey@cpcug.org>
Washington, DC


-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----


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

Date: Tue, 27 Jun 2000 23:41:15 -0400
From: Stephen Kloder <stephenk@cc.gatech.edu>
Subject: Re: newbie REGEX problem
Message-Id: <395973DB.C22C14F0@cc.gatech.edu>

Jason Goodrow wrote:

> I want to say:
>
> put the charicters after '/' and before '.' into $out.
>
> foreach $line (@array){
> if (/stuff/) {
> $out = m#/.*\.#;
> print "$line - $out\n";}
> }
>
> $out = 1 (?) testing positive for match(?)
> and $line is printed without matching /stuff/ (??)
>
> any help / tutorial URLs

The info you seek is in perlop (under m//).
Notice the return values under listand scalar context.

--
Stephen Kloder               |   "I say what it occurs to me to say.
stephenk@cc.gatech.edu       |      More I cannot say."
Phone 404-874-6584           |   -- The Man in the Shack
ICQ #65153895                |            be :- think.




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

Date: Wed, 28 Jun 2000 02:28:38 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Number of Unique Values
Message-Id: <slrn8lioro.m71.tjla@thislove.dyndns.org>

I was shocked! How could Abigail <abigail@delanet.com>
say such a terrible thing:
>
>No. But it's on dejanews.

*shrug* not on my dejanews. I guess the CIA censors what is allowed out
of the US. Why don't you break down and tell me? I promise your head
won't fall off if you answer the same question more than once :)

-- 
Gwyn Judd (tjla@guvfybir.qlaqaf.bet)
My return address is rot13'ed
Why isn't there some cheap and easy way to prove how much she means to me?


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

Date: Wed, 28 Jun 2000 01:42:30 GMT
From: perl@imchat.com (Mark P.)
Subject: Re: Perl/cgi newbie questions
Message-Id: <39595762.1026048649@news.ionet.net>

On Tue, 27 Jun 2000 11:44:33 -0600, rickh <rickh@burgoyne.com> wrote:


>When I access this program through my web browser, I get an "internal
>error.  Looking at the error_log it would appear that the Print <<HTML
>lines are the problem.  the error message indicates that they are not
>numeric and appearently the << is the numeric left shift operator.
>Question is What was the Print <<HTML line supposed to do?
>
	Check the Perl version. Your're probably running an old
version that doesn't support HERE docs. You can always use print qq
instead.


MP


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

Date: Wed, 28 Jun 2000 01:38:35 GMT
From: perl@imchat.com (Mark P.)
Subject: Re: Persistence problem
Message-Id: <3959558b.1025577382@news.ionet.net>

Okay, I'll figure it out on my own!! I figure all I need to do is
bless an object and call it new with each instance. Hopefully that
will do it, and no, I don't think this is off topic. The question was
related to CGI.pm and scoping. Persistence relates only to the effect.


See y'all at Perl Conf 4.0. Hopefully I'll have this figured out by
then so I don't have to ask Lincoln.<G>


MP


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

Date: 28 Jun 2000 01:37:49 GMT
From: efflandt@xnet.com (David Efflandt)
Subject: Re: Problem writing a binary file to another location
Message-Id: <slrn8lilmn.too.efflandt@efflandt.xnet.com>

On Tue, 27 Jun 2000, Jeremiah Adams <adams1015@worldnet.att.net> wrote:
>
>I am trying to get a file which is uploaded with a browser and write it to
>another directory. I am using cgi.mod to do the uploads. The upload works
>fine as well as saving it but the data is corrupted when saved and you
>cannot view the images.

It is not corrupt, you are simply trying to read a filehandle twice that
can only be read once and failing to save the data the first time through. 

>There is no strict pragma because according to Stien (the mod's author) this
>creates problems.
>
>Here is the source. Most of it comes straight from stein's web site.:
>#!/usr/bin/perl -w
>
># test for file upload
>use diagnostics;
>
>use CGI::Carp qw(carpout fatalsToBrowser);
>
>use CGI qw(:standard);
>$save_path = "/httpd/cgi-bin/tests/_temp";
>
>
>print header,
>    start_html('file upload'),
>    h1('file upload');
>print_form()    unless param;
>print_results() if param;
>print end_html;
>
>sub print_form {
>    print start_multipart_form(),
>       filefield(-name=>'upload',-size=>60),br,
>       submit(-label=>'Upload File'),
>       end_form;
>}
>
>sub print_results {
>    my $length;
>
>    my $file = param('upload');
>     my $m_save_path = "$save_path/file1.gif";
>    if (!$file) {
>        print "No file uploaded.";
>        return;
>    }
>   # print h2('File name'),$file;
>   # print h2('File MIME type'),
>   # uploadInfo($file)->{'Content-Type'};
>    while (<$file>) {
>        $length += length($_);

Here you are reading the filehandle of the uploaded file and checking
length of the data, but not storing the data anywhere.  Therefore after
this while loop the uploaded file content does not exist.  Perhaps you
want to do something useful like saving the data here before dumping it.

>   }
>   # print h2('File length'),$length;
>
>    $file_type = uploadInfo($file)->{'Content-Type'};
>
>    if ( $file_type eq 'image/gif' ) {
>        print h2('Correct File');
>
>
>        # Copy a binary file to somewhere safe
>        open (OUTFILE,">> $m_save_path");

You have already read $file without saving it in the while loop above.
Since filehandle $file is already eof, what do you expect the following to
do?  It can only be read once, there is no going back (no seek).

>        while ($bytesread=read($file,$buffer,$length)) {
>           print OUTFILE $buffer;
>        }
>    }
>    else {
>         print_bad_file();
>    }
>}
>sub print_bad_file {
>    print h2('Bad file type');
>    print p('Only select .gif or .jpg files.')
>}


-- 
David Efflandt  efflandt@xnet.com  http://www.de-srv.com/
http://www.autox.chicago.il.us/  http://www.berniesfloral.net/
http://hammer.prohosting.com/~cgi-wiz/  http://cgi-help.virtualave.net/



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

Date: 27 Jun 2000 22:49:58 EDT
From: abigail@delanet.com (Abigail)
Subject: Re: Question on integers
Message-Id: <slrn8lir0g.ka1.abigail@alexandra.delanet.com>

Young H Lee (yhlee@mail.med.upenn.edu) wrote on MMCDXCII September
MCMXCIII in <URL:news:8jbea2$1il$1@netnews.upenn.edu>:
-- Hypothetically speaking, if I wanted to multiply two very large prime 
-- numbers, say with 150 digits each.. What do you guys suggest to implement 
-- this?  I was thinking a 150 indexed array, but that would get really 
-- complicated.  

There are several ways. There's Math::BigInt, and you can pipe things
into bc.

If you only have to multiply one pair of large numbers, performance
hardly matters. But if you have many pairs, using bc in a smart way
beats the crap out of Math::BigInt:


    #!/opt/perl/bin/perl -w

    use strict;
    use Benchmark;
    use Math::BigInt;

    # First generate some large numbers.
    my $size       = 150;
    my $amount     = 15;
    my @numbers    = map {join "" => map {int rand 10} 1 .. $size} 1 .. $amount;

    timethese 1 << 5 => {
        bigInt    =>  sub {foreach my $l (@numbers) {
                               foreach my $r (@numbers) {
                                   my $p = Math::BigInt -> new ($l) *
                                           Math::BigInt -> new ($r);
                               }
                           }
                      },
        bc        =>  sub {foreach my $l (@numbers) {
                               foreach my $r (@numbers) {
                                   my $p = `echo "$l * $r" | bc`;
                               }
                           }
                      },
        bc_smart  =>  sub {my $line = "";
                           foreach my $l (@numbers) {
                               foreach my $r (@numbers) {
                                   $line .= "$l * $r\n";
                               }
                           }
                           my @p = `echo "$line" | bc`;
                      },
    }

    __END__
    Benchmark: timing 32 iterations of bc, bc_smart, bigInt...
            bc: 171 wallclock secs
                ( 0.48 usr  2.17 sys + 38.27 cusr 65.21 csys = 106.13 CPU)
                @ 12.08/s (n=32)
      bc_smart: 10 wallclock secs
                ( 0.68 usr  0.05 sys +  8.38 cusr  0.56 csys =  9.67 CPU)
                @ 43.84/s (n=32)
        bigInt: 104 wallclock secs
                (95.32 usr +  0.01 sys = 95.33 CPU)
                @  0.34/s (n=32)



Abigail
-- 
perl5.004 -wMMath::BigInt -e'$^V=Math::BigInt->new(qq]$^F$^W783$[$%9889$^F47]
 .qq]$|88768$^W596577669$%$^W5$^F3364$[$^W$^F$|838747$[8889739$%$|$^F673$%$^W]
 .qq]98$^F76777$=56]);$^U=substr($]=>$|=>5)*(q.25..($^W=@^V))=>do{print+chr$^V
%$^U;$^V/=$^U}while$^V!=$^W'


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

Date: Tue, 27 Jun 2000 20:53:41 -0400
From: "Jonah" <nomail@nomail.com>
Subject: regex brain teaser
Message-Id: <8jbosp$b7c$1@onlink3.onlink.net>

Well I've banged my head on the wall over this for a couple of hours now
and I still can't get what I want, all I have now is a headache.

I need to allow the following pattern:

any number of words separated by a "/"

Anything that doesn't match this is an error.

In this case, a word is defined by any \w or \d character, but no spaces
anywhere,
and no \W

Also, the slash, "/" can't be at the beginning or at the
end of the string.

And if the user entered nothing at all, that's also acceptable.

This is sort of like a match for a windows directory, but not
quite.

Thanks for your help.








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

Date: Tue, 27 Jun 2000 23:22:36 -0400
From: Stephen Kloder <stephenk@cc.gatech.edu>
Subject: Re: regex brain teaser
Message-Id: <39596F7B.FD96DEF6@cc.gatech.edu>

Jonah wrote:

> Well I've banged my head on the wall over this for a couple of hours now
> and I still can't get what I want, all I have now is a headache.
>
> I need to allow the following pattern:
>
> any number of words separated by a "/"
>
> Anything that doesn't match this is an error.
>
> In this case, a word is defined by any \w or \d character, but no spaces
> anywhere,
> and no \W
>
> Also, the slash, "/" can't be at the beginning or at the
> end of the string.
>
> And if the user entered nothing at all, that's also acceptable.
>
> This is sort of like a match for a windows directory, but not
> quite.
>
> Thanks for your help.

m#^((\w+/)*\w+)?$# matches word1/word2/.../wordn, and the null string, but
not word1 or word1//word2

m#^((\w+/)*\w+|\w*)$# matches the above matched strings, plus the single
word, but not double slashes.
Can a word between slashes have length 0?

--
Stephen Kloder               |   "I say what it occurs to me to say.
stephenk@cc.gatech.edu       |      More I cannot say."
Phone 404-874-6584           |   -- The Man in the Shack
ICQ #65153895                |            be :- think.




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

Date: Wed, 28 Jun 2000 03:28:07 GMT
From: kcivey@cpcug.org (Keith Calvert Ivey)
Subject: Re: regex brain teaser
Message-Id: <39596d8b.11754188@nntp.idsonline.com>

"Jonah" <nomail@nomail.com> wrote:

>any number of words separated by a "/"

I assume there can be multiple slashes.

>Anything that doesn't match this is an error.
>
>In this case, a word is defined by any \w or \d character, but no spaces
>anywhere, and no \W

In other words, a word is \w -- which already includes \d, and
excludes \W (obviously) and spaces.  I assume you really mean
that a word is \w+.

>Also, the slash, "/" can't be at the beginning or at the
>end of the string.

So you want something like this:

   $input =~ m{^\w+(?:/\w+)*$} or die "Error";

That's a word followed by zero or more occurrences of a slash
and a word.  And it's anchored at the beginning and end so that
it matches the whole string.  Change the $ to \z if you're
worried about final newlines.

>And if the user entered nothing at all, that's also acceptable.

I'd do that as a separate test:

   $input =~ m{^\w+(?:/\w+)*$} or $input eq '' or die "Error";


-- 
Keith C. Ivey <kcivey@cpcug.org>
Washington, DC


-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----


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

Date: Tue, 27 Jun 2000 23:27:28 -0400
From: Stephen Kloder <stephenk@cc.gatech.edu>
Subject: Re: regex brain teaser
Message-Id: <395970A0.D822696E@cc.gatech.edu>

Stephen Kloder wrote:

>
> m#^((\w+/)*\w+)?$# matches word1/word2/.../wordn, and the null string, but
> not word1 or word1//word2
>

I just reviewed this and realized that this regex does indeed match single
words.  Change the * to a + if you don't want to match those.


--
Stephen Kloder               |   "I say what it occurs to me to say.
stephenk@cc.gatech.edu       |      More I cannot say."
Phone 404-874-6584           |   -- The Man in the Shack
ICQ #65153895                |            be :- think.




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

Date: 27 Jun 2000 23:36:22 -0300
From: * Tong * <sun_tong_001@yahoo.com>
Subject: shift in sub
Message-Id: <sa8em5i3521.fsf@sun_tong_001.personal.yahoo.com>

Hi,

Why shift behave different in main and sub?

Let me explain with the following code:

##file subref.pl

- - - -
#!/usr/local/bin/perl -w

$case=shift;

if($case){
    $param=shift;
    while(<>){print;}
} else {
    $func="testing";
    &$func;
}

sub testing {
    $param=shift;
    while(<>){print;}
}
- - - -

If I run "perl subref.pl 0 -t subref.pl"
perl with complain:
Can't open -t: No such file or directory

but if I run "perl subref.pl 1 -t subref.pl", it is ok.

I found that if I use "$param=shift(@ARGV);" in the sub testing, it
would be ok.

Can somebody explain the reasons behind above please? thanks

FYI, my perl:

$ perl -v 

This is perl, version 5.004_04 built for sun4-solaris


-- 
Tong (remove underscore(s) to reply)
  http://members.xoom.com/suntong001/
  - All free contribution & collection & music from the heavens


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

Date: Wed, 28 Jun 2000 03:03:58 GMT
From: mejarrell@worldnet.att.net (Maurice E. Jarrell)
Subject: Re: shift in sub
Message-Id: <m38zvq1p9q.fsf@localhost.localdomain>

* Tong * <sun_tong_001@yahoo.com> writes:

> Why shift behave different in main and sub?

Try 'perldoc -f shift'

If the array is not specified, shift operates on the @ARGV array at
the file level and on the @_ array at the subroutine level.  ( I think
I've said that right.

HTH,
Maury


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

Date: 28 Jun 2000 00:33:22 -0300
From: * Tong * <sun_tong_001@yahoo.com>
Subject: Re: shift in sub
Message-Id: <sa866qu32f1.fsf@sun_tong_001.personal.yahoo.com>

mejarrell@worldnet.att.net (Maurice E. Jarrell) writes:

> * Tong * <sun_tong_001@yahoo.com> writes:
> 
> > Why shift behave different in main and sub?
> 
> Try 'perldoc -f shift'
> 
> If the array is not specified, shift operates on the @ARGV array at
> the file level and on the @_ array at the subroutine level.  ( I think
> I've said that right.

yeah, so I read, but what exactly is the difference between @_ and
@ARGV, then? I thought they were the same.

-- 
Tong (remove underscore(s) to reply)
  http://members.xoom.com/suntong001/
  - All free contribution & collection & music from the heavens


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

Date: Wed, 28 Jun 2000 03:50:15 GMT
From: kcivey@cpcug.org (Keith Calvert Ivey)
Subject: Re: shift in sub
Message-Id: <395b74f9.13656459@nntp.idsonline.com>

* Tong * <sun_tong_001@yahoo.com> wrote:

>yeah, so I read, but what exactly is the difference between @_ and
>@ARGV, then? I thought they were the same.

Look in the documentation (perlvar).  In my copy, it says

    The array @ARGV contains the command line arguments intended
    for the script. Note that $#ARGV is the generally number of
    arguments minus one, because $ARGV[0] is the first argument,
    NOT the command name. See ``$0'' for the command name.

and

    Within a subroutine the array @_ contains the parameters
    passed to that subroutine. See perlsub.

What made you think they were the same?

-- 
Keith C. Ivey <kcivey@cpcug.org>
Washington, DC


-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----


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

Date: Tue, 27 Jun 2000 23:45:22 -0400
From: Stephen Kloder <stephenk@cc.gatech.edu>
Subject: Re: shift in sub
Message-Id: <395974D2.182123DF@cc.gatech.edu>

* Tong * wrote:

>
> yeah, so I read, but what exactly is the difference between @_ and
> @ARGV, then? I thought they were the same.
>

@_ is really @ARG, not @ARGV.
perldoc perlvar

--
Stephen Kloder               |   "I say what it occurs to me to say.
stephenk@cc.gatech.edu       |      More I cannot say."
Phone 404-874-6584           |   -- The Man in the Shack
ICQ #65153895                |            be :- think.




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

Date: Tue, 27 Jun 2000 20:59:28 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: split regex
Message-Id: <slrn8lijfg.s8.tadmc@magna.metronet.com>

On Tue, 27 Jun 2000 19:58:55 -0400, Todd W <trw@uakron.edu> wrote:

>I am trying to figure out how to split on only the last two underscores in
>my string. Any1 mind helping? Thanks in advance.


   die "bad data" unless my @parts = /(.*)_([^_]*)_([^_]*)$/;


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


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

Date: Wed, 28 Jun 2000 02:58:12 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: split regex
Message-Id: <FwuG90.6In@news.boeing.com>

In article <8jbf0k$mvn$1@kira.cc.uakron.edu>, Todd W <trw@uakron.edu> wrote:
>I am trying to figure out how to split on only the last two underscores in
>my string. Any1 mind helping? Thanks in advance.
>

my $some_string = ...

my $one  = '(?:[^_]*_?[^_]*$)'; # one other underscore 
my $none = '(?:[^_]*$)';        # no more underscores

my @split = split( /    _       # split on an underscore  
                     (?=        # if via lookahead there's  
                         $one   #    one more underscore 
                           |    #           or
                         $none  #    no more underscores
                     )
                   /x, $some_string  
                 );


--
Charles DeRykus


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

Date: Wed, 28 Jun 2000 02:30:48 GMT
From: mgjv@verbruggen.comdyn.com.au (Martien Verbruggen)
Subject: Re: Teen Volenteers WANTED
Message-Id: <slrn8lioqc.5cs.mgjv@verbruggen.comdyn.com.au>

On Wed, 28 Jun 2000 00:09:35 GMT,
	Keith Calvert Ivey <kcivey@cpcug.org> wrote:
> bart.lateur@skynet.be (Bart Lateur) wrote:
> >
> >Hey? Do you know of a spell checker that is aware of the fact that XML
> >and HTML are not computer languages?
> 
> They're not programming languages, but I wouldn't say they're
> not computer languages.

They're not languages in the same way red paint is not a language.
They're markup.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | I'm just very selective about what I
Commercial Dynamics Pty. Ltd.   | accept as reality - Calvin
NSW, Australia                  | 


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

Date: 27 Jun 2000 22:53:29 EDT
From: abigail@delanet.com (Abigail)
Subject: Re: Teen Volenteers WANTED
Message-Id: <slrn8lir76.ka1.abigail@alexandra.delanet.com>

Martien Verbruggen (mgjv@verbruggen.comdyn.com.au) wrote on MMCDXCIII
September MCMXCIII in <URL:news:slrn8lioqc.5cs.mgjv@verbruggen.comdyn.com.au>:
'' On Wed, 28 Jun 2000 00:09:35 GMT,
'' 	Keith Calvert Ivey <kcivey@cpcug.org> wrote:
'' > bart.lateur@skynet.be (Bart Lateur) wrote:
'' > >
'' > >Hey? Do you know of a spell checker that is aware of the fact that XML
'' > >and HTML are not computer languages?
'' > 
'' > They're not programming languages, but I wouldn't say they're
'' > not computer languages.
'' 
'' They're not languages in the same way red paint is not a language.
'' They're markup.


No, they are not markup, for the same reason Perl variables aren't
the language.

Hint: HTML and XML aren't just pretty tokens. The different letters
actually stand for something. Including the L.


Abigail
-- 
perl5.004 -wMMath::BigInt -e'$^V=Math::BigInt->new(qq]$^F$^W783$[$%9889$^F47]
 .qq]$|88768$^W596577669$%$^W5$^F3364$[$^W$^F$|838747$[8889739$%$|$^F673$%$^W]
 .qq]98$^F76777$=56]);$^U=substr($]=>$|=>5)*(q.25..($^W=@^V))=>do{print+chr$^V
%$^U;$^V/=$^U}while$^V!=$^W'


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

Date: Wed, 28 Jun 2000 03:08:33 GMT
From: Bella <bellamy_walton@my-deja.com>
Subject: Re: Using link checking scripts with Dynamo server (newbie question)
Message-Id: <8jbq77$eii$1@nnrp1.deja.com>

In article <Pine.GHP.4.21.0006232238150.13079-100000@hpplus03.cern.ch>,
  "Alan J. Flavell" <flavell@mail.cern.ch> wrote:
> On Fri, 23 Jun 2000, Bella wrote:
>
> > > Of course, if your server doesn't follow the specs, that's another
> > > matter. In that case, replace the server. Cheers!
> >
> > And this helps my position how?
>
> Standards conformance.
>
> Open client-server protocols work best when the players conform to the
> published rules.  Tell that to Bill Gates when you next see him.

So how did Bill Gates get into this?  I'm talking about a Solaris
machine running Unix.


--
Bella...
"Experience is what you get when you don't get what you want"


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


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

Date: Wed, 28 Jun 2000 09:13:50 +0800
From: "Kwok Chi Hang" <chkwok@unitechnetworks.com>
Subject: Would the function win32::AdminMisc::ScheduleAdd works on the network?
Message-Id: <395950ff$1@newsgate.hknet.com>

I want to use the ScheduleAdd function in CGI, does it work?

$DOM = 2**3 | 2**20 | 2**31 ;
$DOW = FRIDAY | SUNDAY;
$Flags = JOB_ADD_CURRENT_DATE;
$Command = "dir";
$Job = Win32::AdminMisc::ScheduleAdd("\\\\CMS1", "19:30", $DOM, $DOW, $Flags
,         $Command) || &error();

sub error{
my $errmsg = Win32::FormatMessage(Win32::GetLastError());
print "Error: $errmsg\n";

}

The result is: "Error: The system could not find the environment option that
was entered "
What's wrong?
Thanks




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

Date: Wed, 28 Jun 2000 01:37:37 GMT
From: Damani Walton <damani@world.std.com>
Subject: XS and C structures question
Message-Id: <v9k8fabn6m.fsf@world.std.com>


I'm trying pass a structure from C to Perl (5.00503) using XS as the
glue and am not having much luck.  I'm getting a blessed reference
corresponding to the struct, but I can't figure out how to access any
of struct's members. 

As a test I used the function getpwnam() from the pwd.h library.

	struct passwd *getpwnam(const char *name);

passwd has this makeup:

	struct passwd {
		char *pw_name;
		char *pw_passwd;
		uid_t     pw_uid;
		gid_t     pw_gid;
		char *pw_age;
		char *pw_comment;
		char *pw_gecos;
		char *pw_dir;
		char *pw_shell;
	};


I inserted the following code in my .xs file, based on what I found in
the perlxs manpage: 

	#include <pwd.h>

	typedef struct passwd Pwd;

	<snip>

	Pwd *
	getpwnam(username)
	        char *	username
	        OUTPUT:
	        RETVAL

and added the following typemap:

	Pwd *   T_PTROBJ

After running "make", I do "$foo = module_name::getpwnam('root')" and
see that $foo is a reference to something blessed as PwdPtr, but if I
try to get at the data with something like "$foo->pw_uid", I get an
error saying that there is no method "pw_uid".  I've tried writing
custom structs and C functions to return those structs and I've tried
minor variations in the XSUB, but the results are similar. 

What is it that I'm missing?


Thanks in advance,

Damani


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

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


Administrivia:

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

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

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

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V9 Issue 3496
**************************************


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