[28581] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 9945 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Nov 9 14:05:50 2006

Date: Thu, 9 Nov 2006 11:05:08 -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           Thu, 9 Nov 2006     Volume: 10 Number: 9945

Today's topics:
    Re: how to load 'formats' from a file anno4000@radom.zrz.tu-berlin.de
    Re: how to load 'formats' from a file <bol@adv.magwien.gv.at>
    Re: How to reference memory address returned from Win32 <sisyphus1@nomail.afraid.org>
        how to source an environment file dcruncher4@aim.com
    Re: how to source an environment file anno4000@radom.zrz.tu-berlin.de
    Re: how to source an environment file <rvtol+news@isolution.nl>
    Re: how to source an environment file <nobull67@gmail.com>
        id3 tag reader and file name editor? <sameerkumarkaushik@gmail.com>
    Re: IPv4 address validation in Net::IP <joe@inwap.com>
    Re: Newbie perl question <michael_perle@yahoo.com>
    Re: PERL can't open file for logging (world writable di <premgrps@gmail.com>
    Re: PERL can't open file for logging (world writable di <sisyphus1@nomail.afraid.org>
    Re: PERL can't open file for logging (world writable di <tadmc@augustmail.com>
        Perl Regex Query <superman183@hotmail.com>
    Re: Perl Regex Query <superman183@hotmail.com>
    Re: Perl Regex Query <noreply@gunnar.cc>
    Re: Perl Regex Query <glennj@ncf.ca>
    Re: Perl Regex Query <ben.usenet@bsb.me.uk>
    Re: Perl Regex Query <superman183@hotmail.com>
    Re: Perl Regex Query <noreply@gunnar.cc>
    Re: Perl Regex Query <superman183@hotmail.com>
    Re: Perl Regex Query <superman183@hotmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 9 Nov 2006 08:15:19 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: how to load 'formats' from a file
Message-Id: <4rg6cnFqtvc3U1@mid.dfncis.de>

Ben Morrow  <benmorrow@tiscali.co.uk> wrote in comp.lang.perl.misc:
> Quoth anno4000@radom.zrz.tu-berlin.de:

[...]

> > Otherwise, put your code above literally
> > into a file named Format1.pl.  Don't forget to add a final statement
> > "1;".
> > 
> > The main program could do (untested)
> > 
> >     our ( $title, $now, $content) =
> >         ( 'heading', scalar localtime, 'stuff');
> > 
> >     use Format1;
> 
> Umm, either you mean
> 
>     require 'Format1.pl';
> 
> or you meant Format1.pm above.

Thanks, the latter.

Anno


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

Date: Thu, 9 Nov 2006 17:06:22 +0100
From: "Ferry Bolhar" <bol@adv.magwien.gv.at>
Subject: Re: how to load 'formats' from a file
Message-Id: <1163088382.811547@proxy.dienste.wien.at>

Ben Morrow:

> ...and, of course, you have to bear in mind that formats, as
> filehandles, are package-scoped.

but one can say:

package foo;

format main::DYN_FORMAT =
<format spec here>
 .

to access format DYN_FORMAT in package main as usual.

And, as you wrote, one can use eval to define various formats
and select to requested one at run-time:

my $fmt1_req = 0; # or 1
my $fmtstr1 = "format MYFMT =\nFormat1: @<<<<\n\$var1\n.\n";
my $fmtstr2 = "format MYMFT =\nFormat2: @<<<<\n\$var2\n.\n";

eval ($fmt1_req ? $fmtstr1 : $fmtstr2);
write MYFMT;

Greetings, Ferry

-- 
Ing Ferry Bolhar
Magistrat der Stadt Wien - MA 14
A-1010 Wien
E-Mail: bol@adv.magwien.gv.at




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

Date: Fri, 10 Nov 2006 04:37:55 +1100
From: "Sisyphus" <sisyphus1@nomail.afraid.org>
Subject: Re: How to reference memory address returned from Win32::API call
Message-Id: <45536892$0$5105$afc38c87@news.optusnet.com.au>


