[23737] in Perl-Users-Digest
Perl-Users Digest, Issue: 5943 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Dec 16 11:05:40 2003
Date: Tue, 16 Dec 2003 08:05:07 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 16 Dec 2003 Volume: 10 Number: 5943
Today's topics:
Re: @ISA specific to instance rather than class? <mb@uq.net.au.invalid>
Re: Caching results (?) of lengthy cgi process <henryn@zzzspacebbs.com>
Re: Caching results (?) of lengthy cgi process <flavell@ph.gla.ac.uk>
FILE parsing problems (G)
Re: Generate executable from perl scripts that uses Inl <usenet@morrow.me.uk>
How to make global vars? <nomorespam@nomorespam.nospam>
Making \w catch Swedish characters (setlocale) (David Hag)
Re: Making \w catch Swedish characters (setlocale) <noreply@gunnar.cc>
Re: Making \w catch Swedish characters (setlocale) <calle@cyberpomo.com>
Re: Perl equivalent of "On error resume" (Rajesh)
Re: Perl equivalent of "On error resume" <bart.lateur@pandora.be>
Re: Perl equivalent of "On error resume" (Tad McClellan)
Re: redo undefines loop variable <koh@sikkerhet.no>
Re: Shrikage: regexp rookie <noreply@gunnar.cc>
Re: Shrikage: regexp rookie <uri@stemsystems.com>
Re: Starting Perl Script at Bootup <andy@petdance.com>
Re: Starting Perl Script at Bootup <andy@petdance.com>
Re: Starting Perl Script at Bootup <jurgenex@hotmail.com>
stop plus (+) symbol within scalar variable being inter (Tom)
Re: stop plus (+) symbol within scalar variable being i <matthew.garrish@sympatico.ca>
Re: stop plus (+) symbol within scalar variable being i (Tom)
Re: stop plus (+) symbol within scalar variable being i <noreply@gunnar.cc>
Re: stop plus (+) symbol within scalar variable being i <mb@uq.net.au.invalid>
Re: Subroutine return two Hash <karlheinz.weindl@oooonlinehome.de>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 16 Dec 2003 11:47:14 +1000
From: Matthew Braid <mb@uq.net.au.invalid>
Subject: Re: @ISA specific to instance rather than class?
Message-Id: <brlo72$mfi$1@bunyip.cc.uq.edu.au>
Malcolm Dew-Jones wrote:
> Ben Morrow (usenet@morrow.me.uk) wrote:
> : Matthew Braid <mb@uq.net.au.invalid> wrote:
> : > sub use_something {
> : > my $self = shift;
> : > eval {use base qw/My::Package::Something/};
>
> : As someone else pointed out, a 'use' statement is a BEGIN block, so
> : this is silly. What you perhaps meant was
> : eval {
> : require qw/My::Package::Something/;
> : @ISA = qw/My::Package::Something/
> : }
>
> No, what he meant was that it needed to be a string eval.
>
> eval 'use base qw/My::Package::Something/';
>
> (or better because of a bit more syntax checking, as long as you remember
> the "q")
>
> eval q{use base qw/My::Package::Something/};
>
> The string form of eval is evaluated at run time, which means the "use"
> statement is _not_ evaluated as per a BEGIN block, and yet it still
> includes what ever chicanery is going on in the background (importing,
> exporting etc.)
Damn I hate my newsgroup provider - I'm missing a few messages...
Anyway, I didn't realise that use inside eval{} was still evaluated at
compile time. Sigh. I've learnt to avoid eval'' so I might go for the
eval {
require qw/My::Package::Something/;
push @ISA, qw/My::Package::Something/;
};
form (unless require is evaluated at compile time inside an eval as well...)
I like the idea of re-blessing an object into its own private class
though. I might look into that further (I'll be digging into
Class::Classless a bit :) )
Thanks for the help.
MB
------------------------------
Date: Mon, 15 Dec 2003 20:52:44 GMT
From: Henry <henryn@zzzspacebbs.com>
Subject: Re: Caching results (?) of lengthy cgi process
Message-Id: <BC035F1B.1989C%henryn@zzzspacebbs.com>
Bart:
Thanks for your response on this thread:
in article 254rtvcbl00i6vjusuvdcr63vrte0rqtuk@4ax.com, Bart Lateur at
bart.lateur@pandora.be wrote on 12/15/03 2:47 AM:
> Henry wrote:
>
>> As I responded to that issue, my main excuse is that I haven't yet found the
>> right CGI group.
>
> <news:comp.infosystems.www.authoring.cgi>, which is a self-moderated
> newsgroup, meaning you have to jump through some hoops to get your first
> post to it through. Check out
> <http://www.thinkspot.net/ciwac/howtopost.html>
Now, that group looks like the right one, thanks! I'm posting this issue in
someone different form to that group.
Note to everyone on this thread: In the cold light of Monday morning, I've
finally figured out that I haven't made clear my rather perverse design
requirement:
I want the transition from page content 'n' to state 'm' to be visible, not
hidden as it would be in almost all other cases. Thus, when the user hits
the button "update now" he/she might see an cgi-generated accounting of the
differences between state 'n' and state 'm', if the underlying data has
changed since the last update. For this design, it's ok that the user
requesting the update would be the only one seeing this transition.
This sounds really strange, I imagine, but that's what I need. And it's why
I've been resisting background (e.g. crontab) based updating.
Thanks,
Henry
henryn@zzzspacebbs.com remove 'zzz'
------------------------------
Date: Tue, 16 Dec 2003 11:52:43 +0000
From: "Alan J. Flavell" <flavell@ph.gla.ac.uk>
Subject: Re: Caching results (?) of lengthy cgi process
Message-Id: <Pine.LNX.4.53.0312161149080.11020@ppepc56.ph.gla.ac.uk>
On Mon, 15 Dec 2003, l v wrote:
> My understanding is that the web server hands out the last modified
> date/time of the requested file in the http headers.
There's a fine tutorial on cacheability validators (last-modified,
ETag etc.) at http://www.mnot.net/cache_docs/ , with a link to the
same author's "cacheability engine" which can be used online to study
the cacheability of web resources. Widely recommended.
Of course, it's more on-topic for a web authoring group than for here,
hence the brevity of this f'up.
------------------------------
Date: 16 Dec 2003 05:22:46 -0800
From: bay_dar@yahoo.com (G)
Subject: FILE parsing problems
Message-Id: <cad04083.0312160522.2794d454@posting.google.com>
Hi, I'm a newbie to Perl and find regular expressions a mystery.
Anyway, I need to parse a file and display information in an HTML
file. My problem is that I don't know how to parse this stuff. Below
is the sample file showing 2 entries. After that I list my problem
code snip.
Thanks
"Title1" "Title2
" "Page:1" "Date: 12/15/2003 " "Time: 11:28:05AM
" "Sale
Number
" "
Sale Type
" "
Date Assigned
" "
Company Name
" "S034521" "Software Agreement" 11/08/2003 "Joes Garage" "2 Years
support"
"Title1" "Title2
" "Page:1" "Date: 12/15/2003 " "Time: 11:28:05AM
" "Sale
Number
" "
Sale Type
" "
Date Assigned
" "
Company Name
" "S034522" "Hardware" 12/11/2003 "JK & J INC." "Backup Tape"
while (<FILE>) {
#HERE IS WHERE I AM HAVING MY PROBLEM - I can't get a match
if ( ($snum, $type, $date, $comp_name) =
/\"+\"\t+\"+\"\t+\"+\"\t+\"+\"\t+\"+\"\t+\"(.+)\"\t+\"(.+)\"(.+?)\"(.+)\"\s*$/ix
) {
if ($snum !~ /^d/i) { next; }
$date =~ s/^\t*//; $date =~ s/\t*$//;
($ddate) = split(/\t/, $date);
$ddate = " " if (! $ddate);
$_ = <FILE>;
($description) = /^\"(.+)\"\s*$/; # dnum
if ($type !~ /^\s*$/) {
$output .=
PutRec($snum, $type, $ddate, $comp_name, $description);
}
}
}
------------------------------
Date: Mon, 15 Dec 2003 21:14:07 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Generate executable from perl scripts that uses Inline::C?
Message-Id: <brl86v$far$1@wisteria.csv.warwick.ac.uk>
cmaster18@yahoo.com (cmaster) wrote:
> I used to be able to generate executables from 'normal' perl scripts
> (those without any Inline C codes) by using the command "perlcc -o
> hello hello.pl". (I'm using Perl v5.8.0, Inline 0.44 under linux )
>
> However I have no idea on how it could be done to perl scripts that
> have Inline C codes. (Could this be done actually?)
perlcc has always been experimental and not recommended for production
use. You'll probably be better off with PAR. If this won't handle
Inline::C scripts, then you could always factor the Inline stuff out
into a module (probably a good idea anyway), install that module and
then PAR it up.
Ben
--
EAT
KIDS (...er, whoops...)
FOR ben@morrow.me.uk
99p
------------------------------
Date: Tue, 16 Dec 2003 03:16:08 GMT
From: "Sebastien B." <nomorespam@nomorespam.nospam>
Subject: How to make global vars?
Message-Id: <YNuDb.33434$%TO.33392@twister01.bloor.is.net.cable.rogers.com>
I'm trying to figure out how to use/make simple global vars.
Since I have multiple scripts that connect to database, I want to use a
seperate file that does the connection and call it in the other scripts; so
something like:
dbiconnect.pl:
use strict;
use DBI;
my $db=dbi_connect.....
1;
and then in the scripts:
use strict;
require 'dbiconnect.pl';
my $somevar=$db->select(...);
problem is that $db isn't global; how do I make it global? Do I need to make
the first script into a pakage? How? (tried it didn't work). None of the
docs are clear on global (cross-file) vars specifically.
------------------------------
Date: 16 Dec 2003 04:10:34 -0800
From: david.hagstrand@home.se (David Hag)
Subject: Making \w catch Swedish characters (setlocale)
Message-Id: <4ebb369b.0312160410.5cbe3079@posting.google.com>
Hi,
I'm a bit puzzeled. I'm stuck in the place where one has to deal with
different sets of charachters, and it sucks.
Here goes my problem:
I want to do lots of transformations on Sweish texts, using s// and
m// etc. However, perl's \w for example does not cover any of the
Swedish chars "å", "ä" or "ö", besides missing any accented char as
"á" etc. This is a REAL problem for me, and I could make nasty work
arounds like defining a set of characters to look for each time needed
(like: [A-Za-zÅÄÖåäöéèáÀàÀ...]), but that is just crazy.
As far as I understand it should be possible to tell perl that I want
to use a specific locale, and that e.g. \w then should know about the
correct char set. First of all, my locale is already
Swedish-ISO-8859-1 on my Linux system. I tried to use the POSIX
module:
use POSIX qw(setlocale LC_ALL);
setlocale(LC_ALL, "sv_SE.iso-8859-1");
No complaints from perl, but still doing "m/\w+/" misses any word
containing "åäö"...
Any tips on how to solve this in a general way will be very much
appreciated!
Thanks,
David
------------------------------
Date: Tue, 16 Dec 2003 13:43:15 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Making \w catch Swedish characters (setlocale)
Message-Id: <brmv3m$4um7i$1@ID-184292.news.uni-berlin.de>
David Hag wrote:
> As far as I understand it should be possible to tell perl that I
> want to use a specific locale, and that e.g. \w then should know
> about the correct char set.
$_ = 'Göteborg';
use locale;
print /^\w+$/ ? "Match\n" : "No match\n";
http://www.perldoc.com/perl5.8.0/lib/locale.html
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Tue, 16 Dec 2003 13:52:49 +0100
From: Calle Dybedahl <calle@cyberpomo.com>
Subject: Re: Making \w catch Swedish characters (setlocale)
Message-Id: <861xr49b6m.fsf@ulthar.bisexualmenace.org>
>>>>> "David" == David Hag <david.hagstrand@home.se> writes:
> As far as I understand it should be possible to tell perl that I
> want to use a specific locale, and that e.g. \w then should know
> about the correct char set. First of all, my locale is already
> Swedish-ISO-8859-1 on my Linux system. I tried to use the POSIX
> module:
Right thinking, wrong module. perldoc locale
--
Calle Dybedahl <calle@lysator.liu.se>
"Then I dream of a world where idiots are hunted like wild pigs"
-- Stephen Edwards, scary.devil.monastery
------------------------------
Date: 16 Dec 2003 02:03:30 -0800
From: raj1_iit@yahoo.com (Rajesh)
Subject: Re: Perl equivalent of "On error resume"
Message-Id: <bb6dafde.0312160203.59d82286@posting.google.com>
Uri Guttman <uri@stemsystems.com> wrote in message news:<x7y8teskvr.fsf@mail.sysarch.com>...
> >>>>> "R" == Rajesh <raj1_iit@yahoo.com> writes:
>
> > Can anybody tell me if there is any equivalent of "On error resume" in
> > Perl? If not, how can u implemnt it?
>
> it would help if you explained that did in whatever language it came
> from.
>
> uri
Ok...now, I am a newbie to perl. Actually i was working on a script to
export the details of a registry to a file. It was working well but it
stops sometimes with the error,
Can't call method "GetValues" on an undefined value at CompReg.pm line
239.
I figured out the reason for the error which is that i dont have
enough permissions to read a particular registry key. So, the program
stops when it reaches the key. I want it to continue and ignore if it
encounters any key which i dont have any permissions. How to implement
that?
In Visual Basic, there is "On error resume" which will continue the
program if it encounters any error. I wanted to know if there is any
equivalent
Rajesh
------------------------------
Date: Tue, 16 Dec 2003 12:31:46 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: Perl equivalent of "On error resume"
Message-Id: <unuttvc208qhf8clrgphjb4r9hrtt97tek@4ax.com>
Rajesh wrote:
>Can't call method "GetValues" on an undefined value at CompReg.pm line
>239.
>
>I figured out the reason for the error which is that i dont have
>enough permissions to read a particular registry key. So, the program
>stops when it reaches the key. I want it to continue and ignore if it
>encounters any key which i dont have any permissions. How to implement
>that?
Why not check if you indeed have an object before trying to call the
method?
$regObj->GetValues if $regObj;
--
Bart.
------------------------------
Date: Tue, 16 Dec 2003 06:19:12 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Perl equivalent of "On error resume"
Message-Id: <slrnbttu20.e0d.tadmc@magna.augustmail.com>
Rajesh <raj1_iit@yahoo.com> wrote:
> So, the program
> stops when it reaches the key. I want it to continue and ignore if it
> encounters any key which i dont have any permissions. How to implement
> that?
perldoc -f eval
The "eval BLOCK" form is the usual way of dealing with exceptions.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 16 Dec 2003 12:30:14 +0100
From: Ketil <koh@sikkerhet.no>
Subject: Re: redo undefines loop variable
Message-Id: <oprz9t8dxa6pl1k8@news.songnetworks.no>
On Sun, 14 Dec 2003 09:02:18 -0500, zentara <zentara@highstream.net> wrote:
> On 13 Dec 2003 15:56:11 -0800, charley@pulsenet.com (Chris Charley)
> wrote:
>> A small piece of code (below) to demonstrate the bug.
>> If the code would run without a bug, it would be an infinite loop.
>> But the bug produces warnings about the use of an uninitialized value.
>> . .
>>
>> #####################################################################
>> ################### code #######################################
>>
>> #!/usr/bin/perl
>> use strict;
>> use warnings;
>>
>> while (my $data = <DATA>) {
>> print $data;
>> redo if $data == 2;
>> }
>> __DATA__
>> 1
>> 2
>> 3
>> 4
>
> I don't think it's a bug.
> I'm no expert on Perl internals, but when I first looked at this,
> I had these thoughts.
> 1.) Wouldn't you need to chomp $data? Otherwise $data will
> never == 2.
> 2. This seems to work as I would expect since data is a filehandle.
> When I run the code with a chomp $data, it prints 1234. It prints
> 12, then with the redo, it prints 34. I think you are assuming
> that redo resets the DATA filehandle?
>
> If I change redo to "seek DATA,0,0" you get an infinite loop.
>
> #!/usr/bin/perl
> use strict;
> use warnings;
>
> while (my $data = <DATA>) {
> chomp $data;
> print $data;
> #redo if $data == 2;
> seek DATA, 0, 0 if $data == 2;
> }
> __DATA__
> 1
> 2
> 3
> 4
>
>
>
>
>
>
> --
> When life conspires against you, and no longer floats your boat,
> Don't waste your time with crying, just get on your back and float.
--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
------------------------------
Date: Tue, 16 Dec 2003 02:36:23 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Shrikage: regexp rookie
Message-Id: <brlnqb$4n6on$1@ID-184292.news.uni-berlin.de>
Don Stefani wrote:
> I'd like to know if/how I can shorten this regexp, so it's sexier.
> ;-) Chick's dig sexy code!
>
> Original line:
> Color: R14/88H Golden Wheat<br>Size: Average<br>
>
> My regexp:
> $ary2[2] =~ s/(Color:|Size:)//g;
> $ary2[2] =~ s/(\<br\>)/,/g;
> $ary2[2] =~ s/(^\s+)//;
Not sure about your definition of 'sexy', but...
$ary2[2] = "$1,$2" if $ary2[2] =~ /:\s+(.+?)<.+?:\s+([^<]+)/;
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Tue, 16 Dec 2003 01:50:37 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Shrikage: regexp rookie
Message-Id: <x7ad5tpm37.fsf@mail.sysarch.com>
>>>>> "GH" == Gunnar Hjalmarsson <noreply@gunnar.cc> writes:
> Don Stefani wrote:
>> I'd like to know if/how I can shorten this regexp, so it's sexier.
>> ;-) Chick's dig sexy code!
>> Original line:
>> Color: R14/88H Golden Wheat<br>Size: Average<br>
>> My regexp:
>> $ary2[2] =~ s/(Color:|Size:)//g;
>> $ary2[2] =~ s/(\<br\>)/,/g;
< and > are not special in regexes so they don't need to be escaped
>> $ary2[2] =~ s/(^\s+)//;
that doesn't need the () as you don't grab or group anything.
> Not sure about your definition of 'sexy', but...
> $ary2[2] = "$1,$2" if $ary2[2] =~ /:\s+(.+?)<.+?:\s+([^<]+)/;
blech!!
<all untested>
why not just use s///?
$ary2[2] =~ s/:\s+(.+?)<.+?:\s+([^<]+)/$1,$2/ ;
and that can be cleaned up too:
$ary2[2] =~ s/:\s+(.+?)<.+?:\s+(.+?)</$1,$2/ ;
now remove the regex redundancy:
$ary2[2] = join( ',', $ary2[2] =~ /:\s+(.+?)</g ) ;
and then remove the var redundancy:
$_ = join( ',', /:\s+(.+?)</g ) for $ary2[2] ;
bug alert: gunnar's and my code didn't replace the last <br> with , but
that is easily corrected.
now, that will get you the girl!
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Mon, 15 Dec 2003 15:14:16 -0600
From: Andy Lester <andy@petdance.com>
Subject: Re: Starting Perl Script at Bootup
Message-Id: <3FDE2428.1020106@petdance.com>
> && What's the point of posting a misinforming reply like this, Abigail?
>
>
> What's the point of asking non-Perl questions in a Perl group?
To get a useful answer, even if it's not the right place to do it. Far
better than a malicious lie. Plus, everything here gets archived. I'd
hate for someone to Google for "Perl startup script" and hit your answer
that states something patently untrue. Worse still for someone as well
known and useful in the Perl community to say something like that,
because it lends credibility to what you've said.
xoa
------------------------------
Date: Mon, 15 Dec 2003 15:20:25 -0600
From: Andy Lester <andy@petdance.com>
Subject: Re: Starting Perl Script at Bootup
Message-Id: <3FDE2599.1020708@petdance.com>
> && What's the point of posting a misinforming reply like this, Abigail?
>
>
> What's the point of asking non-Perl questions in a Perl group?
To get a useful answer, even if it's not the right place to do it. Far
better than a malicious lie. Plus, everything here gets archived. I'd
hate for someone to Google for "Perl startup script" and hit your answer
that states something patently untrue. Worse still for someone as well
known and useful in the Perl community to say something like that,
because it lends credibility to what you've said.
xoa
------------------------------
Date: Tue, 16 Dec 2003 12:56:41 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Starting Perl Script at Bootup
Message-Id: <diDDb.3543$G9.122@nwrddc01.gnilink.net>
Andy Lester wrote:
>> && What's the point of posting a misinforming reply like this,
>> Abigail?
>> What's the point of asking non-Perl questions in a Perl group?
>
> To get a useful answer, even if it's not the right place to do it.
> Far better than a malicious lie.
You may want to take your sarcasm/irony detector to the shop for a
readjustment.
jue
------------------------------
Date: 15 Dec 2003 18:17:58 -0800
From: clicker@well.ox.ac.uk (Tom)
Subject: stop plus (+) symbol within scalar variable being interpolated in RE when followed by a number
Message-Id: <bdc11bf2.0312151817.67e55abc@posting.google.com>
Hi,
Can someone please tell me how to get round this problem. To simplify
it, I give a small example:
my $string = "catch+22";
my $RE = "h+22";
if ($string =~ /$RE/) {
print "I found the RE.\n";
}
It does not find the string h+22 within the catch+22. I can see why,
but don't know how to remedy it.
Thanks for the help.
Tom.
------------------------------
Date: Mon, 15 Dec 2003 21:38:58 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: stop plus (+) symbol within scalar variable being interpolated in RE when followed by a number
Message-Id: <6fuDb.12194$Ve.1057926@news20.bellglobal.com>
"Tom" <clicker@well.ox.ac.uk> wrote in message
news:bdc11bf2.0312151817.67e55abc@posting.google.com...
> Hi,
>
> Can someone please tell me how to get round this problem. To simplify
> it, I give a small example:
>
> my $string = "catch+22";
>
> my $RE = "h+22";
>
> if ($string =~ /$RE/) {
>
if ($string =~ /\Q$RE/)
You need to escape any metacharacters within the string with \Q. The \E
would be a bit pointless in your example, so I've omitted it, but if you
didn't want to escape any metacharacters after $RE you could end the quoting
that way (i.e., \Q ... \E). Read over the perlre man page for more
information.
Matt
------------------------------
Date: 16 Dec 2003 04:33:17 -0800
From: clicker@well.ox.ac.uk (Tom)
Subject: Re: stop plus (+) symbol within scalar variable being interpolated in RE when followed by a number
Message-Id: <bdc11bf2.0312160433.5da27575@posting.google.com>
Thanks for all your help everyone, much appreciated. It solves my
bigger problem perfectly.
------------------------------
Date: Tue, 16 Dec 2003 03:35:37 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: stop plus (+) symbol within scalar variable being interpolated in RE when followed by a number
Message-Id: <brlra1$4crb8$1@ID-184292.news.uni-berlin.de>
Tom wrote:
>
> my $string = "catch+22";
>
> my $RE = "h+22";
>
> if ($string =~ /$RE/) {
>
> print "I found the RE.\n";
> }
>
> It does not find the string h+22 within the catch+22. I can see
> why, but don't know how to remedy it.
my $RE = quotemeta("h+22");
or
my $RE = "h\\+22";
or
my $RE = 'h\+22';
or
my $RE = qr'h\+22';
or
if ($string =~ /\Q$RE/) {
or some other way...
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Tue, 16 Dec 2003 13:20:01 +1000
From: Matthew Braid <mb@uq.net.au.invalid>
Subject: Re: stop plus (+) symbol within scalar variable being interpolated in RE when followed by a number
Message-Id: <brltl1$ljq$1@bunyip.cc.uq.edu.au>
Tom wrote:
> Hi,
>
> Can someone please tell me how to get round this problem. To simplify
> it, I give a small example:
>
> my $string = "catch+22";
>
> my $RE = "h+22";
>
> if ($string =~ /$RE/) {
>
> print "I found the RE.\n";
> }
>
>
> It does not find the string h+22 within the catch+22. I can see why,
> but don't know how to remedy it.
>
> Thanks for the help.
>
> Tom.
if ($string =~ /\Q$RE/) {
print "I found the RE!\n";
}
\Q quotes everything up to the end of the re or until a \E is found.
There is still a problem - if $RE contains '\E'. I don't know how to get
around that without explicitly searching for it in the variable and
quoting it again yourself (but I think its fixed in perl 6 since it uses
something like \Q{$RE})
MB
------------------------------
Date: Mon, 15 Dec 2003 21:34:36 +0100
From: Karlheinz Weindl <karlheinz.weindl@oooonlinehome.de>
Subject: Re: Subroutine return two Hash
Message-Id: <brl5u8$vm8$1@online.de>
gilgames schrieb:
> my ($hash1, $hash2) = createHash();
> my %hash1 =%$hash1;
> my %hash2 = %$hash2;
Hmm, when I said 'use references to hashes instead' then I implied to
use them on the calling side as well (e.g. as shown in Gunnar's answer).
Unless there is a good reason for it, why would you introduce a
(possible lengthy) copy operation here?
------------------------------
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.
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 5943
***************************************