[9417] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3008 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jun 30 13:57:34 1998

Date: Tue, 30 Jun 98 10:40:46 -0700
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, 30 Jun 1998     Volume: 8 Number: 3008

Today's topics:
        beginner looking for example perl scripts <cjflaherty@ra.rockwell.com>
    Re: beginner looking for example perl scripts <tchrist@mox.perl.com>
    Re: beginner looking for example perl scripts birgitt@my-dejanews.com
    Re: beginner looking for example perl scripts <quednauf@nortel.co.uk>
    Re: beginner looking for example perl scripts (Jeremy  A Horland)
        C lib to link with Perl5 <Claustres@mail.dotcom.fr>
        Cache Terminator <katigaebler@hotmail.com>
    Re: Cache Terminator (Jonathan Stowe)
        Calling a script within a script <ozslot@alphalink.com.au>
    Re: Calling a script within a script (brian d foy)
        Can a Script Tell its CPU Usage? (Steve Abatangle - shell)
    Re: Can a Script Tell its CPU Usage? <rra@stanford.edu>
    Re: Can a Script Tell its CPU Usage? <zenin@bawdycaste.org>
    Re: Can a Script Tell its CPU Usage? <jwb79@mail.idt.net>
        Can I access files on multiple unix stations from withi <dufour@cn.ca>
    Re: Can I access files on multiple unix stations from w <mgenti@evansville.net>
        can't figure out part of regular expression (Ralph Brands)
    Re: can't figure out part of regular expression (Craig Berry)
    Re: can't figure out part of regular expression <*@qz.to>
    Re: can't figure out part of regular expression (Mike Stok)
    Re: can't figure out part of regular expression (Kevin Reid)
    Re: can't figure out part of regular expression (Tad McClellan)
    Re: Catching divide-by-zero <r11630@email.sps.mot.com>
        change directory in perl waikei@my-dejanews.com
        change directory in perl waikei@my-dejanews.com
        change key in hash gunnar.djurberg@front.se
    Re: change key in hash <rra@stanford.edu>
        Changing characters (Peter)
    Re: Changing characters <zmalino@free.polbox.pl>
    Re: Changing characters <rootbeer@teleport.com>
        Checking for diskette present under Windows <vdaniels@nji.com>
    Re: Checking if a file does NOT exist <sloh@palisade.com>
        Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Mon, 29 Jun 1998 12:33:08 -0400
From: Christian Flaherty <cjflaherty@ra.rockwell.com>
Subject: beginner looking for example perl scripts
Message-Id: <3597C1C4.13FE8FA@ra.rockwell.com>

Hello,

    I am new to perl programming and I was wondering where I could find
some basic
    perl programs to look at.  Also, I specifically am looking for an
example program that
    will search through a directory tree and list out file information
such as: owner, size,
    and name.  If anyone has such a program or knows where I could find
one, I would
    greatly appreciate it.  Thanks in advance...

Chris

cjflaherty@ra.rockwell.com



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

Date: 29 Jun 1998 17:22:05 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: beginner looking for example perl scripts
Message-Id: <6n8ift$5bu$4@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

 [trimmed crossposting to inappropriate modules group]

In comp.lang.perl.misc, 
    Christian Flaherty <cjflaherty@ra.rockwell.com> writes:
:    I am new to perl programming and I was wondering where I could find
:some basic [BADWRAP]
:    perl programs to look at.  Also, I specifically am looking for an
:example program that [BADWRAP]
:    will search through a directory tree and list out file information
:such as: owner, size, [BADWRAP]
:    and name.  If anyone has such a program or knows where I could find
:one, I would [BADWRAP]
:    greatly appreciate it.  Thanks in advance...


#!/usr/bin/perl
# lst - list sorted directory contents (depth first)

use Getopt::Std;
use File::Find;
use File::stat;
use User::pwent;
use User::grent;

getopts('lusrcmi')				or die <<DEATH;
Usage: $0 [-mucsril] [dirs ...]
 or    $0 -i [-mucsrl] < filelist

Input format:
    -i  read pathnames from stdin
Output format:
    -l  long listing
Sort on:
    -m  use mtime (modify time) [DEFAULT]
    -u  use atime (access time)
    -c  use ctime (inode change time)
    -s  use size for sorting
Ordering:
    -r  reverse sort