"Sisyphus" <sisyphus1@nomail.afraid.org> wrote in message
news:4552973f$0$17211$afc38c87@news.optusnet.com.au...
>
> "cyl" <u8526505@gmail.com> wrote in message
> news:1162964481.986287.124270@h54g2000cwb.googlegroups.com...
 .
 .
> >  The returned buffer $lpServices
> > is an array of the structure ENUM_SERVICE_STATUS.

I misread that as stating that $lpServices is an ENUM_SERVICE_STATUS
structure.
Consequently what I wrote is possibly not as helpful as I had imagined.

>
>  You can create your SERVICE_STATUS
> struct as:
>
> my $service_status_struct = pack('LLLLLLL', 0, 0, 0, 0, 0, 0, 0);
>
> If any of those values need to be initialised to something other than
zero,
> then replace the zero with the appropriate value - but if the values are
> going to be set by the Call() then zeroes will be fine.
>
> You need to create an lpServiceName buffer (to a size that is at least as
> long as the string it will be set to):
>
> my $lpServiceName_buffer = " " x $size_of_lpServiceName; # or longer
>
> Similarly, for $lpDisplayName:
>
> my $lpDisplayName =  " " x $size_of_lpDisplayName; # or longer
>
> You can now create the $lpServices variable as follows:
>
> my $lpServices = pack('ppP', $lpServiceName, $lpDisplayName,
> $service_status_struct);
>

Having had a chance to play with the 'P' template a little, it now seems to
me that you need to specify the size of the structure - hence 'ppP' should
be changed to 'ppP28'.

 .
 .
>
> Then after the Call() you should be able to get at the values you want
with:
>
> ($lpServiceName, $lpDisplayName, $service_status_struct) = unpack ('ppP',
> $lpServices);
>

Again, the template would need to be 'ppP28'.

> If you want to then get at the values in $service_status_struct, you'll
need
> to also:
>
> @values = unpack('LLLLLL', $service_status_struct);
>

The template is 7 'L's - not 6, as appears there.

Cheers,
Rob




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

Date: 9 Nov 2006 06:52:24 -0800
From: dcruncher4@aim.com
Subject: how to source an environment file
Message-Id: <1163083944.521955.293620@k70g2000cwa.googlegroups.com>

I want my perl script to read a file containing environment variables
and source it back
to the script. That is, when the script is executed, these variables
are not defined
in enviroment. Once the script starts, variables defined in that env
file is sourced
in. In korn shell we can do
                dot(.) scriptname

How do we do the same in perl.

I found a crude approach. I do
system(". scriptname; env > /tmp/env.$$")
then I open /tmp/env.$$ file and store all env defined there
in $ENV{envvar}.

There should be a better way of doing it, shouldn't it?

thanks.



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

Date: 9 Nov 2006 15:37:59 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: how to source an environment file
Message-Id: <4rh0anFragg8U1@mid.dfncis.de>

 <dcruncher4@aim.com> wrote in comp.lang.perl.misc:
> I want my perl script to read a file containing environment variables
> and source it back
> to the script. That is, when the script is executed, these variables
> are not defined
> in enviroment. Once the script starts, variables defined in that env
> file is sourced
> in. In korn shell we can do
>                 dot(.) scriptname
> 
> How do we do the same in perl.
> 
> I found a crude approach. I do
> system(". scriptname; env > /tmp/env.$$")
> then I open /tmp/env.$$ file and store all env defined there
> in $ENV{envvar}.
> 
> There should be a better way of doing it, shouldn't it?

You can use less shell and more Perl.  You can also avoid the temp file.

    my $env_dump = qx(
        . scriptname;
        perl -MData::Dumper -e'print Dumper \\ %ENV'
    );

    %ENV = %{ our $VAR1; eval $env_dump };

Anno


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

Date: Thu, 9 Nov 2006 16:37:56 +0100
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: how to source an environment file
Message-Id: <eivlk9.234.1@news.isolution.nl>

dcruncher4@aim.com schreef:
> I want my perl script to read a file containing environment variables
> and source it back
> to the script. That is, when the script is executed, these variables
> are not defined
> in enviroment. Once the script starts, variables defined in that env
> file is sourced
> in. In korn shell we can do
>                 dot(.) scriptname
>
> How do we do the same in perl.
>
> I found a crude approach. I do
> system(". scriptname; env > /tmp/env.$$")
> then I open /tmp/env.$$ file and store all env defined there
> in $ENV{envvar}.
>
> There should be a better way of doing it, shouldn't it?

If you make that file look like
VAR1=test-A
VAR2="test B"
etc.

and then split per line on the first "=", you can update %ENV more
directly.

Or make it a shell-script that calls your perl-script last:

#!/bin/sh
VAR1=test-A
VAR2="test B"
myscript.pl

(untested)

-- 
Affijn, Ruud

"Gewoon is een tijger."



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

Date: 9 Nov 2006 10:19:22 -0800
From: "Brian McCauley" <nobull67@gmail.com>
Subject: Re: how to source an environment file
Message-Id: <1163096362.496131.137060@i42g2000cwa.googlegroups.com>



On Nov 9, 2:52 pm, dcrunch...@aim.com wrote:
> I want my perl script to read a file containing environment variables
> and source it back
> to the script. That is, when the script is executed, these variables
> are not defined
> in enviroment. Once the script starts, variables defined in that env
> file is sourced
> in. In korn shell we can do
>                 dot(.) scriptname
>
> How do we do the same in perl.

I always find this question ammuzing. The real, but totally unhelpful,
answer is that the nearest thing in Perl to Unix shells' "source"
command is do(FILE).  Of course that expect the file to be in Perl just
as ksh expected it to be in ksh (and bash would expect it in bash and
sh would ....)

 > I found a crude approach. I do
> system(". scriptname; env > /tmp/env.$$")
> then I open /tmp/env.$$ file and store all env defined there
> in $ENV{envvar}.

I think you can avoid the need for a temporary file with a pipe open.

  open(my $env_fh, '|-','. scriptname; env') or die $!;

> There should be a better way of doing it, shouldn't it?

Not really. If you want to execute a script written in another language
then somehow or other you are going to have to fire up and interpreter
for that laguage.

You can also exec a ksh interpreter and have that exec the perl
interpreter again. You do, of course, need to have an argument on your
second invocation of your script to tell it not to do this again!

Somthing like...

exec(". scriptname; exec $^X $0 -not_again ". join " ", map { quotemeta
} @ARGV );



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

Date: 9 Nov 2006 10:55:32 -0800
From: "kaushik" <sameerkumarkaushik@gmail.com>
Subject: id3 tag reader and file name editor?
Message-Id: <1163098532.750457.257640@m73g2000cwd.googlegroups.com>

Hi all,
 i am new to perl scripting. actually i didnt feel the need for it till
now. but now i think i need it. the problem is: i have a directory in
which i have thousands of mp3 songs(all in one directory). The file
names of the mp3files are incorrect. But the information in the ID3 tag
are proper with title, album name and genre entries. now what is, if a
run a script, the id3 tag of a file should be read, rename the file
name of the file to what is there in the title field and save it in a
folder(new/existing) of name as in Album entry. is it possible?
i have tried installing MP3::Tag module. but it is giving errors in
installation. some make file error.
http://builder.com.com/5100-6371-5293815.html
i'm getting this error message----
"
This program comes with several scripts which I would try to install in
directory C:\Perl\bin.
To skip, rerun with option -n given to Makefile.PL.
Checking if your kit is complete...
Looks good
Writing Makefile for MP3::Tag
'nmake' is not recognized as an internal or external command,
operable program or batch file.
  nmake  -- NOT OK
Running make test
  Can't test without successful make
Running make install
  make had returned bad status, install seems impossible
"


Can anyone help me?
Thank you
Kaushik



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

Date: Thu, 09 Nov 2006 01:01:08 -0800
From: Joe Smith <joe@inwap.com>
Subject: Re: IPv4 address validation in Net::IP
Message-Id: <WOadnUtjYcMNc8_YnZ2dnUVZ_rqdnZ2d@comcast.com>

Jigs wrote:

> Can someone please explain why single numbers are valis IP addresses?

IPv4 address are 32-bit numbers, which can be shown in several ways.
"127.1" is perfectly valid; it is the same as "127.0.0.1".