NB: You may only use select one sorting option at a time.
DEATH
    
unless ($opt_i || @ARGV) { @ARGV = ('.') }

if ($opt_c + $opt_u + $opt_s + $opt_m > 1) {
    die "can only sort on one time or size";
}

$IDX = 'mtime';
$IDX = 'atime' if $opt_u;
$IDX = 'ctime' if $opt_c;
$IDX = 'size'  if $opt_s;

$TIME_IDX = $opt_s ? 'mtime' : $IDX;

*name = \$File::Find::name;  # forcibly import that variable

# the $opt_i flag tricks wanted into taking
# its filenames from ARGV instead of being
# called from find.

if ($opt_i) {
     *name = *_;  # $name now alias for $_
     while (<>) { chomp; &wanted; }   # ok, not stdin really
}  else {
    find(\&wanted, @ARGV);
}

# sort the files by their cached times, youngest first
@skeys = sort { $time{$b} <=> $time{$a} } keys %time;

# but flip the order if -r was supplied on command line
@skeys = reverse @skeys if $opt_r;

for (@skeys) {
    unless ($opt_l) {  # emulate ls -l, except for permissions
	print "$_\n";
	next;
    }
    $now = localtime $stat{$_}->$TIME_IDX();
    printf "%6d %04o %6d %8s %8s %8d %s %s\n",
	    $stat{$_}->ino(),
	    $stat{$_}->mode() & 07777,
	    $stat{$_}->nlink(),
	    user($stat{$_}->uid()),
	    group($stat{$_}->gid()),
	    $stat{$_}->size(),
	    $now, $_;
}

# get stat info on the file, saving the desired
# sort criterion (mtime, atime, ctime, or size)
# in the %time hash indexed by filename.
# if they want a long list, we have to save the
# entire stat object in %stat.  yes, this is a
# hash of objects
sub wanted {
    my $sb = stat($_);  # XXX: should be stat or lstat?
    return unless $sb;
    $time{$name} = $sb->$IDX();  # indirect method call
    $stat{$name} = $sb if $opt_l;
}

# cache user number to name conversions
sub user {
    my $uid = shift;
    $user{$uid} = getpwuid($uid)->name || "#$uid"
	unless defined $user{$uid};
    return $user{$uid};
}

# cache group number to name conversions
sub group {
    my $gid = shift;
    $group{$gid} = getgrgid($gid)->name || "#$gid"
	unless defined $group{$gid};
    return $group{$gid};
}

-- 
    echo "Your stdio isn't very std."
            --Larry Wall in Configure from the perl distribution


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

Date: Mon, 29 Jun 1998 21:00:27 GMT
From: birgitt@my-dejanews.com
Subject: Re: beginner looking for example perl scripts
Message-Id: <6n8v9c$1tt$1@nnrp1.dejanews.com>

In article <6n8ift$5bu$4@csnews.cs.colorado.edu>,
  tchrist@mox.perl.com (Tom Christiansen) wrote:
>
>  [courtesy cc of this posting sent to cited author via email]
>
>  [trimmed crossposting to inappropriate modules group]
>
> In comp.lang.perl.misc,
>     Christian Flaherty <cjflaherty@ra.rockwell.com> writes:
> :    I am new to perl programming and I was wondering where I could find
> :some basic [BADWRAP]

[snipped unwrapped stuff]

>
> #!/usr/bin/perl
> # lst - list sorted directory contents (depth first)
>
> use Getopt::Std;
> use File::Find;
> use File::stat;
> use User::pwent;
> use User::grent;

[snipped a too good to be true answer]

I wished the "What a crappy world"-crowd just would read
answers like the above from T.C. too and understand their
meaning.

Do you need a "Thank You" ? Have a couple to give away. :-)

Birgitt Funk

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum


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

Date: Tue, 30 Jun 1998 09:56:58 +0100
From: "F.Quednau" <quednauf@nortel.co.uk>
Subject: Re: beginner looking for example perl scripts
Message-Id: <3598A85A.F3751282@nortel.co.uk>

Tom Christiansen wrote:
> 
>  [courtesy cc of this posting sent to cited author via email]
> 
>  [trimmed crossposting to inappropriate modules group]
> 

> 
> #!/usr/bin/perl
> # lst - list sorted directory contents (depth first)

[Good example script]