The following IP address are all the same:

   1113982867 = 66.6686611 = 66.102.1939 = 66.102.7.147 = 0x42660793

If you don't believe me, try http://1113982867/search?q=%49%50%76%34

	-Joe


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

Date: Wed, 08 Nov 2006 19:36:32 +0100
From: Michael Perle <michael_perle@yahoo.com>
Subject: Re: Newbie perl question
Message-Id: <45522389$1_2@news.arcor-ip.de>

laclac01@yahoo.com wrote:
> I am new to perl, I am having so trouble.  For my program, I just want
> to log in to my router and then spit out the html to the screen.
> here is my code
> 
> #!/usr/bin/perl
> 
> $original ="http://admin:admin@192.168.1.1/cgi-bin/sysinfo.cgi";
> #$original ="README";
> open (FILE, $original);
> @lines=<FILE>;
> close FILE;
> print @lines;

Without no error handling and LWP installed (I guess
it is standard in most distributins - someone may
correct me if I am wrong) that could be easy as:

use LWP::Simple;
$html = get 'http://www.vonabiszet.de/';
print $html;

MP


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

Date: 9 Nov 2006 09:11:16 -0800
From: "PGPS" <premgrps@gmail.com>
Subject: Re: PERL can't open file for logging (world writable directory Windows XP Home/ Active Perl / Apache)
Message-Id: <1163092276.056640.118610@h48g2000cwc.googlegroups.com>

X-No-Archive:Yes

Thanks. I put the same question in Apache groups and I got a response
saying that "That's how it should be".

My question is: "What's the solution to get it working". Since, on the
Linux machine, on which I just had a user login (on someone else's
server), I could get it working. So, the configuration was changed. The
problem is not just HTML, I would like all the depended filies like
*.js, *.jpg, *.css, *.gif to be in the same directory as the program.

Anyway, the above is a Apache configuration problem. Below is my PERL
problem.

Below is the code:

open(LOGFILE, ">>/logs.html");
print LOGFILE "Some stuff here\n";
close(LOGFILE);

The error in the apache access logs is something to the effect that
"Cannot open file" and it points to the line number in the PERL program
which has this line:

open(LOGFILE, ">>/logs.html");

DIRECTORY STRUCTURE
[htdocs]
         logs.html
[cgi-bin]
          [program1]
                       prog1.cgi

htdocs and cgi-bin directories are in the same parent directory.
htdocs has logs.html file
cgi-bin has a folder called program1 and program1 folder has prog1.cgi



Thanks.

Sisyphus wrote:
> "PGPS" <premgrps@gmail.com> wrote in message
> news:1163026204.175252.217270@e3g2000cwe.googlegroups.com...
> .
> .
> >
> > 4. With this setup, I get an error "Cannot open file" in the error logs
> > of Apache.
>
> Can you extend that error message to include the name of the file that perl
> couldn't open (in case it's not the file you think it was), and to include
> the contents of $!.
> 
> Cheers,
> Rob



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

Date: Fri, 10 Nov 2006 04:47:52 +1100
From: "Sisyphus" <sisyphus1@nomail.afraid.org>
Subject: Re: PERL can't open file for logging (world writable directory Windows XP Home/ Active Perl / Apache)
Message-Id: <45536ae8$0$17351$afc38c87@news.optusnet.com.au>


"PGPS" <premgrps@gmail.com> wrote in message
news:1163092276.056640.118610@h48g2000cwc.googlegroups.com...
 .
 .
>
> The error in the apache access logs is something to the effect that
> "Cannot open file" and it points to the line number in the PERL program
> which has this line:
>
> open(LOGFILE, ">>/logs.html");
>

Beats me as to why that error appears in the apache logs.

I could understand it if the line in question was:

open(LOGFILE, ">>/logs.html") or die "Cannot open file";

in which case I would recommend changing it to:

open(LOGFILE, ">>/logs.html") or die "Cannot open file: $!";

(In fact, change it to that even if the code *does* read exactly as you
posted.)

The "$!" bit should provide some hint as to why the failure is occurring.

Cheers,
Rob




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

Date: Thu, 9 Nov 2006 12:43:22 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: PERL can't open file for logging (world writable directory Windows XP Home/ Active Perl / Apache)
Message-Id: <slrnel6tma.p31.tadmc@tadmc30.august.net>

PGPS <premgrps@gmail.com> wrote:

> X-No-Archive:Yes


Why do you want to (attempt to) set no archive?

(it does not work when you include it in the body like that, it
 needs to be in the headers.
)


> I would like all the depended filies like
> *.js, *.jpg, *.css, *.gif to be in the same directory as the program.


Why would you like all the dependent files to be in the same 
directory as the program?


> The error in the apache access logs is something to the effect that
                                         ^^^^^^^^^^^^^^^^^^^^^^^
                                         ^^^^^^^^^^^^^^^^^^^^^^^

Please post the exact text of any messages that you are getting.

The devil is in the details when debugging programs...



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


[snip TOFU]

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


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

Date: 9 Nov 2006 08:14:34 -0800
From: "Jane" <superman183@hotmail.com>
Subject: Perl Regex Query
Message-Id: <1163088874.389154.218830@b28g2000cwb.googlegroups.com>

Hi,

I'm attempting to make sure that any ampersands I produce in a webpage
are using the proper entity code (ie. "&amp;"  as opposed to simply
"&"). I can get so far with it, and it works fine, except for one
small, but important detail.

Importantly, I have to assume, when swapping any "&" I find, that it is
not already part of an entity, which could include "&amp;" itself, or
something like "&#155", for example. It may also simply be preceeded or
suffixed by nothing other than a space.