You've got everything here (Well, not everything, but a lot). Conditionals (? :
, unless, if), a very neat way to drop out of the program (<<DEATH, DEATH), lots
of conditionals ( ||, etc.), usage of Modules (arrow operator, focibly pulling
in parts of the module), passing of subroutines to others, subroutines, sorting
a hash, using functions on their default variables, etc., etc. 
That should give quite a few people a lot to chew through :)

-- 
____________________________________________________________
Frank Quednau               
http://www.surrey.ac.uk/~me51fq
________________________________________________


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

Date: 30 Jun 1998 13:58:34 GMT
From: jhorland@environments.com (Jeremy  A Horland)
Subject: Re: beginner looking for example perl scripts
Message-Id: <jhorland-ya02408000R3006981006040001@news.interport.net>

In article <3597C1C4.13FE8FA@ra.rockwell.com>, Christian Flaherty
<cjflaherty@ra.rockwell.com> wrote:

> Hello,
> 
>     I am new to perl programming and I was wondering where I could find
> some basic
>     perl programs to look at.  Also, I specifically am looking for an
SNIP

Chris - 


Try www.extropia.com and go for the "scripts"


Jeremy


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

Date: Tue, 30 Jun 1998 18:54:05 +0200
From: "Francois Claustres" <Claustres@mail.dotcom.fr>
Subject: C lib to link with Perl5
Message-Id: <6nb5ag$6gu$1@platane.wanadoo.fr>

Hello!

Nobody knows how to link a C library with Perl5, which is like this:

- thelib.h for the headers.
- thelib.a for the code.

I found some informations in the HTML documentation given with Perl (e.g.
perlxs.html, perxstut.html), but it doesn't seem to apply to my specific
case (not having the sources of the C code).

The answer maybe very simple, but as I don't master C very well, I can't
link this C library with Perl! :-(

Thanks in advance for your help!

Francois.




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

Date: Sun, 28 Jun 1998 12:39:35 +0200
From: Kati Gaebler <katigaebler@hotmail.com>
Subject: Cache Terminator
Message-Id: <35961D67.6A24DAEF@hotmail.com>

Hello,

I received one suggestion how to
eliminate a cache problem. See META
suggestion (below mail).

I inserted the suggested META command on a Site and
tested reading with Netscape
(3.04 and 4.0 on Linux and Windows).

But web pages were still accessed via the cache!!

Anyone knows a solution maybe in Perl or SSI
or Javascript that make browsers always
access server version of Sites.

           Kati Gaebler
           katigaebler@hotmail.com

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

Date: Sat, 20 Jun 1998 14:02:46 +0200 (MESZ)
From: Matthias Richter <soz97cyn@studserv.uni-leipzig.de>
To: Kati Gaebler <katigaebler@hotmail.com>
Subject: Re: Javascript Cache Eliminator

Hi,

You do not even need Javascript for this :o) just
add the line <META HTTP-EQUIV="Pragma" Content="Nocache">
in the <HEAD></HEAD> of the document.

            Matthias

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

Date: Wed, 24 Jun 1998 10:23:59 +0200
To: katigaebler@hotmail.com
From: Danko Greiner <greiner@fly.cc.fer.hr>
Subject: Clear cache

I saw your message at comp.lang.javascript newsgroup

Did you find the answer to your ploblem, a need same thing.
I am using frames too,so when user clicks "reload" he
reloads just frame page not both frames!

please help!

Thanx.

Greetings from Croatia


----Original question----

>Can Javascript tell a browser not first to look
>in the cache for a Site, or not to store it in
>the cache in the first place?

>I am making a Site which is always updated, I
>dont want the visitors having to clear the
>cache or hit reload for every page they visit
>in case its their second time around.



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

Date: Sun, 28 Jun 1998 11:29:12 GMT
From: Gellyfish@btinternet.com (Jonathan Stowe)
Subject: Re: Cache Terminator
Message-Id: <359627b1.3134734@news.btinternet.com>

On Sun, 28 Jun 1998 12:39:35 +0200, Kati Gaebler wrote :

>Hello,
>
>I received one suggestion how to
>eliminate a cache problem. See META
>suggestion (below mail).
>
>I inserted the suggested META command on a Site and
>tested reading with Netscape
>(3.04 and 4.0 on Linux and Windows).
>
>But web pages were still accessed via the cache!!
>
>Anyone knows a solution maybe in Perl or SSI
>or Javascript that make browsers always
>access server version of Sites.
>

This is probably not a Perl question at all - I mean you can always
ask the user to get their browser to refresh the page if its
important.

However if you want to do this sort of thing in CGI (again not Perl
specific) you should review the HTTP specification and also examine
the documentation for CGI.pm on how to manipulate HTTP header fields.

/J\
Jonathan Stowe
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>



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

Date: Wed, 01 Jul 1998 01:27:17 +1000
From: David Hamilton <ozslot@alphalink.com.au>
Subject: Calling a script within a script
Message-Id: <359903D4.C1F5518F@alphalink.com.au>

Howdy all,

Sorry for this simple question, but is there a way to call a script that
produces an image in another perl script like an SSI exec call and
without having to copy the image producing script into the main script?

In summary, I need a command to insert the output of an external perl
program into the output being produced by the current main perl
program.  I need this info because my main script has the extention CGI
and due to the server config, it won't pay attention to SSI tags in a
 .cgi file. :(

Thanks,
>From David Hamilton



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

Date: Tue, 30 Jun 1998 11:47:18 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: Calling a script within a script
Message-Id: <comdog-3006981147180001@news.panix.com>
Keywords: just another new york perl hacker

In article <359903D4.C1F5518F@alphalink.com.au>, David Hamilton <ozslot@alphalink.com.au> posted:

> Sorry for this simple question, but is there a way to call a script that
> produces an image in another perl script like an SSI exec call and
> without having to copy the image producing script into the main script?

perhaps you wanted backticks (``), system(), or other things 
mentioned in perlipc or the FAQ.

good luck

-- 
brian d foy                                 <http://computerdog.com>
Comprehensive Perl Archive Network (CPAN) <URL:http://www.perl.com>
Perl Mongers <URL:http://www.pm.org>


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

Date: 28 Jun 1998 19:57:27 GMT
From: sabbat@area51.org (Steve Abatangle - shell)
Subject: Can a Script Tell its CPU Usage?
Message-Id: <6n6777$pdp$1@supernews.com>

Can a Perl script tell what percentage of the CPU it's using?
I don't mean CPU *time* -- that's available in times(). I want
to be able to tell that, say, I'm using > 25% of the CPU.

Is this possible? I've searched the camel book and CPAN, to no
avail.

Steve



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

Date: 28 Jun 1998 20:01:33 -0700
From: Russ Allbery <rra@stanford.edu>
Subject: Re: Can a Script Tell its CPU Usage?
Message-Id: <m3lnqgvrle.fsf@windlord.Stanford.EDU>

Steve Abatangle <sabbat@area51.org> writes:

> Can a Perl script tell what percentage of the CPU it's using?  I don't
> mean CPU *time* -- that's available in times(). I want to be able to
> tell that, say, I'm using > 25% of the CPU.

All of the programs that I know of that do that sort of thing (like top)
do a lot of often platform-specific sorts of things to derive that
information.  I would probably just run top and parse the output before
I'd try to do that.

Getting the current *load average*, on the other hand, is much easier
(just run uptime).

-- 
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
 00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print


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

Date: 29 Jun 1998 05:21:10 GMT
From: Zenin <zenin@bawdycaste.org>
Subject: Re: Can a Script Tell its CPU Usage?
Message-Id: <899098169.286364@thrush.omix.com>

Steve Abatangle - shell <sabbat@area51.org> wrote:
: Can a Perl script tell what percentage of the CPU it's using?
: I don't mean CPU *time* -- that's available in times(). I want
: to be able to tell that, say, I'm using > 25% of the CPU.
:
: Is this possible? I've searched the camel book and CPAN, to no
: avail.

	This is pretty platform dependant (as most answers likely
	will be, alas) but if you've got a BSD version of ps
	around (sometimes in /usr/ucb on SysV boxes) you can get
	this kind of info from it.
-- 
-Zenin
 zenin@archive.rhps.org


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

Date: 29 Jun 1998 07:16:26 GMT
From: "jim babbington" <jwb79@mail.idt.net>
Subject: Re: Can a Script Tell its CPU Usage?
Message-Id: <01bda32c$f546ac60$6488fdc7@dixon>


> Can a Perl script tell what percentage of the CPU it's using?
> I don't mean CPU *time* -- that's available in times(). I want
> to be able to tell that, say, I'm using > 25% of the CPU.

If your not on an SMP, then you could compare CPU time with
actuall time. 

$cpu_percent = $cpu_time / $real_time ;

So, say 10 minutes have elapsed, and use used 2 cpu minites, then your 
cpu percentage would be 20%.  

If your a lucky owner of an SMP box, you could normalize by the number of 
processors you have ....

$cpu_percent = (($cpu_time / $time_elapsed) / $number_of_processors) ;

This is guessing, but thats OK, because no program can accurately account 
for resources used, without consuming them all for themselves. 

Truth_in_statistics - your cpu time numbers, no matter who gives them to
you,
are subject to 101% margin of error - But, hey, thats the best we can do.

Jim



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

Date: Mon, 29 Jun 1998 11:30:11 -0400
From: J-Sebastien Dufour <dufour@cn.ca>
Subject: Can I access files on multiple unix stations from within 1 CGI program?
Message-Id: <3597B303.12BB354B@cn.ca>

I'm currently running this CGI program on this unix station called
wild-dc2.  Now when I use the filepath within the program : /usr/etc/ it
is defaulted to the wild-dc2 unix station and so with the following
would access the hosts file on the wild-dc2 station : /usr/etc/hosts.
However, how would I lets say access the hosts file from the wwwstlaw
station?  What path would I use?  I've tried numerous ways of accessing
files from the wwwstlaw but nothing seems to work unless I run the
program on the station itself.  So how do we access files from unix
stations other than the one the CGI program is running on?



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

Date: Mon, 29 Jun 1998 12:12:46 -0500
From: "Mark Guagenti" <mgenti@evansville.net>
Subject: Re: Can I access files on multiple unix stations from within 1 CGI program?
Message-Id: <6n8i8b$mvl$1@supernews.com>

J-Sebastien Dufour wrote in message <3597B303.12BB354B@cn.ca>...
>I'm currently running this CGI program on this unix station called
>wild-dc2.  Now when I use the filepath within the program : /usr/etc/ it
>is defaulted to the wild-dc2 unix station and so with the following
>would access the hosts file on the wild-dc2 station : /usr/etc/hosts.
>However, how would I lets say access the hosts file from the wwwstlaw
>station?  What path would I use?  I've tried numerous ways of accessing
>files from the wwwstlaw but nothing seems to work unless I run the
>program on the station itself.  So how do we access files from unix
>stations other than the one the CGI program is running on?


I would say that the easiest way of doing this would be to mount the remote
file system(wwstlaw) on to the computer running your CGI program(wild-dc2).

Mark




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

Date: 29 Jun 1998 17:00:02 GMT
From: brinton@unixg.ubc.ca (Ralph Brands)
Subject: can't figure out part of regular expression
Message-Id: <brinton-2906980953230001@p041.intchg1.net.ubc.ca>

A while ago I asked a question here about how to extend the definition of
word boundaries in regular expressions to include the "&" and ";"
characters (searching a corpus in which Old English characters are
delimited this way). So "the&ae;" can be one word. Someone suggested that
instead of searching for 

        \bWORD\b

I should search for 

         (^|[^A-Za-z0-9&;])WORD([^A-Za-z0-9&;]|$)

This works just fine, but I just can't figure out why the "|" has to be
there with each of the anchoring patterns "^" and "$". I've searched high
and low in the perlre docs, "Teach Yourself Perl" etc, and can't figure it
out.

What's it doing there? I can't see that it can be an "or" operator.

Many thanks,

Ralph Brands


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

Date: 29 Jun 1998 18:08:10 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: can't figure out part of regular expression
Message-Id: <6n8l6a$1d9$4@marina.cinenet.net>

Ralph Brands (brinton@unixg.ubc.ca) wrote:
: A while ago I asked a question here about how to extend the definition of
: word boundaries in regular expressions to include the "&" and ";"
: characters (searching a corpus in which Old English characters are
: delimited this way). So "the&ae;" can be one word. Someone suggested that
: instead of searching for 
: 
:         \bWORD\b
: 
: I should search for 
: 
:          (^|[^A-Za-z0-9&;])WORD([^A-Za-z0-9&;]|$)
: 
: This works just fine, but I just can't figure out why the "|" has to be
: there with each of the anchoring patterns "^" and "$". I've searched high
: and low in the perlre docs, "Teach Yourself Perl" etc, and can't figure it
: out.
: 
: What's it doing there? I can't see that it can be an "or" operator.

See perlre; I just searched through it on | and found most of what you'd
want to know.

Briefly, | is almost an 'or' operator; it's called 'alternation' in
regexpese.  The pattern above says "Look for either start-of-string *or* a
character not in [list], followed by 'WORD', followed by either a
character not in [list] *or* end-of-string."  Note the way parens are used
to group the alternations. 

---------------------------------------------------------------------
   |   Craig Berry - cberry@cinenet.net
 --*--    Home Page: http://www.cinenet.net/users/cberry/home.html
   |      Member of The HTML Writers Guild: http://www.hwg.org/   
       "Every man and every woman is a star."


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

Date: 29 Jun 1998 18:25:39 GMT
From: Eli the Bearded <*@qz.to>
Subject: Re: can't figure out part of regular expression
Message-Id: <eli$9806291416@qz.little-neck.ny.us>

In comp.lang.perl.misc, Ralph Brands <brinton@unixg.ubc.ca> wrote:
[snip why]
>          (^|[^A-Za-z0-9&;])WORD([^A-Za-z0-9&;]|$)
> 
> This works just fine, but I just can't figure out why the "|" has to be
> there with each of the anchoring patterns "^" and "$". I've searched high
> and low in the perlre docs, "Teach Yourself Perl" etc, and can't figure it
> out.
> 
> What's it doing there? I can't see that it can be an "or" operator.

It is an 'or' for alternating between the two boundary conditions
allowed in each case: the start of the line OR the boundary character,
and the boundary character OR the end of the line.

	m%			# begin RE
				#
	  (			# begin group one
	     ^			# start of line
	   |			# OR
	     [^A-Za-z0-9&;]	# a character not from this range
	  )			# end greoup one
				#
	     WORD		# word to match
				#
	  (			# begin group two
	     [^A-Za-z0-9&;]	# a character not from this range
	   |			# OR
	     $			# end of line
	  )			# end greoup two
				#
	 %x;			# end RE; /x for extended format

Elijah
------
would probably be using (?: ... ) paren groups there


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

Date: 29 Jun 1998 19:38:15 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: can't figure out part of regular expression
Message-Id: <6n8qf7$9ee@news-central.tiac.net>

In article <brinton-2906980953230001@p041.intchg1.net.ubc.ca>,
Ralph Brands <brinton@unixg.ubc.ca> wrote:

 [...]
>        \bWORD\b
>
>I should search for 
>
>         (^|[^A-Za-z0-9&;])WORD([^A-Za-z0-9&;]|$)
>
>This works just fine, but I just can't figure out why the "|" has to be
>there with each of the anchoring patterns "^" and "$". I've searched high
>and low in the perlre docs, "Teach Yourself Perl" etc, and can't figure it
>out.
>
>What's it doing there? I can't see that it can be an "or" operator.

That's because a word boundary can happen between word & non-word
characters *or* when the word butts up against the end of the string.
Even negated character classes match against a character, and the ends of
the string will not match the class 'cos they aren't characters - consider 
$string = 'WORD' and why $string =~ /[^A-Za-z0-9&;]WORD[^A-Za-z0-9&;]/
wouldn't match.

Hope this helps,

Mike
-- 
mike@stok.co.uk                    |           The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/       |   PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/    |                   65 F3 3F 1D 27 22 B7 41
stok@colltech.com                  |            Collective Technologies (work)


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

Date: Mon, 29 Jun 1998 16:52:55 -0400
From: kpreid@ibm.net (Kevin Reid)
Subject: Re: can't figure out part of regular expression
Message-Id: <1dbdzrn.7nz5sx1nbf39cN@slip166-72-108-122.ny.us.ibm.net>

Ralph Brands <brinton@unixg.ubc.ca> wrote:

> A while ago I asked a question here about how to extend the definition of
> word boundaries in regular expressions to include the "&" and ";"
> characters (searching a corpus in which Old English characters are
> delimited this way). So "the&ae;" can be one word. Someone suggested that
> instead of searching for 
> 
>         \bWORD\b
> 
> I should search for 
> 
>          (^|[^A-Za-z0-9&;])WORD([^A-Za-z0-9&;]|$)
> 
> This works just fine, but I just can't figure out why the "|" has to be
> there with each of the anchoring patterns "^" and "$". I've searched high
> and low in the perlre docs, "Teach Yourself Perl" etc, and can't figure it
> out.
> 
> What's it doing there? I can't see that it can be an "or" operator.

It sort of is. That represents alternation, which means that
(^|[^A-Za-z0-9&;]) matches either ^ or [^A-Za-z0-9&;].

The reason it is there is so that the beginning of the string will be
considered to be a word boundary.

-- 
  Kevin Reid.      |         Macintosh.
   "I'm me."       |      Think different.


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

Date: Mon, 29 Jun 1998 16:19:21 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: can't figure out part of regular expression
Message-Id: <pc09n6.de4.ln@localhost>

Ralph Brands (brinton@unixg.ubc.ca) wrote:
: A while ago I asked a question here about how to extend the definition of
: word boundaries in regular expressions to include the "&" and ";"
: characters (searching a corpus in which Old English characters are
: delimited this way). So "the&ae;" can be one word. Someone suggested that
: instead of searching for 

:         \bWORD\b

: I should search for 

:          (^|[^A-Za-z0-9&;])WORD([^A-Za-z0-9&;]|$)
              ^^^^^^^^^^^^^^

   you also need an underscore in there if you want the effect of
   [\w&;] (underscore matches \w, and \b is defined in terms of \w)



: This works just fine, but I just can't figure out why the "|" has to be
: there with each of the anchoring patterns "^" 


   In case the WORD is at the beginning of the string.

   Take out the ^| and try it with    $_ = 'WORD here';

   There is no char to match your first char class there,
   so you need an alternation (or) that matches the beginning
   of the string.

: and "$". 

   In case the WORD is at the end of the string.

: I've searched high
: and low in the perlre docs, "Teach Yourself Perl" etc, and can't figure it
: out.

: What's it doing there? I can't see that it can be an "or" operator.


   Ahh, but it is.

   You probably "see" it now though? ...


: Many thanks,


   You're welcome.


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


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

Date: Mon, 29 Jun 1998 08:53:56 +0100
From: Michael Scott <r11630@email.sps.mot.com>
Subject: Re: Catching divide-by-zero
Message-Id: <35974814.7ECF62E6@email.sps.mot.com>

Hi everyone.
Firstly, my apologies for the vmail/address book card crap in my original
posting - I (hope) this is now firmly turned off. That's the trouble when Big
Bad Corporate Company insist that you use Netscape for Everything.

I now have the original SIG-handler working, the problem was with my search path
- I had another foo.pl lying about. I can get the correct message printed now.
But I agree, the eval method is the way to go.

Michael Scott.


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

Date: Tue, 30 Jun 1998 10:57:20 GMT
From: waikei@my-dejanews.com
Subject: change directory in perl
Message-Id: <6nagag$dhv$1@nnrp1.dejanews.com>

Hi,

        I want to write a script which is used to change the working
        directory.  The problem is:  After the script run, the working
        dir. is back to the original dir. but actually I want to stay
        in the new working directory.  I change the dir. by the function
        chdir.  Could anyone kindly give me some hints?

Regards,
Wilbur

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum


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

Date: Tue, 30 Jun 1998 11:02:49 GMT
From: waikei@my-dejanews.com
Subject: change directory in perl
Message-Id: <6nagkp$e0d$1@nnrp1.dejanews.com>

Hi,

        I want to write a script which is used to change the working
        directory.  The problem is:  After the script run, the working
        dir. is back to the original dir. but actually I want to stay
        in the new working directory.  I change the dir. by the function
        chdir.  Could anyone kindly give me some hints?

Regards,
Wilbur

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum


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

Date: Tue, 30 Jun 1998 08:31:49 GMT
From: gunnar.djurberg@front.se
Subject: change key in hash
Message-Id: <6na7pm$3n2$1@nnrp1.dejanews.com>

Let's say I detect an incorrect key in a large hash. Is there a way to change
just that key, without creating the entire hash anew?

Also I would like to know if there are ways to "cast" hashes to arrays. (I
know that it is possible to write %hash = @arr;)


Gunnar Djurberg

gunnar.djurberg@front.se

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum


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

Date: 30 Jun 1998 01:42:55 -0700
From: Russ Allbery <rra@stanford.edu>
Subject: Re: change key in hash
Message-Id: <m31zs7z3e8.fsf@windlord.Stanford.EDU>

gunnar djurberg <gunnar.djurberg@front.se> writes:

> Let's say I detect an incorrect key in a large hash. Is there a way to
> change just that key, without creating the entire hash anew?

Um, how do you mean?  Like:

        $hash{'good_key'} = $hash{'bad_key'};
        delete $hash{'bad_key'};

?  Sure, you can do that.

> Also I would like to know if there are ways to "cast" hashes to
> arrays. (I know that it is possible to write %hash = @arr;)

A hash in a list context turns into a list whose elements are the keys
interspersed with the values.  In other words, if you have the hash:

        %hash = ('a' => 1, 'b' => 2, 'c' => 3);

and you do:

        @list = %hash;

then @list will contain ('a', 1, 'b', 2, 'c', 3).  If that isn't what you
want, look at the keys and values functions.

-- 
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
 00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print


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

Date: Tue, 30 Jun 1998 10:35:01 +0200
From: oav95auz@lustudat.student.lu.se (Peter)
Subject: Changing characters
Message-Id: <oav95auz-3006981035010001@du73-98.ppp.algonet.se>

Hi!

I need help for solution of the following problem: How can I change
characters (e.g. vde) in a string to e.g. oaa? (Perl)

$string_old=vldkem

???...

$string_new=olakam

Thanks for your help!

Peter


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

Date: Tue, 30 Jun 1998 09:44:23 GMT
From: "Zbigniew Malinowski" <zmalino@free.polbox.pl>
Subject: Re: Changing characters
Message-Id: <Xr2m1.3467$D7.1538052@news.tpnet.pl>


Peter napisa3(a) w wiadomoci: ...
>Hi!
>
>I need help for solution of the following problem: How can I change
>characters (e.g. vde) in a string to e.g. oaa? (Perl)
>
>$string_old=vldkem
>
>???...
>
>$string_new=olakam
>
>Thanks for your help!
>
>Peter

Peter !

You should try :

$string =~ tr/vde/oaa/ ;

Hope it helps .

Zbyszek Malinowski




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

Date: Tue, 30 Jun 1998 09:27:08 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: Changing characters
Message-Id: <Pine.GSO.3.96.980630022626.17225X-100000@user2.teleport.com>

On Tue, 30 Jun 1998, Peter wrote:

> How can I change characters (e.g. =F6=E4=E5) in a string to e.g. oaa? (Pe=
rl)=20

You probably want either the tr/// or the s/// operator. See the perlop
manpage to decide which. Hope this helps!

--=20
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Tue, 30 Jun 1998 01:20:31 GMT
From: Vince Daniels <vdaniels@nji.com>
Subject: Checking for diskette present under Windows
Message-Id: <35983D5E.A110E24B@nji.com>

I would like to check my floppy drive for the presence of a diskette.
This in it self is not a problem
except that Windows 95/NT will popup a window asking me to put a disk in
the drive, abort, or
ignore and waits for a response.  I just want the program to
automatically move on if there's no
floppy.  Anybody know of a way to do this with Perl?  I have tried
checking for the existence of a file
on the disk, checking for the existence of the directory path (a:\),
attempting to read a file, opendir,
etc.  All result in this stupid popup. . .

Thanks

Vince Daniels



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

Date: Mon, 29 Jun 1998 17:06:11 -0500
From: Stanton Loh <sloh@palisade.com>
Subject: Re: Checking if a file does NOT exist
Message-Id: <35980FD3.2DA6C430@palisade.com>

Larry Rosler wrote:
> 
> In article <3593B6D9.B8611142@palisade.com>, Stanton Loh
> <sloh@palisade.com> says...
> >
> > unless (-s $filename) {
> >    #blah
> > }
> 
> That test fails if the file exists but has zero length.  You really

The original poster said: 

>> #  insert JavaScript alert("$file doesnt exist or has 0 byte
>> size! doh!"); 

which I mistakenly interpreted to mean he wanted to execute some
statements if either the file a) did not exist or b) existed but
had zero length.

-Stanton


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

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


Administrivia:

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

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.

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

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

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

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 V8 Issue 3008
**************************************

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