So, I produced a little test sentence, below, to try out my regex, and
it swaps everything it's supposed to swap, but it gobbles up an extra
character as well, when I don't want it to. The regex, the original
test sentence, and the sentence after being regexed, are below
(hopefully the ampersands etc don't get escaped when I post this):

THE ORIGINAL SENTENCE:
$x="Apples & oranges from T&J are really good and tasty &#8230, &amp; I
should know...\n";

(which contains two ampersands to be regexed, one between apples and
oranges, and one between "T" and "J". The others are, of course,
already in good shape).


THE REGEX:
$x=~s/&[^#a]/&amp;/g;


THE RESULT:
Apples &amp;oranges from T&amp; are really good and tasty &#8230, &amp;
I should know...


 ... so it gobbles up the space character before oranges, and also the
J, from T&J. I've tried all sorts of things, but can only seem to make
it worse!  ... Any assistance would be mightily appreciated.

Thanks!
Jane



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

Date: 9 Nov 2006 08:22:42 -0800
From: "Jane" <superman183@hotmail.com>
Subject: Re: Perl Regex Query
Message-Id: <1163089362.151927.140950@h54g2000cwb.googlegroups.com>

Grrr! All my ampersands did get escaped when I posted, so the post
doesn't make a lot of sense ... however, hopefully someone will
understand what I was babbling about.

Jane


Jane wrote:
> Hi,
>
> I'm attempting to make sure that any ampersands I produce in a webpage
> are using the proper entity code (ie. "&amp;"  as opposed to simply
> "&"). I can get so far with it, and it works fine, except for one
> small, but important detail.
>
> Importantly, I have to assume, when swapping any "&" I find, that it is
> not already part of an entity, which could include "&amp;" itself, or
> something like "&#155", for example. It may also simply be preceeded or
> suffixed by nothing other than a space.
>
> So, I produced a little test sentence, below, to try out my regex, and
> it swaps everything it's supposed to swap, but it gobbles up an extra
> character as well, when I don't want it to. The regex, the original
> test sentence, and the sentence after being regexed, are below
> (hopefully the ampersands etc don't get escaped when I post this):
>
> THE ORIGINAL SENTENCE:
> $x="Apples & oranges from T&J are really good and tasty &#8230, &amp; I
> should know...\n";
>
> (which contains two ampersands to be regexed, one between apples and
> oranges, and one between "T" and "J". The others are, of course,
> already in good shape).
>
>
> THE REGEX:
> $x=~s/&[^#a]/&amp;/g;
>
>
> THE RESULT:
> Apples &amp;oranges from T&amp; are really good and tasty &#8230, &amp;
> I should know...
>
>
> ... so it gobbles up the space character before oranges, and also the
> J, from T&J. I've tried all sorts of things, but can only seem to make
> it worse!  ... Any assistance would be mightily appreciated.
> 
> Thanks!
> Jane



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

Date: Thu, 09 Nov 2006 17:46:14 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Perl Regex Query
Message-Id: <4rh4ekFrg8nvU1@mid.individual.net>

Jane wrote:
> I'm attempting to make sure that any ampersands I produce in a webpage
> are using the proper entity code (ie. "&amp;"  as opposed to simply
> "&").
> ...
> THE REGEX:
> $x=~s/&[^#a]/&amp;/g;

Maybe you want something like:

     $x =~ s/&(?!#?\w+;)/&amp;/g;

Please look for "negative look-ahead assertion" in "perldoc perlre".

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


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

Date: 9 Nov 2006 16:54:15 GMT
From: Glenn Jackman <glennj@ncf.ca>
Subject: Re: Perl Regex Query
Message-Id: <slrnel6n9n.ib2.glennj@smeagol.ncf.ca>

At 2006-11-09 11:14AM, "Jane" wrote:
>  THE ORIGINAL SENTENCE:
>  $x="Apples & oranges from T&J are really good and tasty &#8230, &amp; I
>  should know...\n";
>  
>  (which contains two ampersands to be regexed, one between apples and
>  oranges, and one between "T" and "J". The others are, of course,
>  already in good shape).
>  
>  
>  THE REGEX:
>  $x=~s/&[^#a]/&amp;/g;

The "[^#a]" construct actually consumes the  character after the
ampersand.  You want a negative lookahead:
    s/&(?!#|\w+;)/&amp;/g;

That RE should also handle entities like "&nbsp;", etc

-- 
Glenn Jackman
Ulterior Designer


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

Date: Thu, 09 Nov 2006 16:55:42 +0000
From: Ben Bacarisse <ben.usenet@bsb.me.uk>
Subject: Re: Perl Regex Query
Message-Id: <87ejsctv8x.fsf@bsb.me.uk>

"Jane" <superman183@hotmail.com> writes:

> Hi,
>
> I'm attempting to make sure that any ampersands I produce in a webpage
> are using the proper entity code (ie. "&amp;"  as opposed to simply
> "&"). I can get so far with it, and it works fine, except for one
> small, but important detail.
>
> Importantly, I have to assume, when swapping any "&" I find, that it is
> not already part of an entity, which could include "&amp;" itself, or
> something like "&#155", for example. It may also simply be preceeded or
> suffixed by nothing other than a space.
>
> So, I produced a little test sentence, below, to try out my regex, and
> it swaps everything it's supposed to swap, but it gobbles up an extra
> character as well, when I don't want it to. The regex, the original
> test sentence, and the sentence after being regexed, are below
> (hopefully the ampersands etc don't get escaped when I post this):
>
> THE ORIGINAL SENTENCE:
> $x="Apples & oranges from T&J are really good and tasty &#8230, &amp; I
> should know...\n";
>
> (which contains two ampersands to be regexed, one between apples and
> oranges, and one between "T" and "J". The others are, of course,
> already in good shape).
>
>
> THE REGEX:
> $x=~s/&[^#a]/&amp;/g;

One way is to use negative look ahead matching (X not followed by Y):

  s/&(?!#?\w+;)/&amp;/g

Be careful though.  You don't seem to have correct character entities
since your numeric ones are not followed by ; as they should be so the
above does not work with your example.  If you have lots of these you
could use:

  s/&(?!#\d+;?|\w+;)/&amp;/g

Making the ; optional after alphabetic entity names will not work
because &J will be seen as a valid entity.  Let's hope you don't have
any of these.

-- 
Ben.


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

Date: 9 Nov 2006 09:07:26 -0800
From: "Jane" <superman183@hotmail.com>
Subject: Re: Perl Regex Query
Message-Id: <1163092046.556604.140330@m73g2000cwd.googlegroups.com>


> Be careful though.  You don't seem to have correct character entities
> since your numeric ones are not followed by ; as they should be so the
> above does not work with your example.  If you have lots of these you
> could use:
>
>   s/&(?!#\d+;?|\w+;)/&amp;/g
>
> Making the ; optional after alphabetic entity names will not work
> because &J will be seen as a valid entity.  Let's hope you don't have
> any of these.
>
> --
> Ben.


Wow, thanks so much to everyone for the rapid responses, much
appreciated, and I'll research negative look-ahead for future
reference.

Anyway, the regex from Ben worked perfectly for all cases I have,
including the test sentence I was playing with, and the others worked
except for once instance in the test sentence, which was where it ended
up replacing the & after "tasty", where it was already an entity
reference, but I really appreciate all the suggestions and comments!

Many thanks,
Jane



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

Date: Thu, 09 Nov 2006 18:19:01 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Perl Regex Query
Message-Id: <4rh6c4Frh2gnU1@mid.individual.net>

Jane wrote:
>>Be careful though.  You don't seem to have correct character entities
>>since your numeric ones are not followed by ; as they should be so the
>>above does not work with your example.  If you have lots of these you
>>could use:
>>
>>  s/&(?!#\d+;?|\w+;)/&amp;/g
>>
>>Making the ; optional after alphabetic entity names will not work
>>because &J will be seen as a valid entity.  Let's hope you don't have
>>any of these.
> 
> Wow, thanks so much to everyone for the rapid responses, much
> appreciated, and I'll research negative look-ahead for future
> reference.
> 
> Anyway, the regex from Ben worked perfectly for all cases I have,
> including the test sentence I was playing with, and the others worked
> except for once instance in the test sentence, which was where it ended
> up replacing the & after "tasty", where it was already an entity
> reference,

No, there wasn't. Since there was no trailing ';', it was not an entity 
reference. Hence it should not be treaded as such, should it?

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


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

Date: 9 Nov 2006 09:43:57 -0800
From: "Jane" <superman183@hotmail.com>
Subject: Re: Perl Regex Query
Message-Id: <1163094237.377951.161690@h54g2000cwb.googlegroups.com>

>
> No, there wasn't. Since there was no trailing ';', it was not an entity
> reference. Hence it should not be treaded as such, should it?
>
> --
> Gunnar Hjalmarsson
> Email: http://www.gunnar.cc/cgi-bin/contact.pl

Just for info' ...  In the instances that I'm using it for, I think
that the "&" could in fact be following by any character at all,
including spaces. In some cases it may be part of a numeric entity (or
I suppose other HTML entites, such as nbsp;, etc), but in other cases
it'll just be an ampersand that needs to be entity-ised. However, if
it's followed by a # symbol, then I know not to do anything with it,
and I guess that any other HTML & entity should always be prefixed with
a ";"  , and there will be no whitespace between the "&" and the ";".

Anyway, many thanks to each contributor, I appreciate it.

Thanks,
Jane



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

Date: 9 Nov 2006 09:46:04 -0800
From: "Jane" <superman183@hotmail.com>
Subject: Re: Perl Regex Query
Message-Id: <1163094364.648367.55240@k70g2000cwa.googlegroups.com>

Ooops ... "prefixed" should, of course, have read "suffixed"

Jane


Jane wrote:
> >
> > No, there wasn't. Since there was no trailing ';', it was not an entity
> > reference. Hence it should not be treaded as such, should it?
> >
> > --
> > Gunnar Hjalmarsson
> > Email: http://www.gunnar.cc/cgi-bin/contact.pl
>
> Just for info' ...  In the instances that I'm using it for, I think
> that the "&" could in fact be following by any character at all,
> including spaces. In some cases it may be part of a numeric entity (or
> I suppose other HTML entites, such as nbsp;, etc), but in other cases
> it'll just be an ampersand that needs to be entity-ised. However, if
> it's followed by a # symbol, then I know not to do anything with it,
> and I guess that any other HTML & entity should always be prefixed with
> a ";"  , and there will be no whitespace between the "&" and the ";".
>
> Anyway, many thanks to each contributor, I appreciate it.
> 
> Thanks,
> Jane



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

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


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